diff --git a/tests/e2e/Services/GraphQL/GraphQLBase.php b/tests/e2e/Services/GraphQL/GraphQLBase.php index 1b6f5828a0..a3c2b9175a 100644 --- a/tests/e2e/Services/GraphQL/GraphQLBase.php +++ b/tests/e2e/Services/GraphQL/GraphQLBase.php @@ -13,6 +13,8 @@ trait GraphQLBase static $GET_DOCUMENT = "get_document"; static $UPDATE_DOCUMENT = "update_document"; static $CREATE_USER = "create_user"; + static $GET_USER = "get_user"; + static $DELETE_USER = "delete_user"; static $LIST_COUNTRIES = "list_countries"; static $CREATE_KEY = "create_key"; static $CREATE_ACCOUNT = "create_account"; @@ -377,6 +379,24 @@ trait GraphQLBase } }"; + case self::$DELETE_USER : + return "mutation deleteUser(\$userId: String!) { + users_deleteUser(userId : \$userId) + }"; + + case self::$GET_USER : + return "query getUser (\$userId : String!) { + users_get(userId : \$userId) { + id + name + registration + status + email + emailVerification + prefs + } + }"; + case self::$LIST_COUNTRIES: return "query listCountries { locale_getCountries{ diff --git a/tests/e2e/Services/GraphQL/GraphQLServerTest.php b/tests/e2e/Services/GraphQL/GraphQLServerTest.php index 26f5f81580..ae0b09b2c3 100644 --- a/tests/e2e/Services/GraphQL/GraphQLServerTest.php +++ b/tests/e2e/Services/GraphQL/GraphQLServerTest.php @@ -117,6 +117,78 @@ class GraphQLServerTest extends Scope $this->assertEquals(0, $data['status']); $this->assertEquals(false, $data['emailVerification']); $this->assertEquals([], $data['prefs']); + + return ['userId' => $user['body']['data']['users_create']['id']]; + } + + /** + * @depends testUserCreate + */ + public function testUserDelete(array $data) { + $projectId = $this->getProject()['$id']; + $key = ''; + $query = $this->getQuery(self::$DELETE_USER); + + $variables = [ + 'userId' => $data['userId'], + ]; + + $graphQLPayload = [ + "query" => $query, + "variables" => $variables + ]; + + $user = $this->client->call(Client::METHOD_POST, '/graphql', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $key + ], $graphQLPayload); + + $errorMessage = "User (role: guest) missing scope (users.write)"; + $this->assertEquals($user['headers']['status-code'], 401); + $this->assertEquals($user['body']['errors'][0]['message'], $errorMessage); + $this->assertIsArray($user['body']['data']); + $this->assertNull($user['body']['data']['users_deleteUser']); + + $key = $this->createKey('test', ['users.write']); + $user = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $key + ]), $graphQLPayload); + + $this->assertEquals($user['headers']['status-code'], 200); + $this->assertNull($user['body']['errors']); + $this->assertIsArray($user['body']['data']); + $this->assertIsArray($user['body']['data']['users_deleteUser']); + $this->assertEquals([], $user['body']['data']['users_deleteUser']); + + /** + * Try to fetch the user and check that its empty + */ + $query = $this->getQuery(self::$GET_USER); + $key = $this->createKey('test', ['users.read']); + $variables = [ + 'userId' => $data['userId'], + ]; + + $graphQLPayload = [ + "query" => $query, + "variables" => $variables + ]; + + $user = $this->client->call(Client::METHOD_POST, '/graphql', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $key + ], $graphQLPayload); + + $errorMessage = "User not found"; + $this->assertEquals($user['headers']['status-code'], 404); + $this->assertEquals($user['body']['errors'][0]['message'], $errorMessage); + $this->assertIsArray($user['body']['data']); + $this->assertNull($user['body']['data']['users_get']); }