Skip to content

Commit

Permalink
test(SortPlugin): add integration test for multi-sort
Browse files Browse the repository at this point in the history
  • Loading branch information
flamerohr committed Jul 7, 2023
1 parent 2981640 commit 47811b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
21 changes: 18 additions & 3 deletions tests/Schema/IntegrationTest.php
Expand Up @@ -425,6 +425,9 @@ public function testFilterAndSort()
$dataObject2 = DataObjectFake::create(['MyField' => 'test2', 'AuthorID' => $author2->ID]);
$dataObject2->write();

$dataObject3 = DataObjectFake::create(['MyField' => 'test3', 'AuthorID' => $author2->ID]);
$dataObject3->write();

$file1 = File::create(['Title' => 'file1']);
$file1->write();

Expand All @@ -436,6 +439,7 @@ public function testFilterAndSort()

$id1 = $dataObject1->ID;
$id2 = $dataObject2->ID;
$id3 = $dataObject3->ID;

$schema = $this->createSchema(new TestSchemaBuilder([$dir]));

Expand Down Expand Up @@ -474,7 +478,7 @@ public function testFilterAndSort()

$query = <<<GRAPHQL
query {
readOneDataObjectFake(sort: { myField: DESC }) {
readOneDataObjectFake(sort: { AuthorID: DESC , myField: ASC }) {
myField
}
}
Expand All @@ -485,14 +489,25 @@ public function testFilterAndSort()

$query = <<<GRAPHQL
query {
readOneDataObjectFake(sort: { myField: DESC }, filter: { id: { ne: $id2 } }) {
readOneDataObjectFake(sort: { myField: DESC }) {
myField
}
}
GRAPHQL;
$result = $this->querySchema($schema, $query);
$this->assertSuccess($result);
$this->assertResult('readOneDataObjectFake.myField', 'test1', $result);
$this->assertResult('readOneDataObjectFake.myField', 'test3', $result);

$query = <<<GRAPHQL
query {
readOneDataObjectFake(sort: { myField: DESC }, filter: { id: { ne: $id3 } }) {
myField
}
}
GRAPHQL;
$result = $this->querySchema($schema, $query);
$this->assertSuccess($result);
$this->assertResult('readOneDataObjectFake.myField', 'test2', $result);

$query = <<<GRAPHQL
query {
Expand Down
1 change: 1 addition & 0 deletions tests/Schema/_testFilterAndSort/models.yml
Expand Up @@ -6,6 +6,7 @@ SilverStripe\GraphQL\Tests\Fake\DataObjectFake:
sort: true
fields:
myField: true
AuthorID: true
author:
fields:
firstName: true
Expand Down

0 comments on commit 47811b8

Please sign in to comment.