mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	[Api] Check Notify (always return json) (#10059)
* BEAKING: check return status based on struct not httpStatus * update Tests * CI.restart()
This commit is contained in:
		@@ -81,9 +81,15 @@ func TestAPINotification(t *testing.T) {
 | 
				
			|||||||
	assert.EqualValues(t, thread5.Issue.APIURL(), apiN.Subject.URL)
 | 
						assert.EqualValues(t, thread5.Issue.APIURL(), apiN.Subject.URL)
 | 
				
			||||||
	assert.EqualValues(t, thread5.Repository.HTMLURL(), apiN.Repository.HTMLURL)
 | 
						assert.EqualValues(t, thread5.Repository.HTMLURL(), apiN.Repository.HTMLURL)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						new := struct {
 | 
				
			||||||
 | 
							New int64 `json:"new"`
 | 
				
			||||||
 | 
						}{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// -- check notifications --
 | 
						// -- check notifications --
 | 
				
			||||||
	req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
 | 
						req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
 | 
				
			||||||
	resp = session.MakeRequest(t, req, http.StatusOK)
 | 
						resp = session.MakeRequest(t, req, http.StatusOK)
 | 
				
			||||||
 | 
						DecodeJSON(t, resp, &new)
 | 
				
			||||||
 | 
						assert.True(t, new.New > 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// -- mark notifications as read --
 | 
						// -- mark notifications as read --
 | 
				
			||||||
	req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?token=%s", token))
 | 
						req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?token=%s", token))
 | 
				
			||||||
@@ -110,5 +116,7 @@ func TestAPINotification(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// -- check notifications --
 | 
						// -- check notifications --
 | 
				
			||||||
	req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
 | 
						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)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,15 +19,6 @@ func NewAvailable(ctx *context.APIContext) {
 | 
				
			|||||||
	// summary: Check if unread notifications exist
 | 
						// summary: Check if unread notifications exist
 | 
				
			||||||
	// responses:
 | 
						// responses:
 | 
				
			||||||
	//   "200":
 | 
						//   "200":
 | 
				
			||||||
	//    "$ref": "#/responses/NotificationCount"
 | 
						//     "$ref": "#/responses/NotificationCount"
 | 
				
			||||||
	//   "204":
 | 
						ctx.JSON(http.StatusOK, api.NotificationCount{New: models.CountUnread(ctx.User)})
 | 
				
			||||||
	//     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)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -530,9 +530,6 @@
 | 
				
			|||||||
        "responses": {
 | 
					        "responses": {
 | 
				
			||||||
          "200": {
 | 
					          "200": {
 | 
				
			||||||
            "$ref": "#/responses/NotificationCount"
 | 
					            "$ref": "#/responses/NotificationCount"
 | 
				
			||||||
          },
 | 
					 | 
				
			||||||
          "204": {
 | 
					 | 
				
			||||||
            "description": "No unread notification"
 | 
					 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user