-
Notifications
You must be signed in to change notification settings - Fork 23
/
send_push_test.go
61 lines (52 loc) · 1.36 KB
/
send_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
package customerio_test
import (
"context"
"encoding/json"
"reflect"
"testing"
"time"
"github.com/customerio/go-customerio/v3"
)
func TestSendPush(t *testing.T) {
pushRequest := &customerio.SendPushRequest{
Identifiers: map[string]string{
"id": "customer_1",
},
To: "[email protected]",
Title: "hello, {{ trigger.name }}",
Message: "hello from the Customer.io {{ trigger.client }} client",
MessageData: map[string]interface{}{
"client": "Go",
"name": "gopher",
},
}
d, err := customerio.NewDevice("device-id", "ios", map[string]interface{}{"attr1": "value1"})
if err != nil {
t.Error(err)
}
pushRequest.Device = d
var verify = func(request []byte) {
var body customerio.SendPushRequest
if err := json.Unmarshal(request, &body); err != nil {
t.Error(err)
}
if !reflect.DeepEqual(&body, pushRequest) {
t.Errorf("Request differed, want: %#v, got: %#v", request, body)
}
}
api, srv := transactionalServer(t, verify)
defer srv.Close()
resp, err := api.SendPush(context.Background(), pushRequest)
if err != nil {
t.Error(err)
}
expect := &customerio.SendPushResponse{
TransactionalResponse: customerio.TransactionalResponse{
DeliveryID: testDeliveryID,
QueuedAt: time.Unix(int64(testQueuedAt), 0),
},
}
if !reflect.DeepEqual(resp, expect) {
t.Errorf("Expect: %#v, Got: %#v", expect, resp)
}
}