-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathios_integration_test.go
133 lines (120 loc) · 3.41 KB
/
ios_integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// +build integration
package apn
import (
"encoding/base64"
"flag"
"fmt"
"net/http/httputil"
"testing"
"time"
"github.com/joonix/apn/proto"
)
var (
tokenFlag string
certPath string
keyPath string
bundleID string
server string
)
func init() {
flag.StringVar(&bundleID, "bundle", "", "app bundle ID or APN topic")
flag.StringVar(&tokenFlag, "token", "", "notification token of destination device")
flag.StringVar(&certPath, "cert", "cert.pem", "path of public key used for APN authentication")
flag.StringVar(&keyPath, "key", "key.pem", "path of private key used for APN authentication")
flag.StringVar(&server, "server", "api.development.push.apple.com", "which APN server to use")
}
// https://developer.apple.com/library/prerelease/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW1
func TestIOSNotificationIntegration(t *testing.T) {
msg := proto.Notification{
APS: proto.NotificationAPS{
Alert: proto.NotificationAlert{
Title: "This is a notification title",
Body: "This is the notification body",
},
Category: "FOOBAR_CATEGORY",
Badge: 1,
Sound: "default",
},
}
token, err := base64.StdEncoding.DecodeString(tokenFlag)
if err != nil {
t.Fatal(err)
}
send, err := NewNotificationProvider(certPath, keyPath, bundleID, server)
if err != nil {
t.Fatal(err)
}
identity := "randomuuid1" + time.Now().String()
if _, err = send(&msg, fmt.Sprintf("%x", token), identity, time.Now().Add(time.Minute)); err != nil {
switch err := err.(type) {
case HTTPError:
b, _ := httputil.DumpResponse(err.Response, true)
t.Log(string(b))
}
t.Fatal(err)
}
}
func TestIOSBackgroundUpdateNotificationIntegration(t *testing.T) {
msg := proto.Notification{
APS: proto.NotificationAPS{
ContentAvailable: 1,
},
}
token, err := base64.StdEncoding.DecodeString(tokenFlag)
if err != nil {
t.Fatal(err)
}
send, err := NewNotificationProvider(certPath, keyPath, bundleID, server)
if err != nil {
t.Fatal(err)
}
identity := "randomuuid1" + time.Now().String()
if _, err = send(&msg, fmt.Sprintf("%x", token), identity, time.Now().Add(time.Minute)); err != nil {
switch err := err.(type) {
case HTTPError:
b, _ := httputil.DumpResponse(err.Response, true)
t.Log(string(b))
}
t.Fatal(err)
}
}
type CustomNotification struct {
proto.Notification
FooField string `json:"foo_field"`
}
func (n CustomNotification) NotificationPayload() proto.Notification {
return n.Notification
}
func TestIOSCustomNotificationIntegration(t *testing.T) {
msg := CustomNotification{
Notification: proto.Notification{
APS: proto.NotificationAPS{
Alert: proto.NotificationAlert{
Title: "This is a notification title",
Body: "This is the notification body",
},
Category: "FOOBAR_CUSTOM",
Badge: 1,
Sound: "default",
},
},
FooField: "My custom foo data",
}
token, err := base64.StdEncoding.DecodeString(tokenFlag)
if err != nil {
t.Fatal(err)
}
send, err := NewNotificationProvider(certPath, keyPath, bundleID, server)
if err != nil {
t.Fatal(err)
}
identity := "randomuuid2" + time.Now().String()
if _, err = send(&msg, fmt.Sprintf("%x", token), identity, time.Now().Add(time.Minute)); err != nil {
switch err := err.(type) {
case HTTPError:
b, _ := httputil.DumpResponse(err.Response, true)
t.Log(string(b))
}
t.Fatal(err)
}
}