Skip to content

Commit

Permalink
tests: add missing cursor pagination tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lindyhopchris committed Aug 8, 2024
1 parent adda8b8 commit 87d275a
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/lib/Acceptance/Pagination/CursorPaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,45 @@ public function testWithoutCursor(): void
$this->assertPage($posts->reverse()->take(3), $page);
}

/**
* @return void
*/
public function testWithAscending(): void
{
$this->paginator->withAscending();

$posts = Post::factory()->count(4)->create();

$meta = [
'from' => $this->encodeCursor(["id" => "1"], pointsToNextItems: false),
'hasMore' => true,
'perPage' => 3,
'to' => $this->encodeCursor(["id" => "3"], pointsToNextItems: true),
];

$links = [
'first' => [
'href' => 'http://localhost/api/v1/posts?' . Arr::query([
'page' => ['limit' => '3']
]),
],
'next' => [
'href' => 'http://localhost/api/v1/posts?' . Arr::query([
'page' => [
'after' => $this->encodeCursor(["id" => "3"], pointsToNextItems: true),
'limit' => '3',
],
]),
],
];

$page = $this->posts->repository()->queryAll()->paginate(['limit' => '3']);

$this->assertSame(['page' => $meta], $page->meta());
$this->assertSame($links, $page->links()->toArray());
$this->assertPage($posts->take(3), $page);
}

/**
* @return void
*/
Expand Down Expand Up @@ -569,6 +608,22 @@ public function testPageWithReverseKey(): void
$this->assertPage($posts->take(3), $page);
}

/**
* @return void
*/
public function testPageWithReverseKeyWhenAscending(): void
{
$this->paginator->withAscending();

$posts = Post::factory()->count(4)->create();

$page = $this->posts->repository()->queryAll()
->sort('-id')
->paginate(['limit' => '3']);

$this->assertPage($posts->reverse()->take(3), $page);
}

/**
* If we are sorting by a column that might not be unique, we expect
* the page to always be returned in a particular order i.e. by the
Expand Down

0 comments on commit 87d275a

Please sign in to comment.