@@ -79,20 +79,37 @@ public function testGetBooksWithSimplePagination(): void
7979
8080 public function testGetBooksWithPaginationAndOrder (): void
8181 {
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 ' ]]);
92106 $ response ->assertStatus (200 );
93107 $ data = $ response ->json ();
94108 $ this ->assertArrayHasKey ('data ' , $ data );
95109 $ 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 ' ]);
96113 $ this ->assertArrayNotHasKey ('errors ' , $ data );
97114 }
98115
0 commit comments