@@ -79,20 +79,37 @@ public function testGetBooksWithSimplePagination(): void
79
79
80
80
public function testGetBooksWithPaginationAndOrder (): void
81
81
{
82
- BookFactory::new ()->has (AuthorFactory::new ())->count (10 )->create ();
83
- $ response = $ this ->postJson ('/api/graphql ' , ['query ' => '{
84
- books(first: 3, order: {name: "desc"}) {
85
- edges {
86
- node {
87
- id, name, publicationDate, author { id, name }
88
- }
89
- }
90
- }
91
- } ' ], ['accept ' => ['application/json ' ]]);
82
+ // Create books in reverse alphabetical order to test the 'asc' order
83
+ BookFactory::new ()
84
+ ->count (10 )
85
+ ->sequence (fn ($ sequence ) => ['name ' => \chr (122 - $ sequence ->index )]) // ASCII codes starting from 'z'
86
+ ->has (AuthorFactory::new ())
87
+ ->create ();
88
+
89
+ $ response = $ this ->postJson ('/api/graphql ' , [
90
+ 'query ' => '
91
+ query getBooks($first: Int!, $order: orderBookcollection_query!) {
92
+ books(first: $first, order: $order) {
93
+ edges {
94
+ node {
95
+ id, name, publicationDate, author { id, name }
96
+ }
97
+ }
98
+ }
99
+ }
100
+ ' ,
101
+ 'variables ' => [
102
+ 'first ' => 3 ,
103
+ 'order ' => ['name ' => 'asc ' ],
104
+ ],
105
+ ], ['accept ' => ['application/json ' ]]);
92
106
$ response ->assertStatus (200 );
93
107
$ data = $ response ->json ();
94
108
$ this ->assertArrayHasKey ('data ' , $ data );
95
109
$ this ->assertCount (3 , $ data ['data ' ]['books ' ]['edges ' ]);
110
+ $ this ->assertEquals ('q ' , $ data ['data ' ]['books ' ]['edges ' ][0 ]['node ' ]['name ' ]);
111
+ $ this ->assertEquals ('r ' , $ data ['data ' ]['books ' ]['edges ' ][1 ]['node ' ]['name ' ]);
112
+ $ this ->assertEquals ('s ' , $ data ['data ' ]['books ' ]['edges ' ][2 ]['node ' ]['name ' ]);
96
113
$ this ->assertArrayNotHasKey ('errors ' , $ data );
97
114
}
98
115
0 commit comments