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

@@ -43,6 +43,9 @@ type testExitsResponse struct {
}
func (t testExitsResponse) GetPending() (pendingItems, lastItemID uint64) {
if len(t.Exits) == 0 {
return 0, 0
}
pendingItems = t.PendingItems
lastItemID = t.Exits[len(t.Exits)-1].ItemID
return pendingItems, lastItemID
@@ -248,6 +251,12 @@ func TestGetExits(t *testing.T) {
err = doGoodReqPaginated(path, historydb.OrderDesc, &testExitsResponse{}, appendIter)
assert.NoError(t, err)
assertExitAPIs(t, flipedExits, fetchedExits)
// Empty array
fetchedExits = []testExit{}
path = fmt.Sprintf("%s?batchNum=999999", endpoint)
err = doGoodReqPaginated(path, historydb.OrderDesc, &testExitsResponse{}, appendIter)
assert.NoError(t, err)
assertExitAPIs(t, []testExit{}, fetchedExits)
// 400
path = fmt.Sprintf(
"%s?accountIndex=%s&hezEthereumAddress=%s",
@@ -258,13 +267,6 @@ func TestGetExits(t *testing.T) {
path = fmt.Sprintf("%s?tokenId=X", endpoint)
err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err)
// 404
path = fmt.Sprintf("%s?batchNum=999999", endpoint)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
path = fmt.Sprintf("%s?fromItem=1000999999", endpoint)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
}
func TestGetExit(t *testing.T) {