From b61764693f5e02abcfe1bace4f546152285e6058 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 1 Jul 2022 00:00:00 +1200 Subject: [PATCH] WIP database service tests --- tests/e2e/Services/GraphQL/GraphQLBase.php | 2 +- .../GraphQL/GraphQLDatabaseClientTest.php | 16 ++ .../GraphQL/GraphQLDatabaseServerTest.php | 246 ++++++++++++++++++ .../e2e/Services/GraphQL/GraphQLTeamsBase.php | 215 --------------- .../GraphQL/GraphQLTeamsClientTest.php | 164 +++++++++++- .../GraphQL/GraphQLTeamsServerTest.php | 206 ++++++++++++++- 6 files changed, 624 insertions(+), 225 deletions(-) create mode 100644 tests/e2e/Services/GraphQL/GraphQLDatabaseClientTest.php create mode 100644 tests/e2e/Services/GraphQL/GraphQLDatabaseServerTest.php delete mode 100644 tests/e2e/Services/GraphQL/GraphQLTeamsBase.php diff --git a/tests/e2e/Services/GraphQL/GraphQLBase.php b/tests/e2e/Services/GraphQL/GraphQLBase.php index dd53fd3e66..2058e59f75 100644 --- a/tests/e2e/Services/GraphQL/GraphQLBase.php +++ b/tests/e2e/Services/GraphQL/GraphQLBase.php @@ -265,7 +265,7 @@ trait GraphQLBase }'; case self::$CREATE_CUSTOM_ENTITY: return 'mutation createActor($name: String!, $age: Int!, $alive: Boolean!, $salary: Float) { - actorCreate(name: $name, age: $age, alive: $alive, salary: $salary) { + actorsCreate(name: $name, age: $age, alive: $alive, salary: $salary) { _id name age diff --git a/tests/e2e/Services/GraphQL/GraphQLDatabaseClientTest.php b/tests/e2e/Services/GraphQL/GraphQLDatabaseClientTest.php new file mode 100644 index 0000000000..158b5e7db9 --- /dev/null +++ b/tests/e2e/Services/GraphQL/GraphQLDatabaseClientTest.php @@ -0,0 +1,16 @@ +getProject()['$id']; + $query = $this->getQuery(self::$CREATE_COLLECTION); + $gqlPayload = [ + 'query' => $query, + 'variables' => [ + 'collectionId' => 'actors', + 'name' => 'Actors', + 'permission' => 'collection', + 'read' => ['role:all'], + 'write' => ['role:member'], + ] + ]; + + $actors = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $gqlPayload); + + $this->assertIsArray($actors['body']['data']); + $this->assertArrayNotHasKey('errors', $actors['body']); + $actors = $actors['body']['data']['databaseCreateCollection']; + $this->assertEquals('Actors', $actors['name']); + + return $actors; + } + + /** + * @depends testCreateCollection + * @throws Exception + */ + public function testCreateStringAttribute(array $data): void + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$CREATE_STRING_ATTRIBUTE); + $gqlPayload = [ + 'query' => $query, + 'variables' => [ + 'collectionId' => $data['_id'], + 'key' => 'name', + 'size' => 256, + 'required' => true, + ] + ]; + + $attribute = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $gqlPayload); + + $this->assertArrayNotHasKey('errors', $attribute['body']); + $this->assertIsArray($attribute['body']['data']); + $this->assertIsArray($attribute['body']['data']['databaseCreateStringAttribute']); + + // Wait for attribute to be ready + sleep(2); + } + + /** + * @depends testCreateCollection + * @throws Exception + */ + public function testCreateIntegerAttribute(array $data): void + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$CREATE_INTEGER_ATTRIBUTE); + $gqlPayload = [ + 'query' => $query, + 'variables' => [ + 'collectionId' => $data['_id'], + 'key' => 'age', + 'min' => 18, + 'max' => 150, + 'required' => true, + ] + ]; + + $attribute = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $gqlPayload); + + $this->assertArrayNotHasKey('errors', $attribute['body']); + $this->assertIsArray($attribute['body']['data']); + $this->assertIsArray($attribute['body']['data']['databaseCreateIntegerAttribute']); + + // Wait for attribute to be ready + sleep(2); + } + + /** + * @depends testCreateCollection + * @throws Exception + */ + public function testCreateBooleanAttribute(array $data): void + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$CREATE_BOOLEAN_ATTRIBUTE); + $gqlPayload = [ + 'query' => $query, + 'variables' => [ + 'collectionId' => $data['_id'], + 'key' => 'alive', + 'required' => true, + ] + ]; + + $attribute = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $gqlPayload); + + $this->assertArrayNotHasKey('errors', $attribute['body']); + $this->assertIsArray($attribute['body']['data']); + $this->assertIsArray($attribute['body']['data']['databaseCreateBooleanAttribute']); + + // Wait for attribute to be ready + sleep(2); + } + + /** + * @depends testCreateCollection + * @throws Exception + */ + public function testCreateFloatAttribute(array $data): void + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$CREATE_FLOAT_ATTRIBUTE); + $gqlPayload = [ + 'query' => $query, + 'variables' => [ + 'collectionId' => $data['_id'], + 'key' => 'salary', + 'min' => 1000.0, + 'max' => 999999.99, + 'default' => 1000.0, + 'required' => false, + ] + ]; + + $attribute = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $gqlPayload); + + $this->assertArrayNotHasKey('errors', $attribute['body']); + $this->assertIsArray($attribute['body']['data']); + $this->assertIsArray($attribute['body']['data']['databaseCreateFloatAttribute']); + + // Wait for attribute to be ready + sleep(2); + } + +// /** +// * @depends testCreateCollection +// * @depends testCreateStringAttribute +// * @depends testCreateIntegerAttribute +// * @depends testCreateBooleanAttribute +// * @depends testCreateFloatAttribute +// * @throws \Exception +// */ +// public function testCreateDocument(array $data): void +// { +// $projectId = $this->getProject()['$id']; +// $query = $this->getQuery(self::$CREATE_DOCUMENT_REST); +// $gqlPayload = [ +// 'query' => $query, +// 'variables' => [ +// 'collectionId' => $data['_id'], +// 'documentId' => 'unique()', +// 'data' => [ +// 'name' => 'John Doe', +// 'age' => 30, +// 'alive' => true, +// 'salary' => 9999.5 +// ], +// 'read' => ['role:all'], +// 'write' => ['role:all'], +// ] +// ]; +// +// $document = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $projectId, +// ], $this->getHeaders()), $gqlPayload); +// +// $this->assertArrayNotHasKey('errors', $document['body']); +// $this->assertIsArray($document['body']['data']); +// $this->assertIsArray($document['body']['data']['databaseCreateDocument']); +// } + + /** + * @depends testCreateCollection + * @depends testCreateStringAttribute + * @depends testCreateIntegerAttribute + * @depends testCreateBooleanAttribute + * @depends testCreateFloatAttribute + * @throws Exception + */ + public function testCreateCustomEntity(): void + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$CREATE_CUSTOM_ENTITY); + $gqlPayload = [ + 'query' => $query, + 'variables' => [ + 'name' => 'John Doe', + 'age' => 35, + 'alive' => true, + 'salary' => 9999.5, + ] + ]; + + $actor = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $gqlPayload); + + \var_dump($actor); + + $this->assertArrayNotHasKey('errors', $actor['body']); + $this->assertIsArray($actor['body']['data']); + $this->assertIsArray($actor['body']['data']['actorCreate']); + } + +} \ No newline at end of file diff --git a/tests/e2e/Services/GraphQL/GraphQLTeamsBase.php b/tests/e2e/Services/GraphQL/GraphQLTeamsBase.php deleted file mode 100644 index 00e1594e6e..0000000000 --- a/tests/e2e/Services/GraphQL/GraphQLTeamsBase.php +++ /dev/null @@ -1,215 +0,0 @@ -getProject()['$id']; - $query = $this->getQuery(self::$CREATE_TEAM); - $graphQLPayload = [ - 'query' => $query, - 'variables' => [ - 'teamId' => 'unique()', - 'name' => 'Team Name', - 'roles' => ['admin', 'developer', 'guest'], - ], - ]; - - $team = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), $graphQLPayload); - - $this->assertIsArray($team['body']['data']); - $this->assertArrayNotHasKey('errors', $team['body']); - $team = $team['body']['data']['teamsCreate']; - $this->assertEquals('Team Name', $team['name']); - - return $team; - } - - /** - * @depends testCreateTeam - */ - public function testCreateTeamMembership($team): array - { - $projectId = $this->getProject()['$id']; - $query = $this->getQuery(self::$CREATE_TEAM_MEMBERSHIP); - $graphQLPayload = [ - 'query' => $query, - 'variables' => [ - 'teamId' => $team['_id'], - 'email' => 'user@appwrite.io', - 'roles' => ['developer'], - 'url' => 'http://localhost/membership', - ], - ]; - - $membership = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), $graphQLPayload); - - \var_dump($membership); - - $this->assertIsArray($membership['body']['data']); - $this->assertArrayNotHasKey('errors', $membership['body']); - $membership = $membership['body']['data']['teamsCreateMembership']; - $this->assertEquals($team['_id'], $membership['teamId']); - $this->assertEquals(['developer'], $membership['roles']); - - return $membership; - } - - public function testGetTeams() - { - $projectId = $this->getProject()['$id']; - $query = $this->getQuery(self::$GET_TEAMS); - $graphQLPayload = [ - 'query' => $query, - ]; - - $teams = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), $graphQLPayload); - - $this->assertIsArray($teams['body']['data']); - $this->assertArrayNotHasKey('errors', $teams['body']); - } - - /** - * @depends testCreateTeam - */ - public function testGetTeam($team) - { - $projectId = $this->getProject()['$id']; - $query = $this->getQuery(self::$GET_TEAM); - $graphQLPayload = [ - 'query' => $query, - 'variables' => [ - 'teamId' => $team['_id'], - ], - ]; - - $team = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), $graphQLPayload); - - $this->assertIsArray($team['body']['data']); - $this->assertArrayNotHasKey('errors', $team['body']); - $team = $team['body']['data']['teamsGet']; - $this->assertIsArray($team); - } - - /** - * @depends testCreateTeam - */ - public function testGetTeamMemberships($team) - { - $projectId = $this->getProject()['$id']; - $query = $this->getQuery(self::$GET_TEAM_MEMBERSHIPS); - $graphQLPayload = [ - 'query' => $query, - 'variables' => [ - 'teamId' => $team['_id'], - ], - ]; - - $memberships = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), $graphQLPayload); - - $this->assertIsArray($memberships['body']['data']); - $this->assertArrayNotHasKey('errors', $memberships['body']); - $this->assertIsArray($memberships['body']['data']['teamsGetMemberships']); - } - - /** - * @depends testCreateTeam - * @depends testCreateTeamMembership - */ - public function testGetTeamMembership($team, $membership) - { - $projectId = $this->getProject()['$id']; - $query = $this->getQuery(self::$GET_TEAM_MEMBERSHIP); - $graphQLPayload = [ - 'query' => $query, - 'variables' => [ - 'teamId' => $team['_id'], - 'membershipId' => $membership['_id'], - ], - ]; - - $membership = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), $graphQLPayload); - - $this->assertIsArray($membership['body']['data']['teamsGetMembership']); - $this->assertArrayNotHasKey('errors', $membership['body']); - } - - /** - * @depends testCreateTeam - * @depends testCreateTeamMembership - */ - public function testUpdateTeamMembershipRoles($team, $membership) - { - $projectId = $this->getProject()['$id']; - $query = $this->getQuery(self::$UPDATE_TEAM_MEMBERSHIP_ROLES); - $graphQLPayload = [ - 'query' => $query, - 'variables' => [ - 'teamId' => $team['_id'], - 'membershipId' => $membership['_id'], - 'roles' => ['developer', 'admin'], - ], - ]; - - $membership = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), $graphQLPayload); - - $this->assertIsArray($membership['body']['data']); - $this->assertArrayNotHasKey('errors', $membership['body']); - $membership = $membership['body']['data']['teamsUpdateMembershipRoles']; - $this->assertEquals(['developer', 'admin'], $membership['roles']); - } - - /** - * @depends testCreateTeam - * @depends testCreateTeamMembership - */ - public function testDeleteTeamMembership($team, $membership) - { - $projectId = $this->getProject()['$id']; - $query = $this->getQuery(self::$DELETE_TEAM_MEMBERSHIP); - $graphQLPayload = [ - 'query' => $query, - 'variables' => [ - 'teamId' => $team['_id'], - 'membershipId' => $membership['_id'], - ], - ]; - - $team = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), $graphQLPayload); - - $this->assertEquals(200, $team['headers']['status-code']); - } -} \ No newline at end of file diff --git a/tests/e2e/Services/GraphQL/GraphQLTeamsClientTest.php b/tests/e2e/Services/GraphQL/GraphQLTeamsClientTest.php index 1a705f4b8c..3bd1ec87fe 100644 --- a/tests/e2e/Services/GraphQL/GraphQLTeamsClientTest.php +++ b/tests/e2e/Services/GraphQL/GraphQLTeamsClientTest.php @@ -3,27 +3,153 @@ namespace Tests\E2E\Services\GraphQL; use Tests\E2E\Client; +use Tests\E2E\Scopes\ProjectCustom; +use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideClient; -class GraphQLTeamsClientTest extends GraphQLTeamsBase +class GraphQLTeamsClientTest extends Scope { + use ProjectCustom; + use GraphQLBase; use SideClient; + public function testCreateTeam(): array + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$CREATE_TEAM); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'teamId' => 'unique()', + 'name' => 'Team Name', + 'roles' => ['admin', 'developer', 'guest'], + ], + ]; + + $team = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($team['body']['data']); + $this->assertArrayNotHasKey('errors', $team['body']); + $team = $team['body']['data']['teamsCreate']; + $this->assertEquals('Team Name', $team['name']); + + return $team; + } + + /** + * @depends testCreateTeam + */ + public function testCreateTeamMembership($team): array + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$CREATE_TEAM_MEMBERSHIP); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'teamId' => $team['_id'], + 'email' => 'user@appwrite.io', + 'roles' => ['developer'], + 'url' => 'http://localhost/membership', + ], + ]; + + $membership = $this->client->call(Client::METHOD_POST, '/graphql', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], $graphQLPayload); + + $this->assertIsArray($membership['body']['data']); + $this->assertArrayNotHasKey('errors', $membership['body']); + $membership = $membership['body']['data']['teamsCreateMembership']; + $this->assertEquals($team['_id'], $membership['teamId']); + $this->assertEquals(['developer'], $membership['roles']); + + return $membership; + } + + public function testGetTeams() + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_TEAMS); + $graphQLPayload = [ + 'query' => $query, + ]; + + $teams = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($teams['body']['data']); + $this->assertArrayNotHasKey('errors', $teams['body']); + } + + /** + * @depends testCreateTeam + */ + public function testGetTeam($team) + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_TEAM); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'teamId' => $team['_id'], + ], + ]; + + $team = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($team['body']['data']); + $this->assertArrayNotHasKey('errors', $team['body']); + $team = $team['body']['data']['teamsGet']; + $this->assertIsArray($team); + } + + /** + * @depends testCreateTeam + */ + public function testGetTeamMemberships($team) + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_TEAM_MEMBERSHIPS); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'teamId' => $team['_id'], + ], + ]; + + $memberships = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($memberships['body']['data']); + $this->assertArrayNotHasKey('errors', $memberships['body']); + $this->assertIsArray($memberships['body']['data']['teamsGetMemberships']); + } + /** * @depends testCreateTeam * @depends testCreateTeamMembership */ - public function testUpdateTeamMembershipStatus($team, $membership) + public function testGetTeamMembership($team, $membership) { $projectId = $this->getProject()['$id']; - $query = $this->getQuery(self::$UPDATE_TEAM_MEMBERSHIP_STATUS); + $query = $this->getQuery(self::$GET_TEAM_MEMBERSHIP); $graphQLPayload = [ 'query' => $query, 'variables' => [ 'teamId' => $team['_id'], 'membershipId' => $membership['_id'], - 'userId' => $membership['userId'], - 'secret' => 'secretkey', ], ]; @@ -32,9 +158,31 @@ class GraphQLTeamsClientTest extends GraphQLTeamsBase 'x-appwrite-project' => $projectId, ], $this->getHeaders()), $graphQLPayload); - $this->assertIsArray($membership['body']['data']); + $this->assertIsArray($membership['body']['data']['teamsGetMembership']); $this->assertArrayNotHasKey('errors', $membership['body']); - $membership = $membership['body']['data']['teamsUpdateMembershipStatus']; - $this->assertEquals('active', $membership['status']); + } + + /** + * @depends testCreateTeam + * @depends testCreateTeamMembership + */ + public function testDeleteTeamMembership($team, $membership) + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$DELETE_TEAM_MEMBERSHIP); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'teamId' => $team['_id'], + 'membershipId' => $membership['_id'], + ], + ]; + + $team = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertEquals(200, $team['headers']['status-code']); } } \ No newline at end of file diff --git a/tests/e2e/Services/GraphQL/GraphQLTeamsServerTest.php b/tests/e2e/Services/GraphQL/GraphQLTeamsServerTest.php index 666494c9bd..bc35ee100a 100644 --- a/tests/e2e/Services/GraphQL/GraphQLTeamsServerTest.php +++ b/tests/e2e/Services/GraphQL/GraphQLTeamsServerTest.php @@ -3,12 +3,164 @@ namespace Tests\E2E\Services\GraphQL; use Tests\E2E\Client; +use Tests\E2E\Scopes\ProjectCustom; +use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; -class GraphQLTeamsServerTest extends GraphQLTeamsBase +class GraphQLTeamsServerTest extends Scope { + use ProjectCustom; + use GraphQLBase; use SideServer; + public function testCreateTeam(): array + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$CREATE_TEAM); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'teamId' => 'unique()', + 'name' => 'Team Name', + 'roles' => ['admin', 'developer', 'guest'], + ], + ]; + + $team = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($team['body']['data']); + $this->assertArrayNotHasKey('errors', $team['body']); + $team = $team['body']['data']['teamsCreate']; + $this->assertEquals('Team Name', $team['name']); + + return $team; + } + + /** + * @depends testCreateTeam + */ + public function testCreateTeamMembership($team): array + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$CREATE_TEAM_MEMBERSHIP); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'teamId' => $team['_id'], + 'email' => 'user@appwrite.io', + 'roles' => ['developer'], + 'url' => 'http://localhost/membership', + ], + ]; + + $membership = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($membership['body']['data']); + $this->assertArrayNotHasKey('errors', $membership['body']); + $membership = $membership['body']['data']['teamsCreateMembership']; + $this->assertEquals($team['_id'], $membership['teamId']); + $this->assertEquals(['developer'], $membership['roles']); + + return $membership; + } + + public function testGetTeams() + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_TEAMS); + $graphQLPayload = [ + 'query' => $query, + ]; + + $teams = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($teams['body']['data']); + $this->assertArrayNotHasKey('errors', $teams['body']); + } + + /** + * @depends testCreateTeam + */ + public function testGetTeam($team) + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_TEAM); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'teamId' => $team['_id'], + ], + ]; + + $team = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($team['body']['data']); + $this->assertArrayNotHasKey('errors', $team['body']); + $team = $team['body']['data']['teamsGet']; + $this->assertIsArray($team); + } + + /** + * @depends testCreateTeam + */ + public function testGetTeamMemberships($team) + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_TEAM_MEMBERSHIPS); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'teamId' => $team['_id'], + ], + ]; + + $memberships = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($memberships['body']['data']); + $this->assertArrayNotHasKey('errors', $memberships['body']); + $this->assertIsArray($memberships['body']['data']['teamsGetMemberships']); + } + + /** + * @depends testCreateTeam + * @depends testCreateTeamMembership + */ + public function testGetTeamMembership($team, $membership) + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_TEAM_MEMBERSHIP); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'teamId' => $team['_id'], + 'membershipId' => $membership['_id'], + ], + ]; + + $membership = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($membership['body']['data']['teamsGetMembership']); + $this->assertArrayNotHasKey('errors', $membership['body']); + } + /** * @depends testCreateTeam */ @@ -35,6 +187,58 @@ class GraphQLTeamsServerTest extends GraphQLTeamsBase $this->assertEquals('New Name', $team['name']); } + /** + * @depends testCreateTeam + * @depends testCreateTeamMembership + */ + public function testUpdateTeamMembershipRoles($team, $membership) + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$UPDATE_TEAM_MEMBERSHIP_ROLES); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'teamId' => $team['_id'], + 'membershipId' => $membership['_id'], + 'roles' => ['developer', 'admin'], + ], + ]; + + $membership = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($membership['body']['data']); + $this->assertArrayNotHasKey('errors', $membership['body']); + $membership = $membership['body']['data']['teamsUpdateMembershipRoles']; + $this->assertEquals(['developer', 'admin'], $membership['roles']); + } + + /** + * @depends testCreateTeam + * @depends testCreateTeamMembership + */ + public function testDeleteTeamMembership($team, $membership) + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$DELETE_TEAM_MEMBERSHIP); + $graphQLPayload = [ + 'query' => $query, + 'variables' => [ + 'teamId' => $team['_id'], + 'membershipId' => $membership['_id'], + ], + ]; + + $team = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertEquals(200, $team['headers']['status-code']); + } + public function testDeleteTeam() { $team = $this->testCreateTeam();