From 51c7589136cfc9fdde0a597032d52b1edeb534dc Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Thu, 8 Feb 2024 10:21:01 +0000 Subject: [PATCH] Add failing test case for named sort args --- tests/Schema/IntegrationTest.php | 264 +++++++++++++++++-------------- 1 file changed, 148 insertions(+), 116 deletions(-) diff --git a/tests/Schema/IntegrationTest.php b/tests/Schema/IntegrationTest.php index c3cab186..60bb0176 100644 --- a/tests/Schema/IntegrationTest.php +++ b/tests/Schema/IntegrationTest.php @@ -674,133 +674,165 @@ public function testFieldAliases() public function provideFilterAndSortOnlyRead(): array { return [ - 'read with sort' => [ - 'fixture' => '_QuerySort', - 'query' => << [ - ["myField" => "test2", "author" => ["firstName" => "tester2"]], - ["myField" => "test3", "author" => ["firstName" => "tester2"]], - ["myField" => "test1", "author" => ["firstName" => "tester1"]], + 'read with sort' => [ + 'fixture' => '_QuerySort', + 'query' => << [], + 'expected' => [ + ["myField" => "test2", "author" => ["firstName" => "tester2"]], + ["myField" => "test3", "author" => ["firstName" => "tester2"]], + ["myField" => "test1", "author" => ["firstName" => "tester1"]], + ], ], - ], - 'read with sorter files title DESC' => [ - 'fixture' => '_SortPlugin', - 'query' => << [ - ["myField" => "test1", "files" => [["title" => "file4"], ["title" => "file3"], ["title" => "file2"], ["title" => "file1"]]], - ["myField" => "test2", "files" => []], - ["myField" => "test3", "files" => []], + 'read with sorter files title DESC' => [ + 'fixture' => '_SortPlugin', + 'query' => << [], + 'expected' => [ + ["myField" => "test1", "files" => [["title" => "file4"], ["title" => "file3"], ["title" => "file2"], ["title" => "file1"]]], + ["myField" => "test2", "files" => []], + ["myField" => "test3", "files" => []], + ], ], - ], - 'read with sorter files ParentID ACS, name DESC' => [ - 'fixture' => '_SortPlugin', - 'query' => << [ - ["myField" => "test1", "files" => [["title" => "file2"],["title" => "file1"], ["title" => "file4"],["title" => "file3"]]], - ["myField" => "test2", "files" => []], - ["myField" => "test3", "files" => []], + 'read with sorter files ParentID ACS, name DESC' => [ + 'fixture' => '_SortPlugin', + 'query' => << [], + 'expected' => [ + ["myField" => "test1", "files" => [["title" => "file2"], ["title" => "file1"], ["title" => "file4"], ["title" => "file3"]]], + ["myField" => "test2", "files" => []], + ["myField" => "test3", "files" => []], + ], ], - ], - 'read with sorter files ParentID DESC, name ASC' => [ - 'fixture' => '_SortPlugin', - 'query' => << [ - ["myField" => "test1", "files" => [["title" => "file3"],["title" => "file4"], ["title" => "file1"],["title" => "file2"]]], - ["myField" => "test2", "files" => []], - ["myField" => "test3", "files" => []], + 'read with sorter files ParentID DESC, name ASC' => [ + 'fixture' => '_SortPlugin', + 'query' => << [], + 'expected' => [ + ["myField" => "test1", "files" => [["title" => "file3"], ["title" => "file4"], ["title" => "file1"], ["title" => "file2"]]], + ["myField" => "test2", "files" => []], + ["myField" => "test3", "files" => []], + ], ], - ], - 'read with sorter files name ASC, ParentID DESC' => [ - 'fixture' => '_SortPlugin', - 'query' => << [ - ["myField" => "test1", "files" => [["title" => "file3"],["title" => "file1"], ["title" => "file4"],["title" => "file2"]]], - ["myField" => "test2", "files" => []], - ["myField" => "test3", "files" => []], + 'read with sorter files name ASC, ParentID DESC' => [ + 'fixture' => '_SortPlugin', + 'query' => << [], + 'expected' => [ + ["myField" => "test1", "files" => [["title" => "file3"], ["title" => "file1"], ["title" => "file4"], ["title" => "file2"]]], + ["myField" => "test2", "files" => []], + ["myField" => "test3", "files" => []], + ], ], - ], - 'read with sorter files name DESC, ParentID ASC' => [ - 'fixture' => '_SortPlugin', - 'query' => << [ - ["myField" => "test1", "files" => [["title" => "file2"],[ "title" => "file4"],["title" => "file1"],["title" => "file3"]]], - ["myField" => "test2", "files" => []], - ["myField" => "test3", "files" => []], + 'read with sort - with named sort arg' => [ + 'fixture' => '_QuerySort', + 'query' => << [ + 'sort' => ['author' => ['id' => 'DESC'], 'myField' => 'ASC'] + ], + 'expected' => [ + ["myField" => "test2", "author" => ["firstName" => "tester2"]], + ["myField" => "test3", "author" => ["firstName" => "tester2"]], + ["myField" => "test1", "author" => ["firstName" => "tester1"]], + ], + ], + 'read with sorter files ParentID DESC, name ASC - with named sort args' => [ + 'fixture' => '_SortPlugin', + 'query' => << [ + 'sort' => ['myField' => 'ASC'], + 'fileSort' => ['ParentID' => 'DESC', 'name' => 'ASC'], + ], + 'expected' => [ + ["myField" => "test1", "files" => [["title" => "file2"], ["title" => "file4"], ["title" => "file1"], ["title" => "file3"]]], + ["myField" => "test2", "files" => []], + ["myField" => "test3", "files" => []], + ], ], - ], ]; } /** * @dataProvider provideFilterAndSortOnlyRead */ - public function testFilterAndSortOnlyRead(string $fixture, string $query, array $expected) + public function testFilterAndSortOnlyRead(string $fixture, string $query, array $args, array $expected) { $author = Member::create(['FirstName' => 'tester1']); $author->write(); @@ -841,7 +873,7 @@ public function testFilterAndSortOnlyRead(string $fixture, string $query, array $factory = new TestSchemaBuilder(['_' . __FUNCTION__ . $fixture]); $schema = $this->createSchema($factory); - $result = $this->querySchema($schema, $query); + $result = $this->querySchema($schema, $query, $args); $this->assertSuccess($result); $records = $result['data']['readDataObjectFakes']['nodes'] ?? []; $this->assertResults($expected, $records);