forked from Iwark/pushnotification
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpushnotification_test.go
55 lines (47 loc) · 1.31 KB
/
pushnotification_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
package pushnotification
import (
"log"
"os"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/stretchr/testify/assert"
)
func TestSend(t *testing.T) {
assert := assert.New(t)
svc := Service{
Key: os.Getenv("KEY"),
Secret: os.Getenv("SECRET"),
Region: os.Getenv("REGION"),
// provide at least one of these, based on the devicetype
APNS: os.Getenv("APNS"),
APNSSandbox: os.Getenv("APNSSandbox"),
GCM: os.Getenv("GCM"),
Windows: os.Getenv("WINDOWS"),
Platforms: map[string]string{
"baidu": os.Getenv("baidu"),
},
}
device := &Device{
Token: os.Getenv("DEVICE_TOKEN"),
Type: os.Getenv("DEVICE_TYPE"),
EndpointArn: os.Getenv("DEVICE_ENDPOINT_ARN"), //optional
}
err := svc.Send(device, &Data{
Subject: aws.String("Subject"),
Alert: aws.String("Nice test message"),
Sound: aws.String("default"),
Badge: aws.Int(1),
Data: map[string]interface{}{
"entity": "57cd5acb3b983b0b00bdabf7",
"topic": "Nice topic",
"data": map[string]interface{}{
"evenmore": "568cef4ca041160a00911dd6",
},
},
})
assert.NoError(err)
assert.NotEqual("", device.EndpointArn, "Device endpoint Arn should be populated")
if device.IsCreated() {
log.Printf("New endpoint arn '%v' created for device token '%v'", device.EndpointArn, device.Token)
}
}