empty array instead of 404

This commit is contained in:
Arnau B
2020-12-30 12:41:53 +01:00
parent c2dd982d26
commit a32f75db78
7 changed files with 56 additions and 78 deletions

View File

@@ -29,6 +29,9 @@ type testBidsResponse struct {
}
func (t testBidsResponse) GetPending() (pendingItems, lastItemID uint64) {
if len(t.Bids) == 0 {
return 0, 0
}
pendingItems = t.PendingItems
lastItemID = t.Bids[len(t.Bids)-1].ItemID
return pendingItems, lastItemID
@@ -127,6 +130,13 @@ func TestGetBids(t *testing.T) {
}
assertBids(t, slotNumBidderAddrBids, fetchedBids)
// Empty array
fetchedBids = []testBid{}
path = fmt.Sprintf("%s?slotNum=%d&bidderAddr=%s", endpoint, 5, tc.bids[1].Bidder.String())
err = doGoodReqPaginated(path, historydb.OrderAsc, &testBidsResponse{}, appendIter)
assert.NoError(t, err)
assertBids(t, []testBid{}, fetchedBids)
// 400
// No filters
path = fmt.Sprintf("%s?limit=%d", endpoint, limit)
@@ -140,10 +150,6 @@ func TestGetBids(t *testing.T) {
path = fmt.Sprintf("%s?bidderAddr=%s", endpoint, "0xG0000001")
err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err)
// 404
path = fmt.Sprintf("%s?slotNum=%d&bidderAddr=%s", endpoint, 5, tc.bids[1].Bidder.String())
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
}
func assertBids(t *testing.T, expected, actual []testBid) {