Skip to content

Commit 51babd0

Browse files
authored
fix: response for wrong filter directions can now be unmarshaled (#1037)
1 parent b30d9e5 commit 51babd0

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

pkg/controllers/v4/transaction.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ func GetTransactions(c *gin.Context) {
227227
c.JSON(http.StatusBadRequest, TransactionListResponse{
228228
Error: &s,
229229
})
230+
return
230231
}
231232

232233
if filter.Direction == DirectionTransfer {

pkg/controllers/v4/transaction_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ func (suite *TestSuiteStandard) TestTransactionsGetInvalidQuery() {
309309
suite.T().Run(tt, func(t *testing.T) {
310310
recorder := test.Request(t, http.MethodGet, fmt.Sprintf("http://example.com/v4/transactions?%s", tt), "")
311311
test.AssertHTTPStatus(t, &recorder, http.StatusBadRequest)
312+
313+
var body v4.TransactionListResponse
314+
test.DecodeResponse(t, &recorder, &body)
315+
316+
assert.Len(t, body.Data, 0)
317+
assert.NotEmpty(t, body.Error)
312318
})
313319
}
314320
}

test/request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func Request(t *testing.T, method, reqURL string, body any, headers ...map[strin
6868

6969
// DecodeResponse decodes an HTTP response into a target struct.
7070
func DecodeResponse(t *testing.T, r *httptest.ResponseRecorder, target any) {
71-
err := json.NewDecoder(r.Body).Decode(target)
71+
err := json.Unmarshal(r.Body.Bytes(), &target)
7272
if err != nil {
7373
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"))
7474
}

0 commit comments

Comments
 (0)