Skip to content

Commit

Permalink
fix: response for wrong filter directions can now be unmarshaled (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
morremeyer authored May 21, 2024
1 parent b30d9e5 commit 51babd0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/controllers/v4/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func GetTransactions(c *gin.Context) {
c.JSON(http.StatusBadRequest, TransactionListResponse{
Error: &s,
})
return
}

if filter.Direction == DirectionTransfer {
Expand Down
6 changes: 6 additions & 0 deletions pkg/controllers/v4/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ func (suite *TestSuiteStandard) TestTransactionsGetInvalidQuery() {
suite.T().Run(tt, func(t *testing.T) {
recorder := test.Request(t, http.MethodGet, fmt.Sprintf("http://example.com/v4/transactions?%s", tt), "")
test.AssertHTTPStatus(t, &recorder, http.StatusBadRequest)

var body v4.TransactionListResponse
test.DecodeResponse(t, &recorder, &body)

assert.Len(t, body.Data, 0)
assert.NotEmpty(t, body.Error)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Request(t *testing.T, method, reqURL string, body any, headers ...map[strin

// DecodeResponse decodes an HTTP response into a target struct.
func DecodeResponse(t *testing.T, r *httptest.ResponseRecorder, target any) {
err := json.NewDecoder(r.Body).Decode(target)
err := json.Unmarshal(r.Body.Bytes(), &target)
if err != nil {
assert.FailNow(t, "Parsing error", "Unable to parse response from server %q into %v, '%v', Request ID: %s", r.Body, reflect.TypeOf(target), err, r.Result().Header.Get("x-request-id"))
}
Expand Down

0 comments on commit 51babd0

Please sign in to comment.