@@ -260,6 +260,45 @@ public function testWithoutCursor(): void
260
260
$ this ->assertPage ($ posts ->reverse ()->take (3 ), $ page );
261
261
}
262
262
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
+
263
302
/**
264
303
* @return void
265
304
*/
@@ -569,6 +608,22 @@ public function testPageWithReverseKey(): void
569
608
$ this ->assertPage ($ posts ->take (3 ), $ page );
570
609
}
571
610
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
+
572
627
/**
573
628
* If we are sorting by a column that might not be unique, we expect
574
629
* the page to always be returned in a particular order i.e. by the
0 commit comments