2020-01-16 14:06:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\Teams;
|
|
|
|
|
|
|
|
|
|
use Tests\E2E\Client;
|
2023-12-20 10:55:09 +00:00
|
|
|
use Utopia\Database\Document;
|
2023-02-05 20:07:46 +00:00
|
|
|
use Utopia\Database\Helpers\ID;
|
2023-12-20 10:55:09 +00:00
|
|
|
use Utopia\Database\Query;
|
2023-03-01 12:00:36 +00:00
|
|
|
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
2020-01-16 14:06:28 +00:00
|
|
|
|
|
|
|
|
trait TeamsBaseClient
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateTeam
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
public function testGetTeamMemberships($data): array
|
2020-01-16 14:06:28 +00:00
|
|
|
{
|
2020-10-14 21:11:12 +00:00
|
|
|
$teamUid = $data['teamUid'] ?? '';
|
2022-05-12 13:20:06 +00:00
|
|
|
$teamName = $data['teamName'] ?? '';
|
2020-01-16 14:06:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for SUCCESS
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
|
2020-01-16 14:06:28 +00:00
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-16 14:06:28 +00:00
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertIsInt($response['body']['total']);
|
2020-06-08 08:01:11 +00:00
|
|
|
$this->assertNotEmpty($response['body']['memberships'][0]['$id']);
|
2024-02-25 16:47:26 +00:00
|
|
|
$this->assertFalse($response['body']['memberships'][0]['mfa']);
|
2024-11-07 18:12:41 +00:00
|
|
|
$this->assertArrayHasKey('userName', $response['body']['memberships'][0]);
|
|
|
|
|
$this->assertArrayHasKey('userEmail', $response['body']['memberships'][0]);
|
2022-05-12 13:20:06 +00:00
|
|
|
$this->assertEquals($teamName, $response['body']['memberships'][0]['teamName']);
|
2022-08-27 23:01:46 +00:00
|
|
|
$this->assertContains('owner', $response['body']['memberships'][0]['roles']);
|
|
|
|
|
$this->assertContains('player', $response['body']['memberships'][0]['roles']);
|
2020-01-16 14:06:28 +00:00
|
|
|
|
2022-02-16 16:26:05 +00:00
|
|
|
$membershipId = $response['body']['memberships'][0]['$id'];
|
|
|
|
|
|
2022-08-24 11:55:43 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
2023-12-20 10:55:09 +00:00
|
|
|
'queries' => [
|
|
|
|
|
Query::limit(1)->toString(),
|
|
|
|
|
],
|
2022-08-24 11:55:43 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2023-05-03 11:53:40 +00:00
|
|
|
$this->assertCount(1, $response['body']['memberships']);
|
2022-08-24 11:55:43 +00:00
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
2023-12-20 10:55:09 +00:00
|
|
|
'queries' => [
|
|
|
|
|
Query::offset(1)->toString(),
|
|
|
|
|
],
|
2022-08-24 11:55:43 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
$this->assertCount(0, $response['body']['memberships']);
|
|
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
2023-12-20 10:55:09 +00:00
|
|
|
'queries' => [
|
|
|
|
|
Query::equal('confirm', [true])->toString(),
|
|
|
|
|
],
|
2022-08-24 11:55:43 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
$this->assertCount(1, $response['body']['memberships']);
|
|
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
2023-12-20 10:55:09 +00:00
|
|
|
'queries' => [
|
|
|
|
|
Query::equal('confirm', [false])->toString(),
|
|
|
|
|
],
|
2022-08-24 11:55:43 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
$this->assertCount(0, $response['body']['memberships']);
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
|
2022-02-16 16:26:05 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'search' => $this->getUser()['$id']
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertIsInt($response['body']['total']);
|
2022-02-16 16:26:05 +00:00
|
|
|
$this->assertNotEmpty($response['body']['memberships'][0]);
|
2024-11-07 18:12:41 +00:00
|
|
|
$this->assertArrayHasKey('userName', $response['body']['memberships'][0]);
|
|
|
|
|
$this->assertArrayHasKey('userEmail', $response['body']['memberships'][0]);
|
2022-05-12 13:20:06 +00:00
|
|
|
$this->assertEquals($teamName, $response['body']['memberships'][0]['teamName']);
|
2022-08-27 23:01:46 +00:00
|
|
|
$this->assertContains('owner', $response['body']['memberships'][0]['roles']);
|
|
|
|
|
$this->assertContains('player', $response['body']['memberships'][0]['roles']);
|
2022-02-16 16:26:05 +00:00
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
|
2022-02-16 16:26:05 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'search' => $membershipId
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertIsInt($response['body']['total']);
|
2022-02-16 16:26:05 +00:00
|
|
|
$this->assertNotEmpty($response['body']['memberships'][0]);
|
2024-11-07 18:12:41 +00:00
|
|
|
$this->assertArrayHasKey('userName', $response['body']['memberships'][0]);
|
|
|
|
|
$this->assertArrayHasKey('userEmail', $response['body']['memberships'][0]);
|
2022-05-12 13:20:06 +00:00
|
|
|
$this->assertEquals($teamName, $response['body']['memberships'][0]['teamName']);
|
2022-08-27 23:01:46 +00:00
|
|
|
$this->assertContains('owner', $response['body']['memberships'][0]['roles']);
|
|
|
|
|
$this->assertContains('player', $response['body']['memberships'][0]['roles']);
|
2022-02-16 16:26:05 +00:00
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
|
2022-02-16 16:26:05 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'search' => 'unknown'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertIsInt($response['body']['total']);
|
2022-02-16 16:26:05 +00:00
|
|
|
$this->assertEmpty($response['body']['memberships']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertEquals(0, $response['body']['total']);
|
2022-02-16 16:26:05 +00:00
|
|
|
|
2020-01-16 14:06:28 +00:00
|
|
|
/**
|
|
|
|
|
* Test for FAILURE
|
|
|
|
|
*/
|
|
|
|
|
|
2020-10-27 19:48:38 +00:00
|
|
|
return $data;
|
2020-01-16 14:06:28 +00:00
|
|
|
}
|
2020-01-18 20:02:47 +00:00
|
|
|
|
2022-09-22 08:06:30 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateTeamMembership
|
|
|
|
|
*/
|
|
|
|
|
public function testGetTeamMembership($data): void
|
|
|
|
|
{
|
|
|
|
|
$teamUid = $data['teamUid'] ?? '';
|
|
|
|
|
$membershipUid = $data['membershipUid'] ?? '';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for SUCCESS
|
|
|
|
|
*/
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships/' . $membershipUid, array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2024-02-25 16:47:26 +00:00
|
|
|
$this->assertFalse($response['body']['mfa']);
|
2022-09-22 08:06:30 +00:00
|
|
|
$this->assertNotEmpty($response['body']['userId']);
|
2024-11-07 18:12:41 +00:00
|
|
|
$this->assertArrayHasKey('userName', $response['body']);
|
|
|
|
|
$this->assertArrayHasKey('userEmail', $response['body']);
|
2022-09-22 08:06:30 +00:00
|
|
|
$this->assertNotEmpty($response['body']['teamId']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['teamName']);
|
2024-09-05 03:43:02 +00:00
|
|
|
$this->assertCount(1, $response['body']['roles']);
|
2023-02-05 20:39:41 +00:00
|
|
|
$this->assertEquals(false, (new DatetimeValidator())->isValid($response['body']['joined'])); // is null in DB
|
2022-09-22 08:06:30 +00:00
|
|
|
$this->assertEquals(false, $response['body']['confirm']);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for FAILURE
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships/' . $membershipUid . 'dasdasd', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships/' . $membershipUid, [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-18 20:02:47 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateTeam
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
public function testCreateTeamMembership($data): array
|
2020-01-18 20:02:47 +00:00
|
|
|
{
|
2020-10-14 21:11:12 +00:00
|
|
|
$teamUid = $data['teamUid'] ?? '';
|
|
|
|
|
$teamName = $data['teamName'] ?? '';
|
2022-05-23 14:54:50 +00:00
|
|
|
$email = uniqid() . 'friend@localhost.test';
|
2021-05-04 18:52:46 +00:00
|
|
|
$name = 'Friend User';
|
2020-01-18 20:02:47 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for SUCCESS
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
2020-01-18 20:02:47 +00:00
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-18 20:02:47 +00:00
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'email' => $email,
|
2021-05-04 18:52:46 +00:00
|
|
|
'name' => $name,
|
2024-09-05 03:29:41 +00:00
|
|
|
'roles' => ['developer'],
|
2020-01-18 20:02:47 +00:00
|
|
|
'url' => 'http://localhost:5000/join-us#title'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
2020-02-17 07:16:11 +00:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-01-18 20:02:47 +00:00
|
|
|
$this->assertNotEmpty($response['body']['userId']);
|
2022-07-22 23:51:58 +00:00
|
|
|
$this->assertEquals($name, $response['body']['userName']);
|
|
|
|
|
$this->assertEquals($email, $response['body']['userEmail']);
|
2020-01-18 20:02:47 +00:00
|
|
|
$this->assertNotEmpty($response['body']['teamId']);
|
2022-05-12 13:20:06 +00:00
|
|
|
$this->assertNotEmpty($response['body']['teamName']);
|
2024-09-05 03:43:02 +00:00
|
|
|
$this->assertCount(1, $response['body']['roles']);
|
2023-02-05 20:39:41 +00:00
|
|
|
$this->assertEquals(false, (new DatetimeValidator())->isValid($response['body']['joined'])); // is null in DB
|
2020-01-18 20:02:47 +00:00
|
|
|
$this->assertEquals(false, $response['body']['confirm']);
|
|
|
|
|
|
2020-01-19 12:22:54 +00:00
|
|
|
$lastEmail = $this->getLastEmail();
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($email, $lastEmail['to'][0]['address']);
|
2021-05-04 18:52:46 +00:00
|
|
|
$this->assertEquals($name, $lastEmail['to'][0]['name']);
|
2022-05-23 14:54:50 +00:00
|
|
|
$this->assertEquals('Invitation to ' . $teamName . ' Team at ' . $this->getProject()['name'], $lastEmail['subject']);
|
2025-03-29 11:49:46 +00:00
|
|
|
|
2025-03-29 12:52:59 +00:00
|
|
|
$tokens = $this->extractQueryParamsFromEmailLink($lastEmail['html']);
|
2025-03-29 11:49:46 +00:00
|
|
|
$this->assertEquals($teamName, $tokens['teamName']);
|
|
|
|
|
$this->assertEquals($response['body']['teamId'], $tokens['teamId']);
|
2020-01-19 12:22:54 +00:00
|
|
|
|
2023-01-09 09:17:45 +00:00
|
|
|
/**
|
|
|
|
|
* Test with UserId
|
|
|
|
|
* Create user
|
|
|
|
|
*/
|
|
|
|
|
$secondEmail = uniqid() . 'foe@localhost.test';
|
|
|
|
|
$secondName = 'Another Foe';
|
2023-12-11 20:56:59 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', [
|
2023-01-09 09:17:45 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2023-12-11 20:56:59 +00:00
|
|
|
], [
|
2023-01-09 09:17:45 +00:00
|
|
|
'userId' => 'unique()',
|
|
|
|
|
'email' => $secondEmail,
|
|
|
|
|
'password' => 'password',
|
|
|
|
|
'name' => $secondName
|
|
|
|
|
]);
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
$userId = $response['body']['$id'];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for UserID
|
|
|
|
|
* Failure
|
|
|
|
|
*/
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'userId' => 'abcdefdg',
|
2024-09-05 03:29:41 +00:00
|
|
|
'roles' => ['developer'],
|
2023-01-09 09:17:45 +00:00
|
|
|
'url' => 'http://localhost:5000/join-us#title'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for UserID
|
|
|
|
|
* SUCCESS
|
|
|
|
|
*/
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'userId' => $userId,
|
2024-09-05 03:29:41 +00:00
|
|
|
'roles' => ['developer'],
|
2023-01-09 09:17:45 +00:00
|
|
|
'url' => 'http://localhost:5000/join-us#title'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['userId']);
|
|
|
|
|
$this->assertEquals($secondName, $response['body']['userName']);
|
|
|
|
|
$this->assertEquals($secondEmail, $response['body']['userEmail']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['teamId']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['teamName']);
|
2024-09-05 03:43:02 +00:00
|
|
|
$this->assertCount(1, $response['body']['roles']);
|
2023-02-21 05:18:41 +00:00
|
|
|
$this->assertEquals(false, (new DateTimeValidator())->isValid($response['body']['joined'])); // is null in DB
|
2023-01-09 09:17:45 +00:00
|
|
|
$this->assertEquals(false, $response['body']['confirm']);
|
|
|
|
|
|
|
|
|
|
$lastEmail = $this->getLastEmail();
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($secondEmail, $lastEmail['to'][0]['address']);
|
|
|
|
|
$this->assertEquals($secondName, $lastEmail['to'][0]['name']);
|
|
|
|
|
$this->assertEquals('Invitation to ' . $teamName . ' Team at ' . $this->getProject()['name'], $lastEmail['subject']);
|
2025-03-29 11:49:46 +00:00
|
|
|
|
2025-03-29 12:52:59 +00:00
|
|
|
$tokens = $this->extractQueryParamsFromEmailLink($lastEmail['html']);
|
2025-03-29 11:49:46 +00:00
|
|
|
$this->assertEquals($teamName, $tokens['teamName']);
|
|
|
|
|
$this->assertEquals($response['body']['teamId'], $tokens['teamId']);
|
2023-01-09 09:18:13 +00:00
|
|
|
|
2025-01-16 04:27:25 +00:00
|
|
|
// test for resending invitation
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
2021-05-09 18:37:47 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'email' => $email,
|
|
|
|
|
'name' => 'Friend User',
|
2024-09-05 03:29:41 +00:00
|
|
|
'roles' => ['developer'],
|
2021-05-09 18:37:47 +00:00
|
|
|
'url' => 'http://localhost:5000/join-us#title'
|
|
|
|
|
]);
|
|
|
|
|
|
2025-01-13 18:25:48 +00:00
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
2025-02-12 10:48:32 +00:00
|
|
|
$lastEmail = $this->getLastEmail();
|
2025-03-29 12:52:59 +00:00
|
|
|
$tokens = $this->extractQueryParamsFromEmailLink($lastEmail['html']);
|
2025-03-29 11:49:46 +00:00
|
|
|
$membershipUid = $tokens['membershipId'];
|
|
|
|
|
$userUid = $tokens['userId'];
|
|
|
|
|
$secret = $tokens['secret'];
|
2025-02-12 10:48:32 +00:00
|
|
|
|
2025-01-13 18:25:48 +00:00
|
|
|
/**
|
|
|
|
|
* Test for FAILURE
|
|
|
|
|
*/
|
2021-05-09 18:37:47 +00:00
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
2020-01-19 10:43:06 +00:00
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-19 10:43:06 +00:00
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'email' => 'dasdkaskdjaskdjasjkd',
|
2021-05-04 18:52:46 +00:00
|
|
|
'name' => $name,
|
2024-09-05 03:29:41 +00:00
|
|
|
'roles' => ['developer'],
|
2020-01-19 10:43:06 +00:00
|
|
|
'url' => 'http://localhost:5000/join-us#title'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2020-01-18 20:02:47 +00:00
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
2020-01-19 12:22:54 +00:00
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-19 12:22:54 +00:00
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'email' => $email,
|
2021-05-04 18:52:46 +00:00
|
|
|
'name' => $name,
|
2020-01-19 12:22:54 +00:00
|
|
|
'roles' => 'bad string',
|
|
|
|
|
'url' => 'http://localhost:5000/join-us#title'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
return [
|
2025-03-29 11:49:46 +00:00
|
|
|
'teamUid' => $tokens['teamId'],
|
|
|
|
|
'teamName' => $tokens['teamName'],
|
|
|
|
|
'secret' => $tokens['secret'],
|
|
|
|
|
'membershipUid' => $tokens['membershipId'],
|
|
|
|
|
'userUid' => $tokens['userId'],
|
2021-05-04 18:52:46 +00:00
|
|
|
'email' => $email,
|
|
|
|
|
'name' => $name
|
2020-01-19 12:22:54 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 13:04:14 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateTeamMembership
|
|
|
|
|
*/
|
|
|
|
|
public function testListTeamMemberships($data): void
|
|
|
|
|
{
|
2022-05-23 14:54:50 +00:00
|
|
|
$memberships = $this->client->call(Client::METHOD_GET, '/teams/' . $data['teamUid'] . '/memberships', array_merge([
|
2021-08-09 13:04:14 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $memberships['headers']['status-code']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertIsInt($memberships['body']['total']);
|
2021-08-09 13:04:14 +00:00
|
|
|
$this->assertNotEmpty($memberships['body']['memberships']);
|
2023-01-09 09:17:45 +00:00
|
|
|
$this->assertCount(3, $memberships['body']['memberships']);
|
2021-08-09 13:04:14 +00:00
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $data['teamUid'] . '/memberships', array_merge([
|
2021-08-09 13:04:14 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
2023-12-20 10:55:09 +00:00
|
|
|
'queries' => [
|
|
|
|
|
Query::cursorAfter(new Document(['$id' => $memberships['body']['memberships'][0]['$id']]))->toString(),
|
|
|
|
|
],
|
2021-08-09 13:04:14 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertIsInt($response['body']['total']);
|
2021-08-09 13:04:14 +00:00
|
|
|
$this->assertNotEmpty($response['body']['memberships']);
|
2023-01-09 09:17:45 +00:00
|
|
|
$this->assertCount(2, $response['body']['memberships']);
|
2021-08-09 13:04:14 +00:00
|
|
|
$this->assertEquals($memberships['body']['memberships'][1]['$id'], $response['body']['memberships'][0]['$id']);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-19 12:22:54 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateTeamMembership
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
public function testUpdateTeamMembership($data): array
|
2020-01-19 12:22:54 +00:00
|
|
|
{
|
2020-10-14 21:11:12 +00:00
|
|
|
$teamUid = $data['teamUid'] ?? '';
|
|
|
|
|
$secret = $data['secret'] ?? '';
|
2021-05-07 16:54:56 +00:00
|
|
|
$membershipUid = $data['membershipUid'] ?? '';
|
2020-10-14 21:11:12 +00:00
|
|
|
$userUid = $data['userUid'] ?? '';
|
2021-05-04 18:52:46 +00:00
|
|
|
$email = $data['email'] ?? '';
|
|
|
|
|
$name = $data['name'] ?? '';
|
2020-01-19 12:22:54 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for SUCCESS
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipUid . '/status', array_merge([
|
2020-01-19 12:22:54 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-19 12:22:54 +00:00
|
|
|
]), [
|
|
|
|
|
'secret' => $secret,
|
2022-08-15 11:24:31 +00:00
|
|
|
'userId' => $userUid,
|
2020-01-19 12:22:54 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-02-17 07:16:11 +00:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-01-19 12:22:54 +00:00
|
|
|
$this->assertNotEmpty($response['body']['userId']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['teamId']);
|
2024-09-05 03:43:02 +00:00
|
|
|
$this->assertCount(1, $response['body']['roles']);
|
2023-02-05 20:39:41 +00:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['joined']));
|
2020-01-19 12:22:54 +00:00
|
|
|
$this->assertEquals(true, $response['body']['confirm']);
|
2023-12-08 23:17:13 +00:00
|
|
|
$session = $response['cookies']['a_session_' . $this->getProject()['$id']];
|
2021-05-13 17:59:54 +00:00
|
|
|
$data['session'] = $session;
|
2021-05-04 18:52:46 +00:00
|
|
|
|
2022-11-24 11:40:17 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
|
]));
|
|
|
|
|
|
2024-01-18 13:19:30 +00:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-11-24 11:40:17 +00:00
|
|
|
$this->assertEquals(true, $response['body']['emailVerification']);
|
|
|
|
|
|
2021-05-13 18:01:57 +00:00
|
|
|
|
|
|
|
|
/** [START] TESTS TO CHECK PASSWORD UPDATE OF NEW USER CREATED USING TEAM INVITE */
|
2021-05-04 18:52:46 +00:00
|
|
|
/**
|
|
|
|
|
* New User tries to update password without old password -> SHOULD PASS
|
|
|
|
|
*/
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([
|
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-23 14:54:50 +00:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-05-04 18:52:46 +00:00
|
|
|
]), [
|
|
|
|
|
'password' => 'new-password'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2023-02-05 20:39:41 +00:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['registration']));
|
2021-05-04 18:52:46 +00:00
|
|
|
$this->assertEquals($response['body']['email'], $email);
|
|
|
|
|
$this->assertEquals($response['body']['name'], $name);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* New User again tries to update password with ONLY new password -> SHOULD FAIL
|
|
|
|
|
*/
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([
|
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-23 14:54:50 +00:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-05-04 18:52:46 +00:00
|
|
|
]), [
|
|
|
|
|
'password' => 'new-password',
|
|
|
|
|
]);
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* New User tries to update password by passing both old and new password -> SHOULD PASS
|
|
|
|
|
*/
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([
|
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-23 14:54:50 +00:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-05-04 18:52:46 +00:00
|
|
|
]), [
|
|
|
|
|
'password' => 'newer-password',
|
|
|
|
|
'oldPassword' => 'new-password'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
|
|
|
|
$this->assertIsArray($response['body']);
|
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2023-02-05 20:39:41 +00:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['registration']));
|
2021-05-04 18:52:46 +00:00
|
|
|
$this->assertEquals($response['body']['email'], $email);
|
|
|
|
|
$this->assertEquals($response['body']['name'], $name);
|
2021-05-12 13:44:41 +00:00
|
|
|
|
2021-05-13 18:01:57 +00:00
|
|
|
/** [END] TESTS TO CHECK PASSWORD UPDATE OF NEW USER CREATED USING TEAM INVITE */
|
2020-01-19 12:22:54 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for FAILURE
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipUid . '/status', array_merge([
|
2020-01-19 12:22:54 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-19 12:22:54 +00:00
|
|
|
]), [
|
|
|
|
|
'secret' => 'sdasdasd',
|
2022-08-15 11:24:31 +00:00
|
|
|
'userId' => $userUid,
|
2020-01-19 12:22:54 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipUid . '/status', array_merge([
|
2020-01-19 12:22:54 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-19 12:22:54 +00:00
|
|
|
]), [
|
|
|
|
|
'secret' => '',
|
2022-08-15 11:24:31 +00:00
|
|
|
'userId' => $userUid,
|
2020-01-19 12:22:54 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipUid . '/status', array_merge([
|
2020-01-19 12:22:54 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-19 12:22:54 +00:00
|
|
|
]), [
|
|
|
|
|
'secret' => $secret,
|
2022-08-14 10:33:36 +00:00
|
|
|
'userId' => ID::custom('sdasd'),
|
2020-01-19 12:22:54 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipUid . '/status', array_merge([
|
2020-01-19 12:22:54 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-19 12:22:54 +00:00
|
|
|
]), [
|
|
|
|
|
'secret' => $secret,
|
2023-03-01 12:00:36 +00:00
|
|
|
'userId' => ID::custom('$notallowed'),
|
2020-01-19 12:22:54 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipUid . '/status', array_merge([
|
2022-01-18 22:32:36 +00:00
|
|
|
'origin' => 'http://localhost',
|
2023-03-01 12:00:36 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
]), [
|
|
|
|
|
'secret' => $secret,
|
2024-01-09 02:54:46 +00:00
|
|
|
'userId' => ID::custom('asdf'),
|
2023-03-01 12:00:36 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipUid . '/status', array_merge([
|
2022-01-18 22:32:36 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
]), [
|
|
|
|
|
'secret' => $secret,
|
2022-08-15 11:24:31 +00:00
|
|
|
'userId' => $userUid,
|
2022-01-18 22:32:36 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(409, $response['headers']['status-code']);
|
|
|
|
|
|
2020-01-19 13:36:30 +00:00
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-19 15:47:14 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateTeam
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateMembershipWithSession(array $data): void
|
|
|
|
|
{
|
|
|
|
|
$teamUid = $data['teamUid'] ?? '';
|
|
|
|
|
|
|
|
|
|
// create user
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], [
|
|
|
|
|
'userId' => 'unique()',
|
|
|
|
|
'email' => uniqid() . 'foe@localhost.test',
|
|
|
|
|
'password' => 'password',
|
|
|
|
|
'name' => 'test'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
$user = $response['body'];
|
|
|
|
|
|
|
|
|
|
// create session
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions', [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], [
|
|
|
|
|
'email' => $user['email'],
|
|
|
|
|
'password' => 'password'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
$session = $response['cookies']['a_session_' . $this->getProject()['$id']];
|
|
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'email' => $user['email'],
|
|
|
|
|
'roles' => ['developer'],
|
|
|
|
|
'url' => 'http://localhost:5000/join-us#title'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
$lastEmail = $this->getLastEmail();
|
2025-03-29 12:52:59 +00:00
|
|
|
$tokens = $this->extractQueryParamsFromEmailLink($lastEmail['html']);
|
2024-11-19 15:47:14 +00:00
|
|
|
|
2025-03-29 11:49:46 +00:00
|
|
|
$secret = $tokens['secret'];
|
|
|
|
|
$membershipUid = $tokens['membershipId'];
|
|
|
|
|
$userUid = $tokens['userId'];
|
2024-11-19 15:47:14 +00:00
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipUid . '/status', [
|
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
|
|
|
|
], [
|
|
|
|
|
'secret' => $secret,
|
|
|
|
|
'userId' => $userUid,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['userId']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['teamId']);
|
|
|
|
|
$this->assertCount(1, $response['body']['roles']);
|
|
|
|
|
$this->assertEmpty($response['cookies']);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-19 13:36:30 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testUpdateTeamMembership
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
public function testUpdateTeamMembershipRoles($data): array
|
2020-01-19 13:36:30 +00:00
|
|
|
{
|
2020-10-14 21:11:12 +00:00
|
|
|
$teamUid = $data['teamUid'] ?? '';
|
2021-05-07 16:54:56 +00:00
|
|
|
$membershipUid = $data['membershipUid'] ?? '';
|
2021-05-12 17:00:22 +00:00
|
|
|
$session = $data['session'] ?? '';
|
|
|
|
|
|
2020-01-19 13:36:30 +00:00
|
|
|
/**
|
|
|
|
|
* Test for SUCCESS
|
|
|
|
|
*/
|
2024-09-05 03:29:41 +00:00
|
|
|
$roles = ['editor', 'uncle'];
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipUid, array_merge([
|
2020-01-19 13:36:30 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2021-05-12 17:00:22 +00:00
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'roles' => $roles
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['userId']);
|
|
|
|
|
$this->assertNotEmpty($response['body']['teamId']);
|
|
|
|
|
$this->assertCount(count($roles), $response['body']['roles']);
|
|
|
|
|
$this->assertEquals($roles[0], $response['body']['roles'][0]);
|
|
|
|
|
$this->assertEquals($roles[1], $response['body']['roles'][1]);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for unknown team
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . 'abc' . '/memberships/' . $membershipUid, array_merge([
|
2021-05-12 17:00:22 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'roles' => $roles
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
2020-01-19 13:36:30 +00:00
|
|
|
|
2021-05-12 17:00:22 +00:00
|
|
|
/**
|
|
|
|
|
* Test for unknown membership ID
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . 'abc', array_merge([
|
2021-05-12 17:00:22 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'roles' => $roles
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
|
2021-05-12 17:00:22 +00:00
|
|
|
/**
|
|
|
|
|
* Test for when a user other than the owner tries to update membership
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipUid, [
|
2021-05-12 17:00:22 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-23 14:54:50 +00:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-05-12 17:00:22 +00:00
|
|
|
], [
|
|
|
|
|
'roles' => $roles
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
$this->assertEquals('User is not allowed to modify roles', $response['body']['message']);
|
2022-05-23 14:54:50 +00:00
|
|
|
|
2021-05-12 17:10:44 +00:00
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 17:34:21 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testUpdateTeamMembershipRoles
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
public function testDeleteTeamMembership($data): array
|
2020-01-19 13:36:30 +00:00
|
|
|
{
|
2020-10-14 21:11:12 +00:00
|
|
|
$teamUid = $data['teamUid'] ?? '';
|
2021-05-07 16:54:56 +00:00
|
|
|
$membershipUid = $data['membershipUid'] ?? '';
|
2021-12-07 08:01:09 +00:00
|
|
|
$session = $data['session'] ?? '';
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
|
2021-12-07 08:01:09 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2024-11-19 15:47:14 +00:00
|
|
|
$this->assertEquals(4, $response['body']['total']);
|
2022-05-23 14:54:50 +00:00
|
|
|
|
2021-12-07 08:01:09 +00:00
|
|
|
$ownerMembershipUid = $response['body']['memberships'][0]['$id'];
|
|
|
|
|
|
2020-01-19 13:36:30 +00:00
|
|
|
/**
|
2021-12-07 08:01:09 +00:00
|
|
|
* Test for FAILURE
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test deleting a membership that does not exists
|
2020-01-19 13:36:30 +00:00
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamUid . '/memberships/dne', [
|
2020-01-19 13:36:30 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-23 14:54:50 +00:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-12-07 08:01:09 +00:00
|
|
|
]);
|
2022-05-23 14:54:50 +00:00
|
|
|
|
2021-12-07 08:01:09 +00:00
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test deleting another user's membership
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamUid . '/memberships/' . $ownerMembershipUid, [
|
2021-12-07 08:01:09 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-23 14:54:50 +00:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-12-07 08:01:09 +00:00
|
|
|
]);
|
2022-05-23 14:54:50 +00:00
|
|
|
|
2021-12-07 08:01:09 +00:00
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
2020-01-19 13:36:30 +00:00
|
|
|
|
2021-12-07 08:01:09 +00:00
|
|
|
/**
|
|
|
|
|
* Test for SUCCESS
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for when a user other than the owner tries to delete their membership
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamUid . '/memberships/' . $membershipUid, [
|
2021-12-07 08:01:09 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-23 14:54:50 +00:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
|
2021-12-07 08:01:09 +00:00
|
|
|
]);
|
2022-05-23 14:54:50 +00:00
|
|
|
|
2020-01-19 13:36:30 +00:00
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
|
2021-12-07 08:01:09 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2024-11-19 15:47:14 +00:00
|
|
|
$this->assertEquals(3, $response['body']['total']);
|
2021-12-07 08:01:09 +00:00
|
|
|
|
2020-01-19 13:36:30 +00:00
|
|
|
/**
|
2021-12-07 08:01:09 +00:00
|
|
|
* Test for when the owner tries to delete their membership
|
2020-01-19 13:36:30 +00:00
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamUid . '/memberships/' . $ownerMembershipUid, array_merge([
|
2021-12-07 08:01:09 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships/' . $ownerMembershipUid, array_merge([
|
2020-01-19 13:36:30 +00:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-19 13:36:30 +00:00
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
2021-08-05 04:29:43 +00:00
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
2020-01-19 13:36:30 +00:00
|
|
|
|
2020-01-18 20:02:47 +00:00
|
|
|
return [];
|
|
|
|
|
}
|
2022-05-23 14:54:50 +00:00
|
|
|
}
|