forked from SherClockHolmes/webpush-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpush_test.go
66 lines (54 loc) · 1.72 KB
/
webpush_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
package webpush
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
type testHTTPClient struct{}
func (*testHTTPClient) Do(*http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 201}, nil
}
func getURLEncodedTestSubscription() *Subscription {
return &Subscription{
Endpoint: "https://updates.push.services.mozilla.com/wpush/v2/gAAAAA",
Keys: Keys{
P256dh: "BNNL5ZaTfK81qhXOx23-wewhigUeFb632jN6LvRWCFH1ubQr77FE_9qV1FuojuRmHP42zmf34rXgW80OvUVDgTk",
Auth: "zqbxT6JKstKSY9JKibZLSQ",
},
}
}
func getStandardEncodedTestSubscription() *Subscription {
return &Subscription{
Endpoint: "https://updates.push.services.mozilla.com/wpush/v2/gAAAAA",
Keys: Keys{
P256dh: "BNNL5ZaTfK81qhXOx23+wewhigUeFb632jN6LvRWCFH1ubQr77FE/9qV1FuojuRmHP42zmf34rXgW80OvUVDgTk=",
Auth: "zqbxT6JKstKSY9JKibZLSQ==",
},
}
}
func TestSendNotificationToURLEncodedSubscription(t *testing.T) {
assert := assert.New(t)
resp, err := SendNotification([]byte("Test"), getURLEncodedTestSubscription(), &Options{
HTTPClient: &testHTTPClient{},
Subscriber: "mailto:<[email protected]>",
Topic: "test_topic",
TTL: 0,
Urgency: "low",
VAPIDPrivateKey: "testKey",
})
assert.Nil(err)
assert.Equal(201, resp.StatusCode)
}
func TestSendNotificationToStandardEncodedSubscription(t *testing.T) {
assert := assert.New(t)
resp, err := SendNotification([]byte("Test"), getStandardEncodedTestSubscription(), &Options{
HTTPClient: &testHTTPClient{},
Subscriber: "mailto:<[email protected]>",
Topic: "test_topic",
TTL: 0,
Urgency: "low",
VAPIDPrivateKey: "testKey",
})
assert.Nil(err)
assert.Equal(201, resp.StatusCode)
}