Skip to content

Commit 0057d6e

Browse files
author
Gregory Haddow
committed
test: add test to cover with Id Encoding combined with withoutKeySort behaviour
1 parent 1386ad7 commit 0057d6e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/lib/Acceptance/Pagination/CursorPaginationTest.php

+51
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,57 @@ public function testWithoutCursor(): void
275275
$this->assertPage($posts->reverse()->take(3), $page);
276276
}
277277

278+
/**
279+
* @return void
280+
*/
281+
public function testWithIdEncodingWithoutKeySort(): void
282+
{
283+
$this->withIdEncoding();
284+
$this->paginator->withoutKeySort();
285+
286+
$posts = Post::factory()->count(4)->sequence(['title' => 'd'], ['title' => 'c'], ['title' => 'b'], ['title' => 'a'])->create();
287+
288+
$meta = [
289+
'from' => $this->encodeCursor(
290+
["posts.title"=> "a"],
291+
pointsToNextItems: false,
292+
),
293+
'hasMore' => true,
294+
'perPage' => 3,
295+
'to' => $this->encodeCursor(
296+
["posts.title"=> "c"],
297+
pointsToNextItems: true,
298+
),
299+
];
300+
301+
$links = [
302+
'first' => [
303+
'href' => 'http://localhost/api/v1/posts?' . Arr::query([
304+
'page' => ['limit' => '3'],
305+
'sort' => 'title',
306+
]),
307+
],
308+
'next' => [
309+
'href' => 'http://localhost/api/v1/posts?' . Arr::query([
310+
'page' => [
311+
'after' => $this->encodeCursor(
312+
["posts.title"=> "c"],
313+
pointsToNextItems: true,
314+
),
315+
'limit' => '3',
316+
],
317+
'sort' => 'title',
318+
]),
319+
],
320+
];
321+
322+
$page = $this->posts->repository()->queryAll()->sort('title')->paginate(['limit' => '3']);
323+
324+
$this->assertSame(['page' => $meta], $page->meta());
325+
$this->assertSame($links, $page->links()->toArray());
326+
$this->assertPage($posts->reverse()->take(3), $page);
327+
}
328+
278329
/**
279330
* @return void
280331
*/

0 commit comments

Comments
 (0)