Skip to content

Commit

Permalink
Adds tests for description and deprecationReason parameters of mutati…
Browse files Browse the repository at this point in the history
…onWithClientMutationId
  • Loading branch information
Tpt committed Mar 2, 2018
1 parent 3cf9cb7 commit 4f6bc75
Showing 1 changed file with 150 additions and 0 deletions.
150 changes: 150 additions & 0 deletions tests/Mutation/MutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ class MutationTest extends \PHPUnit_Framework_TestCase
*/
protected $simpleMutation;

/**
* @var ObjectType
*/
protected $simpleMutationWithDescription;

/**
* @var ObjectType
*/
protected $simpleMutationWithDeprecationReason;

/**
* @var ObjectType
*/
Expand Down Expand Up @@ -56,6 +66,34 @@ public function setup()
}
]);

$this->simpleMutationWithDescription = Mutation::mutationWithClientMutationId([
'name' => 'SimpleMutationWithDescription',
'description' => 'Simple Mutation Description',
'inputFields' => [],
'outputFields' => [
'result' => [
'type' => Type::int()
]
],
'mutateAndGetPayload' => function () {
return ['result' => 1];
}
]);

$this->simpleMutationWithDeprecationReason = Mutation::mutationWithClientMutationId([
'name' => 'SimpleMutationWithDeprecationReason',
'inputFields' => [],
'outputFields' => [
'result' => [
'type' => Type::int()
]
],
'mutateAndGetPayload' => function () {
return ['result' => 1];
},
'deprecationReason' => 'Just because'
]);

$this->simpleMutationWithThunkFields = Mutation::mutationWithClientMutationId([
'name' => 'SimpleMutationWithThunkFields',
'inputFields' => function() {
Expand Down Expand Up @@ -105,6 +143,8 @@ public function setup()
'name' => 'Mutation',
'fields' => [
'simpleMutation' => $this->simpleMutation,
'simpleMutationWithDescription' => $this->simpleMutationWithDescription,
'simpleMutationWithDeprecationReason' => $this->simpleMutationWithDeprecationReason,
'simpleMutationWithThunkFields' => $this->simpleMutationWithThunkFields,
'edgeMutation' => $this->edgeMutation
]
Expand Down Expand Up @@ -332,6 +372,26 @@ public function testContainsCorrectField()
'kind' => 'OBJECT',
]
],
[
'name' => 'simpleMutationWithDescription',
'args' => [
[
'name' => 'input',
'type' => [
'name' => null,
'kind' => 'NON_NULL',
'ofType' => [
'name' => 'SimpleMutationWithDescriptionInput',
'kind' => 'INPUT_OBJECT'
]
],
]
],
'type' => [
'name' => 'SimpleMutationWithDescriptionPayload',
'kind' => 'OBJECT',
]
],
[
'name' => 'simpleMutationWithThunkFields',
'args' => [
Expand Down Expand Up @@ -404,6 +464,96 @@ public function testContainsCorrectField()
$this->assertValidQuery($query, $expected);
}

public function testContainsCorrectDescriptions() {
$query = '{
__schema {
mutationType {
fields {
name
description
}
}
}
}';

$expected = [
'__schema' => [
'mutationType' => [
'fields' => [
[
'name' => 'simpleMutation',
'description' => null
],
[
'name' => 'simpleMutationWithDescription',
'description' => 'Simple Mutation Description'
],
[
'name' => 'simpleMutationWithThunkFields',
'description' => null
],
[
'name' => 'edgeMutation',
'description' => null
]
]
]
]
];

$this->assertValidQuery($query, $expected);
}

public function testContainsCorrectDeprecationReasons() {
$query = '{
__schema {
mutationType {
fields(includeDeprecated: true) {
name
isDeprecated
deprecationReason
}
}
}
}';

$expected = [
'__schema' => [
'mutationType' => [
'fields' => [
[
'name' => 'simpleMutation',
'isDeprecated' => false,
'deprecationReason' => null
],
[
'name' => 'simpleMutationWithDescription',
'isDeprecated' => false,
'deprecationReason' => null
],
[
'name' => 'simpleMutationWithDeprecationReason',
'isDeprecated' => true,
'deprecationReason' => 'Just because',
],
[
'name' => 'simpleMutationWithThunkFields',
'isDeprecated' => false,
'deprecationReason' => null
],
[
'name' => 'edgeMutation',
'isDeprecated' => false,
'deprecationReason' => null
]
]
]
]
];

$this->assertValidQuery($query, $expected);
}

/**
* Helper function to test a query and the expected response.
*/
Expand Down

0 comments on commit 4f6bc75

Please sign in to comment.