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
+6 -10
View File
@@ -51,8 +51,7 @@ func TestAPIIssuesReactions(t *testing.T) {
Reaction: "rocket",
}).AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusCreated)
var apiNewReaction api.Reaction
DecodeJSON(t, resp, &apiNewReaction)
apiNewReaction := DecodeJSON(t, resp, &api.Reaction{})
// Add existing reaction
req = NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
@@ -71,15 +70,14 @@ func TestAPIIssuesReactions(t *testing.T) {
req = NewRequest(t, "GET", urlStr).
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
var apiReactions []*api.Reaction
DecodeJSON(t, resp, &apiReactions)
apiReactions := DecodeJSON(t, resp, []*api.Reaction{})
expectResponse := make(map[int]api.Reaction)
expectResponse[0] = api.Reaction{
User: convert.ToUser(t.Context(), user2, user2),
Reaction: "eyes",
Created: time.Unix(1573248003, 0),
}
expectResponse[1] = apiNewReaction
expectResponse[1] = *apiNewReaction
assert.Len(t, apiReactions, 2)
for i, r := range apiReactions {
assert.Equal(t, expectResponse[i].Reaction, r.Reaction)
@@ -141,8 +139,7 @@ func TestAPICommentReactions(t *testing.T) {
Reaction: "+1",
}).AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusCreated)
var apiNewReaction api.Reaction
DecodeJSON(t, resp, &apiNewReaction)
apiNewReaction := DecodeJSON(t, resp, &api.Reaction{})
// Add existing reaction
req = NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
@@ -154,8 +151,7 @@ func TestAPICommentReactions(t *testing.T) {
req = NewRequest(t, "GET", urlStr).
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
var apiReactions []*api.Reaction
DecodeJSON(t, resp, &apiReactions)
apiReactions := DecodeJSON(t, resp, []*api.Reaction{})
expectResponse := make(map[int]api.Reaction)
expectResponse[0] = api.Reaction{
User: convert.ToUser(t.Context(), user2, user2),
@@ -167,7 +163,7 @@ func TestAPICommentReactions(t *testing.T) {
Reaction: "laugh",
Created: time.Unix(1573248005, 0),
}
expectResponse[2] = apiNewReaction
expectResponse[2] = *apiNewReaction
assert.Len(t, apiReactions, 3)
for i, r := range apiReactions {
assert.Equal(t, expectResponse[i].Reaction, r.Reaction)