forked from NaySoftware/go-fcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instanceid_test.go
130 lines (106 loc) · 2.86 KB
/
instanceid_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
package fcm
import (
"testing"
)
func TestGenTopicUrl(t *testing.T) {
expected := "https://iid.googleapis.com/iid/v1/DeviceToken/rel/topics/TopicNamE"
result := generateSubToTopicUrl("DeviceToken", "TopicNamE")
if result != expected {
t.Error("Gen Topic Url Error")
}
}
func TestGenInfoResult1(t *testing.T) {
result1 := `{"applicationVersion":"1","connectDate":"2016-07-02","attestStatus":"NOT_ROOTED","application":"com.comp.company","scope":"*","authorizedEntity":"1234567891234","rel":{"topics":{"global":{"addDate":"2016-07-02"}}},"connectionType":"WIFI","appSigner":"c822c1b63853ed273b89687ac505f9faabcdefgh","platform":"ANDROID"}`
resp, err := parseGetInfo([]byte(result1))
if err != nil {
t.Error("Parsing Error: ", err)
}
if resp == nil {
t.Error("Parsing Error: Response is nil")
}
}
func TestGenInfoResult2(t *testing.T) {
result2 := `{
"applicationVersion":"1",
"connectDate":"2016-07-02",
"attestStatus":"NOT_ROOTED",
"application":"com.comp.company",
"scope":"*",
"authorizedEntity":"1234567891234",
"rel":
{
"topics":
{
"global":{ "addDate":"2016-07-02" }
}
},
"connectionType":"WIFI",
"appSigner":"c822c1b63853ed273b89687ac505f9faabcdefgh",
"platform":"ANDROID"
}`
resp, err := parseGetInfo([]byte(result2))
if err != nil {
t.Error("Parsing Error: ", err)
}
if resp == nil {
t.Error("Parsing Error: Response is nil")
}
}
func TestGenInfoResult3(t *testing.T) {
result3 := `{"error":"No information found about this instance id."}`
resp, err := parseGetInfo([]byte(result3))
if err != nil {
t.Error("Parsing Error: ", err)
}
if resp == nil {
t.Error("Parsing Error: Response is nil")
}
}
func TestParseApnsBatchToByte(t *testing.T) {
batch1 := new(ApnsBatchRequest)
batch1.App = "com.comp.company"
batch1.Sandbox = true
batch1.ApnsTokens = []string{
"368dde283db539abc4a6419b1795b6131194703b816e4f624ffa12",
"76b39c2b2ceaadee8400b8868c2f45325ab9831c1998ed70859d86",
}
batch2 := &ApnsBatchRequest{
App: "com.comp.company",
Sandbox: true,
ApnsTokens: []string{
"368dde283db539abc4a6419b1795b6131194703b816e4f624ffa12",
"76b39c2b2ceaadee8400b8868c2f45325ab9831c1998ed70859d86",
},
}
resp, err := batch1.ToByte()
if err != nil {
t.Error("Parsing Error: ", err)
}
if resp == nil {
t.Error("Parsing Error: batch1 is nil")
}
resp, err = batch2.ToByte()
if err != nil {
t.Error("Parsing Error: ", err)
}
if resp == nil {
t.Error("Parsing Error: batch2 is nil")
}
}
func TestExtractTopicName(t *testing.T) {
topic := "/topics/news"
expected := "news"
if expected != extractTopicName(topic) {
t.Error("Extracting topic name faild")
}
topic = "/TOPICS/alpha"
expected = "alpha"
if expected != extractTopicName(topic) {
t.Error("Extracting topic name faild")
}
topic = "beta"
expected = "beta"
if expected != extractTopicName(topic) {
t.Error("Extracting topic name faild")
}
}