1
0
Fork 0
mirror of synced 2024-07-07 23:46:11 +12:00

Add teams service tests

This commit is contained in:
Jake Barnby 2022-06-30 22:48:15 +12:00
parent fead0f89b9
commit ee9e204410
5 changed files with 360 additions and 30 deletions

View file

@ -83,14 +83,15 @@ trait GraphQLBase
public static string $DELETE_USER = 'delete_user';
// Teams
public static string $GET_TEAM = 'get_team';
public static string $LIST_TEAMS = 'list_teams';
public static string $GET_TEAMS = 'list_teams';
public static string $CREATE_TEAM = 'create_team';
public static string $UPDATE_TEAM = 'update_team';
public static string $DELETE_TEAM = 'delete_team';
public static string $GET_TEAM_MEMBERSHIP = 'get_team_membership';
public static string $LIST_TEAM_MEMBERSHIPS = 'list_team_memberships';
public static string $GET_TEAM_MEMBERSHIPS = 'list_team_memberships';
public static string $CREATE_TEAM_MEMBERSHIP = 'create_team_membership';
public static string $UPDATE_MEMBERSHIP_STATUS = 'update_membership_status';
public static string $UPDATE_TEAM_MEMBERSHIP_ROLES = 'update_team_membership_roles';
public static string $UPDATE_TEAM_MEMBERSHIP_STATUS = 'update_membership_status';
public static string $DELETE_TEAM_MEMBERSHIP = 'delete_team_membership';
// Functions
@ -664,18 +665,17 @@ trait GraphQLBase
}';
case self::$GET_TEAM:
return 'query getTeam($teamId: String!){
teamGet (teamId: $teamId) {
teamsGet (teamId: $teamId) {
_id
name
total
}
}';
case self::$LIST_TEAMS:
case self::$GET_TEAMS:
return 'query listTeams {
teamsList {
total
teams {
_id
name
total
}
@ -686,7 +686,6 @@ trait GraphQLBase
teamsCreate(teamId: $teamId, name : $name, roles: $roles) {
_id
name
dateCreated,
total
}
}';
@ -695,6 +694,7 @@ trait GraphQLBase
teamsUpdate(teamId: $teamId, name : $name) {
_id
name
total
}
}';
case self::$DELETE_TEAM:
@ -702,48 +702,65 @@ trait GraphQLBase
teamsDelete(teamId: $teamId)
}';
case self::$GET_TEAM_MEMBERSHIP:
return 'query getTeamMembership($teamId: String!, $userId: String!){
teamGetMembership (teamId: $teamId, userId: $userId) {
_id
name
email
invited
}
}';
case self::$LIST_TEAM_MEMBERSHIPS:
return 'query listTeamMemberships($teamId: String!){
teamListMemberships (teamId: $teamId) {
return 'query getTeamMembership($teamId: String!, $membershipId: String!){
teamsGetMembership (teamId: $teamId, membershipId: $membershipId) {
total
memberships {
_id
name
email
invited
teamId
userName
userEmail
}
}
}';
case self::$GET_TEAM_MEMBERSHIPS:
return 'query getTeamMemberships($teamId: String!){
teamsGetMemberships (teamId: $teamId) {
total
memberships {
_id
teamId
userName
userEmail
}
}
}';
case self::$CREATE_TEAM_MEMBERSHIP:
return 'mutation createTeamMembership($teamId: String!, $email: String!, $name: String, $roles: [Json]!, $url: String!){
return 'mutation createTeamMembership($teamId: String!, $email: String!, $name: String, $roles: [String!]!, $url: String!){
teamsCreateMembership(teamId: $teamId, email: $email, name : $name, roles: $roles, url: $url) {
_id
userId
teamId
name
email
userName
userEmail
invited
joined
confirm
roles
}
}';
case self::$UPDATE_MEMBERSHIP_STATUS:
return 'mutation updateTeamMembership($teamId: String!, $inviteId: String!, $userId: String!, $secret: String!){
teamsUpdateMembershipStatus(teamId: $teamId, inviteId: $inviteId, userId: $userId, secret: $secret ) {
case self::$UPDATE_TEAM_MEMBERSHIP_ROLES:
return 'mutation updateTeamMembershipRoles($teamId: String!, $membershipId: String!, $roles: [String!]!){
teamsUpdateMembershipRoles(teamId: $teamId, membershipId: $membershipId, roles: $roles) {
_id
userId
teamId
name
email
userName
userEmail
invited
joined
confirm
roles
}
}';
case self::$UPDATE_TEAM_MEMBERSHIP_STATUS:
return 'mutation updateTeamMembership($teamId: String!, $membershipId: String!, $userId: String!, $secret: String!){
teamsUpdateMembershipStatus(teamId: $teamId, membershipId: $membershipId, userId: $userId, secret: $secret ) {
_id
userId
teamId
userName
userEmail
invited
joined
confirm

View file

@ -408,7 +408,7 @@ class GraphQLClientTest extends Scope
$userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13);
/** Update membership status */
$query = $this->getQuery(self::$UPDATE_MEMBERSHIP_STATUS);
$query = $this->getQuery(self::$UPDATE_TEAM_MEMBERSHIP_STATUS);
$updateMembershipStatus = [
'teamId' => $team['id'],
'inviteId' => $inviteUid,

View file

@ -0,0 +1,215 @@
<?php
namespace Tests\E2E\Services\GraphQL;
use Tests\E2E\Client;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
abstract class GraphQLTeamsBase extends Scope
{
use ProjectCustom;
use GraphQLBase;
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);
\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']);
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace Tests\E2E\Services\GraphQL;
use Tests\E2E\Client;
use Tests\E2E\Scopes\SideClient;
class GraphQLTeamsClientTest extends GraphQLTeamsBase
{
use SideClient;
/**
* @depends testCreateTeam
* @depends testCreateTeamMembership
*/
public function testUpdateTeamMembershipStatus($team, $membership)
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$UPDATE_TEAM_MEMBERSHIP_STATUS);
$graphQLPayload = [
'query' => $query,
'variables' => [
'teamId' => $team['_id'],
'membershipId' => $membership['_id'],
'userId' => $membership['userId'],
'secret' => 'secretkey',
],
];
$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']['teamsUpdateMembershipStatus'];
$this->assertEquals('active', $membership['status']);
}
}

View file

@ -0,0 +1,58 @@
<?php
namespace Tests\E2E\Services\GraphQL;
use Tests\E2E\Client;
use Tests\E2E\Scopes\SideServer;
class GraphQLTeamsServerTest extends GraphQLTeamsBase
{
use SideServer;
/**
* @depends testCreateTeam
*/
public function testUpdateTeam($team)
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$UPDATE_TEAM);
$graphQLPayload = [
'query' => $query,
'variables' => [
'teamId' => $team['_id'],
'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']);
$team = $team['body']['data']['teamsUpdate'];
$this->assertEquals('New Name', $team['name']);
}
public function testDeleteTeam()
{
$team = $this->testCreateTeam();
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$DELETE_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->assertEquals(200, $team['headers']['status-code']);
}
}