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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user