1
0
Fork 0
mirror of synced 2024-09-08 05:42:15 +12:00
appwrite/tests/e2e/Services/GraphQL/TeamsServerTest.php

322 lines
10 KiB
PHP
Raw Normal View History

2022-06-30 22:48:15 +12:00
<?php
namespace Tests\E2E\Services\GraphQL;
use Tests\E2E\Client;
2022-07-01 00:00:00 +12:00
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
2022-06-30 22:48:15 +12:00
use Tests\E2E\Scopes\SideServer;
2023-01-16 22:25:40 +13:00
use Utopia\Database\Helpers\ID;
2022-06-30 22:48:15 +12:00
2022-09-22 20:29:42 +12:00
class TeamsServerTest extends Scope
2022-06-30 22:48:15 +12:00
{
2022-07-01 00:00:00 +12:00
use ProjectCustom;
2022-09-22 20:29:42 +12:00
use Base;
2022-06-30 22:48:15 +12:00
use SideServer;
2022-07-01 00:00:00 +12:00
public function testCreateTeam(): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_TEAM);
$graphQLPayload = [
'query' => $query,
'variables' => [
2022-09-22 13:53:41 +12:00
'teamId' => ID::unique(),
2022-07-01 00:00:00 +12:00
'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' => [
2022-12-08 16:08:57 +13:00
'teamId' => $team['_id'],
2022-07-01 00:00:00 +12:00
'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'];
2022-12-08 16:08:57 +13:00
$this->assertEquals($team['_id'], $membership['teamId']);
2022-07-01 00:00:00 +12:00
$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' => [
2022-12-08 16:08:57 +13:00
'teamId' => $team['_id'],
2022-07-01 00:00:00 +12:00
],
];
$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);
2023-03-24 01:54:12 +13:00
return $team;
}
/**
* @depends testGetTeam
*/
public function testUpdateTeamPrefs($team)
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$UPDATE_TEAM_PREFERENCES);
$graphQLPayload = [
'query' => $query,
'variables' => [
'teamId' => $team['_id'],
'prefs' => [
'key' => 'value'
]
],
];
$prefs = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
$this->assertIsArray($prefs['body']['data']);
$this->assertArrayNotHasKey('errors', $prefs['body']);
$this->assertIsArray($prefs['body']['data']['teamsUpdatePrefs']);
$this->assertEquals('{"key":"value"}', $prefs['body']['data']['teamsUpdatePrefs']['data']);
return $team;
}
/**
* @depends testUpdateTeamPrefs
*/
public function testGetTeamPreferences($team)
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_TEAM_PREFERENCES);
$graphQLPayload = [
'query' => $query,
'variables' => [
'teamId' => $team['_id'],
]
];
$prefs = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
$this->assertIsArray($prefs['body']['data']);
$this->assertArrayNotHasKey('errors', $prefs['body']);
$this->assertIsArray($prefs['body']['data']['teamsGetPrefs']);
2022-07-01 00:00:00 +12:00
}
/**
* @depends testCreateTeam
*/
public function testGetTeamMemberships($team)
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_TEAM_MEMBERSHIPS);
$graphQLPayload = [
'query' => $query,
'variables' => [
2022-12-08 16:08:57 +13:00
'teamId' => $team['_id'],
2022-07-01 00:00:00 +12:00
],
];
$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']);
2022-09-21 19:03:28 +12:00
$this->assertIsArray($memberships['body']['data']['teamsListMemberships']);
2022-07-01 00:00:00 +12:00
}
/**
* @depends testCreateTeam
* @depends testCreateTeamMembership
*/
public function testGetTeamMembership($team, $membership)
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_TEAM_MEMBERSHIP);
$graphQLPayload = [
'query' => $query,
'variables' => [
2022-12-08 16:08:57 +13:00
'teamId' => $team['_id'],
'membershipId' => $membership['_id'],
2022-07-01 00:00:00 +12:00
],
];
$membership = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
2022-09-22 13:55:31 +12:00
$this->assertIsArray($membership['body']['data']['teamsGetMembership']);
2022-07-01 00:00:00 +12:00
$this->assertArrayNotHasKey('errors', $membership['body']);
}
2022-06-30 22:48:15 +12:00
/**
* @depends testCreateTeam
*/
public function testUpdateTeam($team)
{
$projectId = $this->getProject()['$id'];
2023-03-24 01:54:12 +13:00
$query = $this->getQuery(self::$UPDATE_TEAM_NAME);
2022-06-30 22:48:15 +12:00
$graphQLPayload = [
'query' => $query,
'variables' => [
2022-12-08 16:08:57 +13:00
'teamId' => $team['_id'],
2022-06-30 22:48:15 +12:00
'name' => 'New Name',
],
];
$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']);
2023-03-24 01:54:12 +13:00
$team = $team['body']['data']['teamsUpdateName'];
2022-06-30 22:48:15 +12:00
$this->assertEquals('New Name', $team['name']);
}
2022-07-01 00:00:00 +12:00
/**
* @depends testCreateTeam
* @depends testCreateTeamMembership
*/
public function testUpdateTeamMembershipRoles($team, $membership)
{
$projectId = $this->getProject()['$id'];
2023-08-18 09:58:04 +12:00
$query = $this->getQuery(self::$UPDATE_TEAM_MEMBERSHIP);
2022-07-01 00:00:00 +12:00
$graphQLPayload = [
'query' => $query,
'variables' => [
2022-12-08 16:08:57 +13:00
'teamId' => $team['_id'],
'membershipId' => $membership['_id'],
2022-07-01 00:00:00 +12:00
'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']);
2023-08-18 11:08:30 +12:00
$membership = $membership['body']['data']['teamsUpdateMembership'];
2022-07-01 00:00:00 +12:00
$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' => [
2022-12-08 16:08:57 +13:00
'teamId' => $team['_id'],
'membershipId' => $membership['_id'],
2022-07-01 00:00:00 +12:00
],
];
$team = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
2022-07-18 21:38:13 +12:00
$this->assertIsNotArray($team['body']);
$this->assertEquals(204, $team['headers']['status-code']);
2022-07-01 00:00:00 +12:00
}
2022-06-30 22:48:15 +12:00
public function testDeleteTeam()
{
$team = $this->testCreateTeam();
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$DELETE_TEAM);
$graphQLPayload = [
'query' => $query,
'variables' => [
2022-12-08 16:08:57 +13:00
'teamId' => $team['_id'],
2022-06-30 22:48:15 +12:00
],
];
$team = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
2022-07-18 21:38:13 +12:00
$this->assertIsNotArray($team['body']);
$this->assertEquals(204, $team['headers']['status-code']);
2022-06-30 22:48:15 +12:00
}
2022-07-12 09:52:00 +12:00
}