forked from pubnub/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_push_provisions_request_test.go
160 lines (117 loc) · 4 KB
/
list_push_provisions_request_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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package pubnub
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestListPushProvisionsRequestValidate(t *testing.T) {
assert := assert.New(t)
opts := newListPushProvisionsRequestOpts(pubnub, pubnub.ctx)
opts.DeviceIDForPush = "deviceId"
opts.PushType = PNPushTypeAPNS
err := opts.validate()
assert.Nil(err)
opts1 := newListPushProvisionsRequestOpts(pubnub, pubnub.ctx)
opts1.DeviceIDForPush = "deviceId"
opts1.PushType = PNPushTypeNone
err1 := opts1.validate()
assert.Contains(err1.Error(), "Missing Push Type")
opts3 := newListPushProvisionsRequestOpts(pubnub, pubnub.ctx)
opts3.PushType = PNPushTypeAPNS
err3 := opts3.validate()
assert.Contains(err3.Error(), "Missing Device ID")
}
func TestListPushProvisionsRequestBuildPath(t *testing.T) {
assert := assert.New(t)
opts := newListPushProvisionsRequestOpts(pubnub, pubnub.ctx)
opts.DeviceIDForPush = "deviceId"
opts.PushType = PNPushTypeAPNS
str, err := opts.buildPath()
assert.Equal("/v1/push/sub-key/sub_key/devices/deviceId", str)
assert.Nil(err)
}
func TestNewListPushProvisionsRequestBuilder(t *testing.T) {
assert := assert.New(t)
o := newListPushProvisionsRequestBuilder(pubnub)
o.DeviceIDForPush("deviceId")
o.PushType(PNPushTypeAPNS)
str, err := o.opts.buildPath()
assert.Equal("/v1/push/sub-key/sub_key/devices/deviceId", str)
assert.Nil(err)
}
func TestNewListPushProvisionsRequestBuilderContext(t *testing.T) {
assert := assert.New(t)
o := newListPushProvisionsRequestBuilderWithContext(pubnub, backgroundContext)
o.DeviceIDForPush("deviceId")
o.PushType(PNPushTypeAPNS)
str, err := o.opts.buildPath()
assert.Equal("/v1/push/sub-key/sub_key/devices/deviceId", str)
assert.Nil(err)
}
func TestListPushProvisionsRequestBuildQuery(t *testing.T) {
assert := assert.New(t)
opts := newListPushProvisionsRequestOpts(pubnub, pubnub.ctx)
opts.DeviceIDForPush = "deviceId"
opts.PushType = PNPushTypeAPNS
u, err := opts.buildQuery()
assert.Equal("apns", u.Get("type"))
assert.Nil(err)
}
func TestListPushProvisionsRequestBuildQueryParam(t *testing.T) {
assert := assert.New(t)
opts := newListPushProvisionsRequestOpts(pubnub, pubnub.ctx)
opts.DeviceIDForPush = "deviceId"
opts.PushType = PNPushTypeAPNS
queryParam := map[string]string{
"q1": "v1",
"q2": "v2",
}
opts.QueryParam = queryParam
u, err := opts.buildQuery()
assert.Equal("apns", u.Get("type"))
assert.Equal("v1", u.Get("q1"))
assert.Equal("v2", u.Get("q2"))
assert.Nil(err)
}
func TestListPushProvisionsRequestBuildQueryParamTopicAndEnv(t *testing.T) {
assert := assert.New(t)
opts := newListPushProvisionsRequestOpts(pubnub, pubnub.ctx)
opts.DeviceIDForPush = "deviceId"
opts.PushType = PNPushTypeAPNS
opts.Topic = "a"
opts.Environment = PNPushEnvironmentDevelopment
queryParam := map[string]string{
"q1": "v1",
"q2": "v2",
}
opts.QueryParam = queryParam
u, err := opts.buildQuery()
assert.Equal("apns", u.Get("type"))
assert.Equal("v1", u.Get("q1"))
assert.Equal("v2", u.Get("q2"))
assert.Equal("development", u.Get("environment"))
assert.Equal("a", u.Get("topic"))
assert.Nil(err)
}
func TestListPushProvisionsRequestBuildBody(t *testing.T) {
assert := assert.New(t)
opts := newListPushProvisionsRequestOpts(pubnub, pubnub.ctx)
opts.DeviceIDForPush = "deviceId"
opts.PushType = PNPushTypeAPNS
_, err := opts.buildBody()
assert.Nil(err)
}
func TestListPushProvisionsNewListPushProvisionsRequestResponseErrorUnmarshalling(t *testing.T) {
assert := assert.New(t)
jsonBytes := []byte(`s`)
_, _, err := newListPushProvisionsRequestResponse(jsonBytes, StatusResponse{})
assert.Equal("pubnub/parsing: Error unmarshalling response: {s}", err.Error())
}
func TestListPushProvisionsValidateSubscribeKey(t *testing.T) {
assert := assert.New(t)
pn := NewPubNub(NewDemoConfig())
pn.Config.SubscribeKey = ""
opts := newListPushProvisionsRequestOpts(pn, pn.ctx)
opts.DeviceIDForPush = "deviceId"
opts.PushType = PNPushTypeAPNS
assert.Equal("pubnub/validation: pubnub: Remove Channel Group: Missing Subscribe Key", opts.validate().Error())
}