-
Notifications
You must be signed in to change notification settings - Fork 0
/
push_test.go
67 lines (62 loc) · 1.44 KB
/
push_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
package gomeng
import (
"context"
"os"
"testing"
)
func newTest() (client *Client, payload Payload, token string) {
cfg := &Config{
AppKey: os.Getenv("APP_KEY"),
AppSecret: os.Getenv("APP_SECRET"),
Timeout: defaultTimeout,
}
return NewClient(cfg), Payload{
"display_type": "notification",
"body": map[string]interface{}{
"ticker": "test_ticker",
"title": "test_title",
"text": "test_text",
"builder_id:": 1,
"custom": map[string]interface{}{
"key1": "value1",
"key2": "value2",
"key3": "value3",
},
"after_open": "go_app",
"play_sound": "true",
},
}, os.Getenv("DEVICE_TOKEN")
}
func TestPush2SingleUser(t *testing.T) {
c, payload, token := newTest()
rm, err := c.Unicast(context.Background(), payload, token)
if err != nil {
t.Errorf("err: %v", err)
return
}
if err := rm.Error(); err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
}
}
func TestPush2MultiUsers(t *testing.T) {
c, payload, token := newTest()
rm, err := c.ListCast(context.Background(), payload, token)
if err != nil {
t.Errorf("err: %v", err)
return
}
if err := rm.Error(); err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
}
}
func TestPush2AllUsers(t *testing.T) {
c, payload, _ := newTest()
rm, err := c.Broadcast(context.Background(), payload)
if err != nil {
t.Errorf("err: %v", err)
return
}
if err := rm.Error(); err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
}
}