Skip to content

Commit

Permalink
Add search filter tests
Browse files Browse the repository at this point in the history
1. First test will fail because the relatedDummies.age is an int
bug reported here api-platform#4290

2. Second test will work because the relatedDummies.name is an string.
  • Loading branch information
jmontoyaa committed May 26, 2021
1 parent b4e02da commit d33159f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
62 changes: 62 additions & 0 deletions features/graphql/collection.feature
Expand Up @@ -909,3 +909,65 @@ Feature: GraphQL collection support
Then the response status code should be 200
And the response should be in JSON
And the JSON node "data.fooDummies.collection" should have 1 element

@createSchema
Scenario: Retrieve a collection with a nested collection filtering by age through a GraphQL query
Given there are 4 dummy objects having each 3 relatedDummies
When I send the following GraphQL request:
"""
{
dummies(name: "Dummy #1") {
totalCount
edges {
node {
name
relatedDummies(age: 31) {
totalCount
edges {
node {
id
name
age
}
}
}
}
}
}
}
"""

Then the JSON node "data.dummies.totalCount" should be equal to 1
And the JSON node "data.dummies.edges[0].node.relatedDummies.totalCount" should be equal to 1
Then the JSON node "data.dummies.edges[0].node.relatedDummies.edges[0].node.age" should be equal to "31"

@createSchema
Scenario: Retrieve a collection with a nested collection filtering by name through a GraphQL query
Given there are 4 dummy objects having each 3 relatedDummies
When I send the following GraphQL request:
"""
{
dummies(name: "Dummy #1") {
totalCount
edges {
node {
name
relatedDummies(name: "RelatedDummy31") {
totalCount
edges {
node {
id
name
age
}
}
}
}
}
}
}
"""

Then the JSON node "data.dummies.totalCount" should be equal to 1
And the JSON node "data.dummies.edges[0].node.relatedDummies.totalCount" should be equal to 1
Then the JSON node "data.dummies.edges[0].node.relatedDummies.edges[0].node.name" should be equal to "RelatedDummy31"
2 changes: 1 addition & 1 deletion tests/Behat/DoctrineContext.php
Expand Up @@ -678,7 +678,7 @@ public function thereAreDummyObjectsWithRelatedDummies(int $nb, int $nbrelated)
for ($j = 1; $j <= $nbrelated; ++$j) {
$relatedDummy = $this->buildRelatedDummy();
$relatedDummy->setName('RelatedDummy'.$j.$i);

$relatedDummy->setAge((int) ($j.$i));
$this->manager->persist($relatedDummy);

$dummy->addRelatedDummy($relatedDummy);
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/app/config/config_test.yml
Expand Up @@ -64,7 +64,7 @@ services:

app.related_dummy_resource.search_filter:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [ { 'relatedToDummyFriend.dummyFriend': 'exact', 'name': 'partial' } ]
arguments: [ { 'relatedToDummyFriend.dummyFriend': 'exact', 'name': 'partial', 'age': 'exact' } ]
tags: [ { name: 'api_platform.filter', id: 'related_dummy.friends' } ]

app.related_dummy_resource.complex_sub_query_filter:
Expand Down

0 comments on commit d33159f

Please sign in to comment.