diff options
Diffstat (limited to 'internal/api/client/followrequests/get_test.go')
-rw-r--r-- | internal/api/client/followrequests/get_test.go | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/internal/api/client/followrequests/get_test.go b/internal/api/client/followrequests/get_test.go index 24f3c9646..35e4488c3 100644 --- a/internal/api/client/followrequests/get_test.go +++ b/internal/api/client/followrequests/get_test.go @@ -107,28 +107,28 @@ func (suite *GetTestSuite) TestGet() { ]`, dst.String()) } -func (suite *GetTestSuite) TestGetPageBackwardLimit2() { - suite.testGetPage(2, "backward") +func (suite *GetTestSuite) TestGetPageNewestToOldestLimit2() { + suite.testGetPage(2, "newestToOldest") } -func (suite *GetTestSuite) TestGetPageBackwardLimit4() { - suite.testGetPage(4, "backward") +func (suite *GetTestSuite) TestGetPageNewestToOldestLimit4() { + suite.testGetPage(4, "newestToOldest") } -func (suite *GetTestSuite) TestGetPageBackwardLimit6() { - suite.testGetPage(6, "backward") +func (suite *GetTestSuite) TestGetPageNewestToOldestLimit6() { + suite.testGetPage(6, "newestToOldest") } -func (suite *GetTestSuite) TestGetPageForwardLimit2() { - suite.testGetPage(2, "forward") +func (suite *GetTestSuite) TestGetPageOldestToNewestLimit2() { + suite.testGetPage(2, "oldestToNewest") } -func (suite *GetTestSuite) TestGetPageForwardLimit4() { - suite.testGetPage(4, "forward") +func (suite *GetTestSuite) TestGetPageOldestToNewestLimit4() { + suite.testGetPage(4, "oldestToNewest") } -func (suite *GetTestSuite) TestGetPageForwardLimit6() { - suite.testGetPage(6, "forward") +func (suite *GetTestSuite) TestGetPageOldestToNewestLimit6() { + suite.testGetPage(6, "oldestToNewest") } func (suite *GetTestSuite) testGetPage(limit int, direction string) { @@ -143,8 +143,11 @@ func (suite *GetTestSuite) testGetPage(limit int, direction string) { var i int - for _, targetAccount := range suite.testAccounts { - if targetAccount.ID == requestingAccount.ID { + // Have each account in the testrig follow req the + // account requesting their followers from the API. + for _, account := range suite.testAccounts { + targetAccount := requestingAccount + if account.ID == requestingAccount.ID { // we cannot be our own target... continue } @@ -158,9 +161,9 @@ func (suite *GetTestSuite) testGetPage(limit int, direction string) { ID: id, CreatedAt: now, UpdatedAt: now, - URI: fmt.Sprintf("%s/follow/%s", targetAccount.URI, id), - AccountID: targetAccount.ID, - TargetAccountID: requestingAccount.ID, + URI: fmt.Sprintf("%s/follow/%s", account.URI, id), + AccountID: account.ID, + TargetAccountID: targetAccount.ID, }) suite.NoError(err) @@ -178,15 +181,17 @@ func (suite *GetTestSuite) testGetPage(limit int, direction string) { var query string switch direction { - case "backward": - // Set the starting query to page backward from newest. + case "newestToOldest": + // Set the starting query to page from + // newest (ie., first entry in slice). acc := expectAccounts[0].(*model.Account) newest, _ := suite.db.GetFollowRequest(ctx, acc.ID, requestingAccount.ID) expectAccounts = expectAccounts[1:] query = fmt.Sprintf("limit=%d&max_id=%s", limit, newest.ID) - case "forward": - // Set the starting query to page forward from the oldest. + case "oldestToNewest": + // Set the starting query to page from + // oldest (ie., last entry in slice). acc := expectAccounts[len(expectAccounts)-1].(*model.Account) oldest, _ := suite.db.GetFollowRequest(ctx, acc.ID, requestingAccount.ID) expectAccounts = expectAccounts[:len(expectAccounts)-1] @@ -232,9 +237,9 @@ func (suite *GetTestSuite) testGetPage(limit int, direction string) { ) switch direction { - case "backward": - // When paging backwards (DESC) we: - // - iter from end of received accounts + case "newestToOldest": + // When paging newest to oldest (ie., first page to last page): + // - iter from start of received accounts // - iterate backward through received accounts // - stop when we reach last index of received accounts // - compare each received with the first index of expected accounts @@ -245,8 +250,8 @@ func (suite *GetTestSuite) testGetPage(limit int, direction string) { expect = func(i []interface{}) interface{} { return i[0] } trunc = func(i []interface{}) []interface{} { return i[1:] } - case "forward": - // When paging forwards (ASC) we: + case "oldestToNewest": + // When paging oldest to newest (ie., last page to first page): // - iter from end of received accounts // - iterate backward through received accounts // - stop when we reach first index of received accounts @@ -254,7 +259,7 @@ func (suite *GetTestSuite) testGetPage(limit int, direction string) { // - after each compare, drop the last index of expected accounts start = func(i []*model.Account) int { return len(i) - 1 } iter = func(i int) int { return i - 1 } - check = func(idx int, i []*model.Account) bool { return idx >= 0 } + check = func(idx int, _ []*model.Account) bool { return idx >= 0 } expect = func(i []interface{}) interface{} { return i[len(i)-1] } trunc = func(i []interface{}) []interface{} { return i[:len(i)-1] } } @@ -280,7 +285,14 @@ func (suite *GetTestSuite) testGetPage(limit int, direction string) { // Parse response link header values. values := result.Header.Values("Link") links := linkheader.ParseMultiple(values) - filteredLinks := links.FilterByRel("next") + + var filteredLinks linkheader.Links + if direction == "newestToOldest" { + filteredLinks = links.FilterByRel("next") + } else { + filteredLinks = links.FilterByRel("prev") + } + suite.NotEmpty(filteredLinks, "no next link provided with more remaining accounts on page=%d", p) // A ref link header was set. |