Refactor integration test DecodeJSON calls to use generic return value (#37432)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Copilot
2026-04-26 14:57:07 +00:00
committed by GitHub
parent 99cd4f6b22
commit 2671b997f2
105 changed files with 569 additions and 930 deletions
+16 -19
View File
@@ -37,8 +37,7 @@ func TestAPINotification(t *testing.T) {
req := NewRequest(t, "GET", "/api/v1/notifications?since="+since).
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
var apiNL []api.NotificationThread
DecodeJSON(t, resp, &apiNL)
apiNL := DecodeJSON(t, resp, []api.NotificationThread{})
assert.Len(t, apiNL, 1)
assert.EqualValues(t, 5, apiNL[0].ID)
@@ -49,7 +48,7 @@ func TestAPINotification(t *testing.T) {
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?all=%s&before=%s", "true", before)).
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
apiNL = DecodeJSON(t, resp, []api.NotificationThread{})
assert.Len(t, apiNL, 3)
assert.EqualValues(t, 4, apiNL[0].ID)
@@ -66,7 +65,7 @@ func TestAPINotification(t *testing.T) {
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?status-types=unread", user2.Name, repo1.Name)).
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
apiNL = DecodeJSON(t, resp, []api.NotificationThread{})
assert.Len(t, apiNL, 1)
assert.EqualValues(t, 4, apiNL[0].ID)
@@ -75,7 +74,7 @@ func TestAPINotification(t *testing.T) {
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?status-types=unread&status-types=pinned", user2.Name, repo1.Name)).
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
apiNL = DecodeJSON(t, resp, []api.NotificationThread{})
assert.Len(t, apiNL, 2)
assert.EqualValues(t, 4, apiNL[0].ID)
@@ -97,8 +96,7 @@ func TestAPINotification(t *testing.T) {
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d", thread5.ID)).
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
var apiN api.NotificationThread
DecodeJSON(t, resp, &apiN)
apiN := DecodeJSON(t, resp, &api.NotificationThread{})
assert.EqualValues(t, 5, apiN.ID)
assert.False(t, apiN.Pinned)
@@ -110,22 +108,20 @@ func TestAPINotification(t *testing.T) {
MakeRequest(t, NewRequest(t, "GET", "/api/v1/notifications/new"), http.StatusUnauthorized)
newStruct := struct {
New int64 `json:"new"`
}{}
// -- check notifications --
req = NewRequest(t, "GET", "/api/v1/notifications/new").
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &newStruct)
newStruct := DecodeJSON(t, resp, &struct {
New int64 `json:"new"`
}{})
assert.Positive(t, newStruct.New)
// -- mark notifications as read --
req = NewRequest(t, "GET", "/api/v1/notifications?status-types=unread").
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
apiNL = DecodeJSON(t, resp, []api.NotificationThread{})
assert.Len(t, apiNL, 2)
lastReadAt := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801 <- only Notification 4 is in this filter ...
@@ -136,7 +132,7 @@ func TestAPINotification(t *testing.T) {
req = NewRequest(t, "GET", "/api/v1/notifications?status-types=unread").
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
apiNL = DecodeJSON(t, resp, []api.NotificationThread{})
assert.Len(t, apiNL, 1)
// -- PATCH /notifications/threads/{id} --
@@ -152,7 +148,9 @@ func TestAPINotification(t *testing.T) {
req = NewRequest(t, "GET", "/api/v1/notifications/new").
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &newStruct)
newStruct = DecodeJSON(t, resp, &struct {
New int64 `json:"new"`
}{})
assert.Zero(t, newStruct.New)
}
@@ -169,8 +167,7 @@ func TestAPINotificationPUT(t *testing.T) {
req := NewRequest(t, "GET", "/api/v1/notifications?all=true").
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
var apiNL []api.NotificationThread
DecodeJSON(t, resp, &apiNL)
apiNL := DecodeJSON(t, resp, []api.NotificationThread{})
assert.Len(t, apiNL, 4)
assert.EqualValues(t, 5, apiNL[0].ID)
@@ -193,7 +190,7 @@ func TestAPINotificationPUT(t *testing.T) {
req = NewRequest(t, "PUT", "/api/v1/notifications?status-types=read&status-type=pinned&to-status=unread").
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusResetContent)
DecodeJSON(t, resp, &apiNL)
apiNL = DecodeJSON(t, resp, []api.NotificationThread{})
assert.Len(t, apiNL, 1)
assert.EqualValues(t, 2, apiNL[0].ID)
assert.True(t, apiNL[0].Unread)
@@ -205,7 +202,7 @@ func TestAPINotificationPUT(t *testing.T) {
req = NewRequest(t, "GET", "/api/v1/notifications?all=true").
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL)
apiNL = DecodeJSON(t, resp, []api.NotificationThread{})
assert.Len(t, apiNL, 4)
assert.EqualValues(t, 2, apiNL[0].ID)