From a8994a51104359e2a03569ade4b94d202bcaa9f4 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Tue, 22 May 2018 10:19:13 +0800 Subject: [PATCH] fix(debug): show error message. (#356) --- gorush/server.go | 2 +- gorush/server_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/gorush/server.go b/gorush/server.go index 1f3c3e7..3e4570d 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -49,7 +49,7 @@ func pushHandler(c *gin.Context) { if err := c.ShouldBindWith(&form, binding.JSON); err != nil { msg = "Missing notifications field." - LogAccess.Debug(msg) + LogAccess.Debug(err) abortWithError(c, http.StatusBadRequest, msg) return } diff --git a/gorush/server_test.go b/gorush/server_test.go index 3b80317..faa0741 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -218,6 +218,35 @@ func TestEmptyNotifications(t *testing.T) { }) } +func TestMutableContent(t *testing.T) { + initTest() + + r := gofight.New() + + // notifications is empty. + r.POST("/api/push"). + SetJSON(gofight.D{ + "notifications": []gofight.D{ + { + "tokens": []string{"aaaaa", "bbbbb"}, + "platform": PlatFormAndroid, + "message": "Welcome", + "mutable-content": 1, + "topic": "test", + "badge": 1, + "alert": gofight.D{ + "title": "title", + "body": "body", + }, + }, + }, + }). + Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { + // json: cannot unmarshal number into Go struct field PushNotification.mutable-content of type bool + assert.Equal(t, http.StatusBadRequest, r.Code) + }) +} + func TestOutOfRangeMaxNotifications(t *testing.T) { initTest()