add ios and android test.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-04-01 11:58:34 +08:00
parent 64db4504bb
commit 3538cfba4d
2 changed files with 41 additions and 1 deletions

View File

@ -197,6 +197,7 @@ func pushNotificationIos(req RequestPushNotification) bool {
if res.Sent() { if res.Sent() {
log.Println("APNs ID:", res.ApnsID) log.Println("APNs ID:", res.ApnsID)
return true return true
} }
} }

View File

@ -48,7 +48,7 @@ func TestAPIStatusHandler(t *testing.T) {
}) })
} }
func TestPushHandler(t *testing.T) { func TestMissingParameterPushHandler(t *testing.T) {
initTest() initTest()
r := gofight.New() r := gofight.New()
@ -63,3 +63,42 @@ func TestPushHandler(t *testing.T) {
assert.Equal(t, http.StatusBadRequest, r.Code) assert.Equal(t, http.StatusBadRequest, r.Code)
}) })
} }
func TestIosPushHandler(t *testing.T) {
initTest()
PushConf.Ios.Enabled = false
InitAPNSClient()
r := gofight.New()
r.POST("/api/push").
SetJSON(gofight.D{
"tokens": []string{"dc0ca2819417e528d8a4a01fc3e6bc7d2518ce738930c3b11203c0ef7c0fab8c"},
"platform": 1,
"message": "Welcome",
}).
Run(GetMainEngine(), func(r gofight.HttpResponse, rq gofight.HttpRequest) {
assert.Equal(t, http.StatusOK, r.Code)
})
}
func TestAndroidPushHandler(t *testing.T) {
initTest()
PushConf.Android.Enabled = true
r := gofight.New()
r.POST("/api/push").
SetJSON(gofight.D{
"tokens": []string{"aaaaaa", "bbbbb"},
"platform": 2,
"message": "Welcome",
}).
Run(GetMainEngine(), func(r gofight.HttpResponse, rq gofight.HttpRequest) {
assert.Equal(t, http.StatusOK, r.Code)
})
}