Skip to content

Commit

Permalink
test: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpoulain committed May 27, 2021
1 parent 292086f commit 3ff2293
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 63 deletions.
92 changes: 31 additions & 61 deletions features/graphql/filters.feature
Expand Up @@ -84,6 +84,36 @@ Feature: Collections filtering
Then the JSON node "data.dummies.edges" should have 1 element
And the JSON node "data.dummies.edges[0].node.id" should be equal to "/dummies/2"

@createSchema
Scenario: Retrieve a collection filtered using the search filter with an int
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
And the JSON node "data.dummies.edges[0].node.relatedDummies.edges[0].node.age" should be equal to "31"

@createSchema
Scenario: Retrieve a collection filtered using the search filter and a name converter
Given there are 10 dummy objects
Expand Down Expand Up @@ -130,7 +160,7 @@ Feature: Collections filtering
And the JSON node "data.convertedOwners.edges[1].node.name_converted.name_converted" should be equal to "Converted 20"

@createSchema
Scenario: Retrieve a collection filtered using the search filter
Scenario: Retrieve a nested collection filtered using the search filter
Given there are 3 dummy objects having each 3 relatedDummies
When I send the following GraphQL request:
"""
Expand Down Expand Up @@ -270,63 +300,3 @@ Feature: Collections filtering
And the JSON node "data.dummies.edges" should have 2 element
And the JSON node "data.dummies.edges[0].node.relatedDummy.name" should be equal to "RelatedDummy #1"
And the JSON node "data.dummies.edges[1].node.relatedDummy.name" should be equal to "RelatedDummy #2"

@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
And 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
And the JSON node "data.dummies.edges[0].node.relatedDummies.edges[0].node.name" should be equal to "RelatedDummy31"
2 changes: 1 addition & 1 deletion src/Bridge/Doctrine/Common/Filter/SearchFilterTrait.php
Expand Up @@ -136,7 +136,7 @@ protected function getIdFromValue(string $value)
protected function normalizeValues(array $values, string $property): ?array
{
foreach ($values as $key => $value) {
if (!\is_int($key) || \is_array($value)) {
if (!\is_int($key) || !(\is_string($value) || \is_int($value))) {
unset($values[$key]);
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Bridge/Doctrine/Common/Filter/SearchFilterTestTrait.php
Expand Up @@ -474,6 +474,14 @@ private function provideApplyTestArguments(): array
'relatedDummy.symfony' => [],
],
],
'integer value' => [
[
'age' => 'exact',
],
[
'age' => 46,
],
],
];
}
}
15 changes: 15 additions & 0 deletions tests/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilterTest.php
Expand Up @@ -690,6 +690,21 @@ public function provideApplyTestData(): array
[],
$filterFactory,
],
'integer value' => [
[
[
'$match' => [
'age' => [
'$in' => [
'46',
],
],
],
],
],
$filterFactory,
RelatedDummy::class,
],
]
);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Bridge/Doctrine/Orm/Filter/SearchFilterTest.php
Expand Up @@ -567,6 +567,12 @@ public function provideApplyTestData(): array
[],
$filterFactory,
],
'integer value' => [
sprintf('SELECT %s FROM %s %1$s WHERE %1$s.age = :age_p1', $this->alias, RelatedDummy::class),
['age_p1' => 46],
$filterFactory,
RelatedDummy::class,
],
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/app/config/config_mongodb.yml
Expand Up @@ -54,7 +54,7 @@ services:
tags: [ { name: 'api_platform.filter', id: 'my_dummy.mongodb.search' } ]
app.related_dummy_resource.mongodb.search_filter:
parent: 'api_platform.doctrine_mongodb.odm.search_filter'
arguments: [ { 'relatedToDummyFriend.dummyFriend': 'exact', 'name': 'partial' } ]
arguments: [ { 'relatedToDummyFriend.dummyFriend': 'exact', 'name': 'partial', 'age': 'exact' } ]
tags: [ { name: 'api_platform.filter', id: 'related_dummy.mongodb.friends' } ]
app.my_dummy_date_resource.mongodb.date_filter:
parent: 'api_platform.doctrine_mongodb.odm.date_filter'
Expand Down

0 comments on commit 3ff2293

Please sign in to comment.