Skip to content

Commit 87d275a

Browse files
committed
tests: add missing cursor pagination tests
1 parent adda8b8 commit 87d275a

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/lib/Acceptance/Pagination/CursorPaginationTest.php

+55
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,45 @@ public function testWithoutCursor(): void
260260
$this->assertPage($posts->reverse()->take(3), $page);
261261
}
262262

263+
/**
264+
* @return void
265+
*/
266+
public function testWithAscending(): void
267+
{
268+
$this->paginator->withAscending();
269+
270+
$posts = Post::factory()->count(4)->create();
271+
272+
$meta = [
273+
'from' => $this->encodeCursor(["id" => "1"], pointsToNextItems: false),
274+
'hasMore' => true,
275+
'perPage' => 3,
276+
'to' => $this->encodeCursor(["id" => "3"], pointsToNextItems: true),
277+
];
278+
279+
$links = [
280+
'first' => [
281+
'href' => 'http://localhost/api/v1/posts?' . Arr::query([
282+
'page' => ['limit' => '3']
283+
]),
284+
],
285+
'next' => [
286+
'href' => 'http://localhost/api/v1/posts?' . Arr::query([
287+
'page' => [
288+
'after' => $this->encodeCursor(["id" => "3"], pointsToNextItems: true),
289+
'limit' => '3',
290+
],
291+
]),
292+
],
293+
];
294+
295+
$page = $this->posts->repository()->queryAll()->paginate(['limit' => '3']);
296+
297+
$this->assertSame(['page' => $meta], $page->meta());
298+
$this->assertSame($links, $page->links()->toArray());
299+
$this->assertPage($posts->take(3), $page);
300+
}
301+
263302
/**
264303
* @return void
265304
*/
@@ -569,6 +608,22 @@ public function testPageWithReverseKey(): void
569608
$this->assertPage($posts->take(3), $page);
570609
}
571610

611+
/**
612+
* @return void
613+
*/
614+
public function testPageWithReverseKeyWhenAscending(): void
615+
{
616+
$this->paginator->withAscending();
617+
618+
$posts = Post::factory()->count(4)->create();
619+
620+
$page = $this->posts->repository()->queryAll()
621+
->sort('-id')
622+
->paginate(['limit' => '3']);
623+
624+
$this->assertPage($posts->reverse()->take(3), $page);
625+
}
626+
572627
/**
573628
* If we are sorting by a column that might not be unique, we expect
574629
* the page to always be returned in a particular order i.e. by the

0 commit comments

Comments
 (0)