Skip to content

Commit 0dadea1

Browse files
authored
[Api] Check Notify (always return json) (#10059)
* BEAKING: check return status based on struct not httpStatus * update Tests * CI.restart()
1 parent c97e988 commit 0dadea1

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

integrations/api_notification_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,15 @@ func TestAPINotification(t *testing.T) {
8181
assert.EqualValues(t, thread5.Issue.APIURL(), apiN.Subject.URL)
8282
assert.EqualValues(t, thread5.Repository.HTMLURL(), apiN.Repository.HTMLURL)
8383

84+
new := struct {
85+
New int64 `json:"new"`
86+
}{}
87+
8488
// -- check notifications --
8589
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
8690
resp = session.MakeRequest(t, req, http.StatusOK)
91+
DecodeJSON(t, resp, &new)
92+
assert.True(t, new.New > 0)
8793

8894
// -- mark notifications as read --
8995
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?token=%s", token))
@@ -110,5 +116,7 @@ func TestAPINotification(t *testing.T) {
110116

111117
// -- check notifications --
112118
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
113-
resp = session.MakeRequest(t, req, http.StatusNoContent)
119+
resp = session.MakeRequest(t, req, http.StatusOK)
120+
DecodeJSON(t, resp, &new)
121+
assert.True(t, new.New == 0)
114122
}

routers/api/v1/notify/notifications.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ func NewAvailable(ctx *context.APIContext) {
1919
// summary: Check if unread notifications exist
2020
// responses:
2121
// "200":
22-
// "$ref": "#/responses/NotificationCount"
23-
// "204":
24-
// description: No unread notification
25-
26-
count := models.CountUnread(ctx.User)
27-
28-
if count > 0 {
29-
ctx.JSON(http.StatusOK, api.NotificationCount{New: count})
30-
} else {
31-
ctx.Status(http.StatusNoContent)
32-
}
22+
// "$ref": "#/responses/NotificationCount"
23+
ctx.JSON(http.StatusOK, api.NotificationCount{New: models.CountUnread(ctx.User)})
3324
}

templates/swagger/v1_json.tmpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,6 @@
530530
"responses": {
531531
"200": {
532532
"$ref": "#/responses/NotificationCount"
533-
},
534-
"204": {
535-
"description": "No unread notification"
536533
}
537534
}
538535
}

0 commit comments

Comments
 (0)