Skip to content

Commit

Permalink
Add test for non-existent post.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriszarate committed Aug 25, 2018
1 parent dc1d24c commit c3a597f
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/wpunit/PostObjectQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,61 @@ public function testPostQuery() {
$this->assertEquals( $expected, $actual );
}

/**
* testPostQueryWherePostDoesNotExist
*
* Tests a query for non existant post.
*
* @since 0.0.34
*/
public function testPostQueryWherePostDoesNotExist() {
/**
* Create the global ID based on the plugin_type and the created $id
*/
$global_id = \GraphQLRelay\Relay::toGlobalId( 'post', 'doesNotExist' );

/**
* Create the query string to pass to the $query
*/
$query = "
query {
post(id: \"{$global_id}\") {
slug
}
}";

/**
* Run the GraphQL query
*/
$actual = do_graphql_request( $query );

/**
* Establish the expectation for the output of the query
*/
$expected = [
'data' => [
'post' => null,
],
'errors' => [
[
'message' => 'No post was found with the ID: doesNotExist',
'locations' => [
[
'line' => 3,
'column' => 4,
],
],
'path' => [
'post',
],
'category' => 'user',
],
],
];

$this->assertEquals( $expected, $actual );
}

/**
* testPostQueryWithComments
*
Expand Down

0 comments on commit c3a597f

Please sign in to comment.