-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification_test.go
64 lines (49 loc) · 1.49 KB
/
notification_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
package pushpad
import (
"testing"
"github.com/h2non/gock"
"encoding/json"
)
func TestNotificationSend(t *testing.T) {
defer gock.Off()
gock.New("https://pushpad.xyz").
Post("/api/v1/projects/PROJECT_ID/notifications").
MatchHeader("Content-Type", "application/json").
MatchHeader("Accept", "application/json").
MatchHeader("Authorization", "Token token=\"AUTH_TOKEN\"").
Reply(201).
BodyString("{\"id\": 123456789, \"scheduled\": 98765}")
Configure("AUTH_TOKEN", "PROJECT_ID")
n := Notification { Body: "Hello world!" }
res, err := n.Send()
if err != nil {
t.Errorf("got an error: %s", err)
}
if res.ID != 123456789 {
t.Errorf("got ID: %d, want ID: 123456789", res.ID)
}
}
func TestNotificationWithUIDs(t *testing.T) {
n := Notification { Body: "Hello user1", UIDs: []string{"user1"} }
notificationJSON, err := json.Marshal(n)
if err != nil {
t.Errorf("got an error: %s", err)
}
got := string(notificationJSON)
want := `{"body":"Hello user1","uids":["user1"],"tags":null}`
if got != want {
t.Errorf("got: %q, want: %q", got, want)
}
}
func TestNotificationWithTags(t *testing.T) {
n := Notification { Body: "Hello tag1", Tags: []string{"tag1"} }
notificationJSON, err := json.Marshal(n)
if err != nil {
t.Errorf("got an error: %s", err)
}
got := string(notificationJSON)
want := `{"body":"Hello tag1","uids":null,"tags":["tag1"]}`
if got != want {
t.Errorf("got: %q, want: %q", got, want)
}
}