]> source.dussan.org Git - gitea.git/commitdiff
[Api] Check Notify (always return json) (#10059)
author6543 <6543@obermui.de>
Fri, 10 Apr 2020 23:49:39 +0000 (01:49 +0200)
committerGitHub <noreply@github.com>
Fri, 10 Apr 2020 23:49:39 +0000 (19:49 -0400)
* BEAKING: check return status based on struct not httpStatus

* update Tests

* CI.restart()

integrations/api_notification_test.go
routers/api/v1/notify/notifications.go
templates/swagger/v1_json.tmpl

index baab00f6d29bb698667014be3890be72d379d292..3296604a081fc002b0511df59aa943ef937c4ba1 100644 (file)
@@ -81,9 +81,15 @@ func TestAPINotification(t *testing.T) {
        assert.EqualValues(t, thread5.Issue.APIURL(), apiN.Subject.URL)
        assert.EqualValues(t, thread5.Repository.HTMLURL(), apiN.Repository.HTMLURL)
 
+       new := struct {
+               New int64 `json:"new"`
+       }{}
+
        // -- check notifications --
        req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
        resp = session.MakeRequest(t, req, http.StatusOK)
+       DecodeJSON(t, resp, &new)
+       assert.True(t, new.New > 0)
 
        // -- mark notifications as read --
        req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?token=%s", token))
@@ -110,5 +116,7 @@ func TestAPINotification(t *testing.T) {
 
        // -- check notifications --
        req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
-       resp = session.MakeRequest(t, req, http.StatusNoContent)
+       resp = session.MakeRequest(t, req, http.StatusOK)
+       DecodeJSON(t, resp, &new)
+       assert.True(t, new.New == 0)
 }
index 847fe3313e0d52ee407a803ca8ff0474a67e525b..71dd7d949267f954e1f9e9e41c3baaddc2df4737 100644 (file)
@@ -19,15 +19,6 @@ func NewAvailable(ctx *context.APIContext) {
        // summary: Check if unread notifications exist
        // responses:
        //   "200":
-       //    "$ref": "#/responses/NotificationCount"
-       //   "204":
-       //     description: No unread notification
-
-       count := models.CountUnread(ctx.User)
-
-       if count > 0 {
-               ctx.JSON(http.StatusOK, api.NotificationCount{New: count})
-       } else {
-               ctx.Status(http.StatusNoContent)
-       }
+       //     "$ref": "#/responses/NotificationCount"
+       ctx.JSON(http.StatusOK, api.NotificationCount{New: models.CountUnread(ctx.User)})
 }
index 8591381ef4a7b644094931f62f9fd8b60df10075..8b10a759901d348494bbddbc0697a4cae46476b7 100644 (file)
         "responses": {
           "200": {
             "$ref": "#/responses/NotificationCount"
-          },
-          "204": {
-            "description": "No unread notification"
           }
         }
       }