forked from SherClockHolmes/webpush-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpush_test.go
38 lines (30 loc) · 886 Bytes
/
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
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 getTestSubscription() *Subscription {
return &Subscription{
Endpoint: "https://updates.push.services.mozilla.com/wpush/v2/gAAAAA",
Keys: Keys{
P256dh: "BNNL5ZaTfK81qhXOx23-wewhigUeFb632jN6LvRWCFH1ubQr77FE_9qV1FuojuRmHP42zmf34rXgW80OvUVDgTk",
Auth: "zqbxT6JKstKSY9JKibZLSQ",
},
}
}
func TestSendNotification(t *testing.T) {
assert := assert.New(t)
resp, err := SendNotification([]byte("Test"), getTestSubscription(), &Options{
HTTPClient: &testHTTPClient{},
Subscriber: "mailto:<EMAIL@EXAMPLE.COM>",
TTL: 0,
VAPIDPrivateKey: "testKey",
})
assert.Equal(201, resp.StatusCode)
assert.Nil(err)
}