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 TeamsBase
|
|
|
|
|
{
|
2022-05-23 14:54:50 +00:00
|
|
|
public function testCreateTeam(): array
|
2020-01-16 14:06:28 +00:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Test for SUCCESS
|
|
|
|
|
*/
|
|
|
|
|
$response1 = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
|
'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()), [
|
2022-08-14 10:33:36 +00:00
|
|
|
'teamId' => ID::unique(),
|
2022-08-27 23:01:46 +00:00
|
|
|
'name' => 'Arsenal',
|
|
|
|
|
'roles' => ['player'],
|
2020-01-16 14:06:28 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response1['headers']['status-code']);
|
2020-02-17 07:16:11 +00:00
|
|
|
$this->assertNotEmpty($response1['body']['$id']);
|
2020-01-16 14:06:28 +00:00
|
|
|
$this->assertEquals('Arsenal', $response1['body']['name']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertGreaterThan(-1, $response1['body']['total']);
|
|
|
|
|
$this->assertIsInt($response1['body']['total']);
|
2023-03-06 14:24:02 +00:00
|
|
|
$this->assertArrayHasKey('prefs', $response1['body']);
|
|
|
|
|
|
2022-12-19 11:21:09 +00:00
|
|
|
$dateValidator = new DatetimeValidator();
|
|
|
|
|
$this->assertEquals(true, $dateValidator->isValid($response1['body']['$createdAt']));
|
2020-01-16 14:06:28 +00:00
|
|
|
|
2020-02-17 07:16:11 +00:00
|
|
|
$teamUid = $response1['body']['$id'];
|
2020-01-19 12:22:54 +00:00
|
|
|
$teamName = $response1['body']['name'];
|
2020-01-16 14:06:28 +00:00
|
|
|
|
2025-04-06 04:51:55 +00:00
|
|
|
/**
|
2025-04-06 04:59:18 +00:00
|
|
|
* Test: Attempt to downgrade the only OWNER in an organization (should fail)
|
2025-04-06 04:51:55 +00:00
|
|
|
*/
|
2025-04-06 04:59:18 +00:00
|
|
|
if ($this->getProject()['$id'] === 'console') {
|
|
|
|
|
// Step 1: Fetch all team memberships — only one exists at this point
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'queries' => [
|
|
|
|
|
Query::limit(1)->toString(),
|
|
|
|
|
],
|
|
|
|
|
]);
|
2025-04-06 04:51:55 +00:00
|
|
|
|
2025-04-06 04:59:18 +00:00
|
|
|
// Step 2: Extract the membership ID of the only member (also the only OWNER)
|
|
|
|
|
$membershipID = $response['body']['memberships'][0]['$id'];
|
2025-04-06 04:51:55 +00:00
|
|
|
|
2025-04-06 04:59:18 +00:00
|
|
|
// Step 3: Attempt to downgrade the member's role to 'developer'
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/' . $teamUid . '/memberships/' . $membershipID, array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'roles' => ['developer']
|
|
|
|
|
]);
|
2025-04-06 04:51:55 +00:00
|
|
|
|
2025-04-06 04:59:18 +00:00
|
|
|
// Step 4: Assert failure — cannot remove the only OWNER from a team
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2025-05-30 08:51:11 +00:00
|
|
|
$this->assertEquals('membership_downgrade_prohibited', $response['body']['type']);
|
2025-04-06 04:59:18 +00:00
|
|
|
$this->assertEquals('There must be at least one owner in the organization.', $response['body']['message']);
|
|
|
|
|
}
|
2025-04-06 04:51:55 +00:00
|
|
|
|
2022-08-15 11:40:41 +00:00
|
|
|
$teamId = ID::unique();
|
2020-01-16 14:06:28 +00:00
|
|
|
$response2 = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
|
'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()), [
|
2022-08-15 11:24:31 +00:00
|
|
|
'teamId' => $teamId,
|
2020-01-16 14:06:28 +00:00
|
|
|
'name' => 'Manchester United'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response2['headers']['status-code']);
|
2020-02-17 07:16:11 +00:00
|
|
|
$this->assertNotEmpty($response2['body']['$id']);
|
2021-07-19 07:53:57 +00:00
|
|
|
$this->assertEquals($teamId, $response2['body']['$id']);
|
2020-01-16 14:06:28 +00:00
|
|
|
$this->assertEquals('Manchester United', $response2['body']['name']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertGreaterThan(-1, $response2['body']['total']);
|
|
|
|
|
$this->assertIsInt($response2['body']['total']);
|
2023-03-06 14:24:02 +00:00
|
|
|
$this->assertArrayHasKey('prefs', $response2['body']);
|
2022-12-19 11:21:09 +00:00
|
|
|
$this->assertEquals(true, $dateValidator->isValid($response2['body']['$createdAt']));
|
2020-01-16 14:06:28 +00:00
|
|
|
|
|
|
|
|
$response3 = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
|
'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()), [
|
2022-08-14 10:33:36 +00:00
|
|
|
'teamId' => ID::unique(),
|
2020-01-16 14:06:28 +00:00
|
|
|
'name' => 'Newcastle'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response3['headers']['status-code']);
|
2020-02-17 07:16:11 +00:00
|
|
|
$this->assertNotEmpty($response3['body']['$id']);
|
2020-01-16 14:06:28 +00:00
|
|
|
$this->assertEquals('Newcastle', $response3['body']['name']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertGreaterThan(-1, $response3['body']['total']);
|
|
|
|
|
$this->assertIsInt($response3['body']['total']);
|
2022-12-19 11:21:09 +00:00
|
|
|
$this->assertEquals(true, $dateValidator->isValid($response3['body']['$createdAt']));
|
2023-03-06 14:24:02 +00:00
|
|
|
|
2020-01-16 14:06:28 +00:00
|
|
|
/**
|
|
|
|
|
* Test for FAILURE
|
|
|
|
|
*/
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
|
'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(400, $response['headers']['status-code']);
|
|
|
|
|
|
2023-07-09 11:20:09 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'teamId' => $teamId,
|
|
|
|
|
'name' => 'John'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(409, $response['headers']['status-code']);
|
2023-07-13 06:40:52 +00:00
|
|
|
$this->assertEquals('team_already_exists', $response['body']['type']);
|
2023-07-09 11:20:09 +00:00
|
|
|
|
2020-01-19 12:22:54 +00:00
|
|
|
return ['teamUid' => $teamUid, 'teamName' => $teamName];
|
2020-01-16 14:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateTeam
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
public function testGetTeam($data): array
|
2020-01-16 14:06:28 +00:00
|
|
|
{
|
2020-10-14 21:11:12 +00:00
|
|
|
$id = $data['teamUid'] ?? '';
|
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/' . $id, 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']);
|
2020-02-17 07:16:11 +00:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-01-16 14:06:28 +00:00
|
|
|
$this->assertEquals('Arsenal', $response['body']['name']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertGreaterThan(-1, $response['body']['total']);
|
|
|
|
|
$this->assertIsInt($response['body']['total']);
|
2023-03-06 14:24:02 +00:00
|
|
|
$this->assertArrayHasKey('prefs', $response['body']);
|
2022-12-19 11:21:09 +00:00
|
|
|
$dateValidator = new DatetimeValidator();
|
|
|
|
|
$this->assertEquals(true, $dateValidator->isValid($response['body']['$createdAt']));
|
2020-01-16 14:06:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for FAILURE
|
|
|
|
|
*/
|
|
|
|
|
|
2020-10-27 19:48:38 +00:00
|
|
|
return [];
|
2020-01-16 14:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateTeam
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
public function testListTeams($data): array
|
2020-01-16 14:06:28 +00:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Test for SUCCESS
|
|
|
|
|
*/
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([
|
|
|
|
|
'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->assertGreaterThan(0, $response['body']['total']);
|
|
|
|
|
$this->assertIsInt($response['body']['total']);
|
2020-07-08 13:02:01 +00:00
|
|
|
$this->assertGreaterThan(2, count($response['body']['teams']));
|
2020-01-16 14:06:28 +00:00
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([
|
|
|
|
|
'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()), [
|
2023-12-20 10:55:09 +00:00
|
|
|
'queries' => [
|
|
|
|
|
Query::limit(2)->toString(),
|
|
|
|
|
],
|
2020-01-16 14:06:28 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-08-24 12:43:07 +00:00
|
|
|
$this->assertEquals(2, count($response['body']['teams']));
|
2021-08-09 13:04:14 +00:00
|
|
|
|
2020-01-16 14:06:28 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([
|
|
|
|
|
'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()), [
|
2023-12-20 10:55:09 +00:00
|
|
|
'queries' => [
|
|
|
|
|
Query::offset(1)->toString(),
|
|
|
|
|
],
|
2020-01-16 14:06:28 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-08-24 12:43:07 +00:00
|
|
|
$this->assertGreaterThan(1, count($response['body']['teams']));
|
2021-08-09 13:04:14 +00:00
|
|
|
|
2022-08-24 11:55:43 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
2023-12-20 10:55:09 +00:00
|
|
|
'queries' => [
|
|
|
|
|
Query::greaterThanEqual('total', 0)->toString(),
|
|
|
|
|
],
|
2022-08-24 11:55:43 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-08-24 12:43:07 +00:00
|
|
|
$this->assertGreaterThan(2, count($response['body']['teams']));
|
2022-08-24 11:55:43 +00:00
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams', 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('name', ['Arsenal', 'Newcastle'])->toString(),
|
|
|
|
|
],
|
2022-08-24 11:55:43 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-08-24 12:43:07 +00:00
|
|
|
$this->assertEquals(2, count($response['body']['teams']));
|
2021-08-09 13:04:14 +00:00
|
|
|
|
2020-01-16 14:06:28 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([
|
|
|
|
|
'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()), [
|
|
|
|
|
'search' => 'Manchester',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertGreaterThan(0, $response['body']['total']);
|
|
|
|
|
$this->assertIsInt($response['body']['total']);
|
2020-01-16 14:06:28 +00:00
|
|
|
$this->assertCount(1, $response['body']['teams']);
|
|
|
|
|
$this->assertEquals('Manchester United', $response['body']['teams'][0]['name']);
|
2021-08-09 13:04:14 +00:00
|
|
|
|
2020-01-16 14:06:28 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([
|
|
|
|
|
'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()), [
|
|
|
|
|
'search' => 'United',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertGreaterThan(0, $response['body']['total']);
|
|
|
|
|
$this->assertIsInt($response['body']['total']);
|
2020-01-16 14:06:28 +00:00
|
|
|
$this->assertCount(1, $response['body']['teams']);
|
|
|
|
|
$this->assertEquals('Manchester United', $response['body']['teams'][0]['name']);
|
|
|
|
|
|
2021-09-21 08:22:13 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'search' => $data['teamUid'],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertGreaterThan(0, $response['body']['total']);
|
|
|
|
|
$this->assertIsInt($response['body']['total']);
|
2021-09-21 08:22:13 +00:00
|
|
|
$this->assertCount(1, $response['body']['teams']);
|
|
|
|
|
$this->assertEquals('Arsenal', $response['body']['teams'][0]['name']);
|
|
|
|
|
|
2021-08-09 13:04:14 +00:00
|
|
|
$teams = $this->client->call(Client::METHOD_GET, '/teams', 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(2)->toString(),
|
|
|
|
|
],
|
2021-08-09 13:04:14 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $teams['headers']['status-code']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertGreaterThan(0, $teams['body']['total']);
|
|
|
|
|
$this->assertIsInt($teams['body']['total']);
|
2021-08-09 13:04:14 +00:00
|
|
|
$this->assertCount(2, $teams['body']['teams']);
|
|
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams', 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(),
|
|
|
|
|
Query::cursorAfter(new Document(['$id' => $teams['body']['teams'][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->assertGreaterThan(0, $response['body']['total']);
|
|
|
|
|
$this->assertIsInt($response['body']['total']);
|
2021-08-09 13:04:14 +00:00
|
|
|
$this->assertCount(1, $response['body']['teams']);
|
|
|
|
|
$this->assertEquals($teams['body']['teams'][1]['$id'], $response['body']['teams'][0]['$id']);
|
|
|
|
|
|
2021-10-05 10:30:33 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams', 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(),
|
|
|
|
|
Query::cursorBefore(new Document(['$id' => $teams['body']['teams'][1]['$id']]))->toString(),
|
|
|
|
|
],
|
2021-10-05 10:30:33 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertGreaterThan(0, $response['body']['total']);
|
|
|
|
|
$this->assertIsInt($response['body']['total']);
|
2021-10-05 10:30:33 +00:00
|
|
|
$this->assertCount(1, $response['body']['teams']);
|
|
|
|
|
$this->assertEquals($teams['body']['teams'][0]['$id'], $response['body']['teams'][0]['$id']);
|
|
|
|
|
|
2020-01-16 14:06:28 +00:00
|
|
|
/**
|
|
|
|
|
* Test for FAILURE
|
|
|
|
|
*/
|
2021-10-05 10:30:33 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([
|
|
|
|
|
'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' => 'unknown']))->toString(),
|
|
|
|
|
],
|
2021-10-05 10:30:33 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2020-01-16 14:06:28 +00:00
|
|
|
|
2025-10-20 15:18:17 +00:00
|
|
|
/**
|
2025-10-29 09:08:08 +00:00
|
|
|
* Test for SUCCESS with total=false
|
2025-10-20 15:18:17 +00:00
|
|
|
*/
|
|
|
|
|
$teamsWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/teams', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
2025-10-29 09:08:08 +00:00
|
|
|
'total' => false
|
2025-10-20 15:18:17 +00:00
|
|
|
]);
|
|
|
|
|
|
2025-10-20 15:38:14 +00:00
|
|
|
$this->assertEquals(200, $teamsWithIncludeTotalFalse['headers']['status-code']);
|
2025-10-20 15:18:17 +00:00
|
|
|
$this->assertIsArray($teamsWithIncludeTotalFalse['body']);
|
|
|
|
|
$this->assertIsArray($teamsWithIncludeTotalFalse['body']['teams']);
|
|
|
|
|
$this->assertIsInt($teamsWithIncludeTotalFalse['body']['total']);
|
|
|
|
|
$this->assertEquals(0, $teamsWithIncludeTotalFalse['body']['total']);
|
|
|
|
|
$this->assertGreaterThan(0, count($teamsWithIncludeTotalFalse['body']['teams']));
|
|
|
|
|
|
2020-10-27 19:48:38 +00:00
|
|
|
return [];
|
2020-01-16 14:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
public function testUpdateTeam(): array
|
2020-01-16 14:06:28 +00:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Test for SUCCESS
|
|
|
|
|
*/
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
|
'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()), [
|
2022-08-14 10:33:36 +00:00
|
|
|
'teamId' => ID::unique(),
|
2020-01-16 14:06:28 +00:00
|
|
|
'name' => 'Demo'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
2020-02-17 07:16:11 +00:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-01-16 14:06:28 +00:00
|
|
|
$this->assertEquals('Demo', $response['body']['name']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertGreaterThan(-1, $response['body']['total']);
|
|
|
|
|
$this->assertIsInt($response['body']['total']);
|
2023-02-05 20:39:41 +00:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['$createdAt']));
|
2020-01-16 14:06:28 +00:00
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/teams/' . $response['body']['$id'], 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()), [
|
2022-08-14 10:33:36 +00:00
|
|
|
'teamId' => ID::unique(),
|
2020-01-16 14:06:28 +00:00
|
|
|
'name' => 'Demo New'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-02-17 07:16:11 +00:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-01-16 14:06:28 +00:00
|
|
|
$this->assertEquals('Demo New', $response['body']['name']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertGreaterThan(-1, $response['body']['total']);
|
|
|
|
|
$this->assertIsInt($response['body']['total']);
|
2023-02-05 20:39:41 +00:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['$createdAt']));
|
2023-03-06 14:24:02 +00:00
|
|
|
$this->assertArrayHasKey('prefs', $response['body']);
|
2020-01-16 14:06:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for FAILURE
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/teams/' . $response['body']['$id'], 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(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
public function testDeleteTeam(): array
|
2020-01-16 14:06:28 +00:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Test for SUCCESS
|
|
|
|
|
*/
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
|
'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()), [
|
2022-08-14 10:33:36 +00:00
|
|
|
'teamId' => ID::unique(),
|
2020-01-16 14:06:28 +00:00
|
|
|
'name' => 'Demo'
|
|
|
|
|
]);
|
|
|
|
|
|
2020-02-17 07:16:11 +00:00
|
|
|
$teamUid = $response['body']['$id'];
|
2020-01-16 14:06:28 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
2020-02-17 07:16:11 +00:00
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2020-01-18 14:00:15 +00:00
|
|
|
$this->assertEquals('Demo', $response['body']['name']);
|
2022-02-27 09:57:09 +00:00
|
|
|
$this->assertGreaterThan(-1, $response['body']['total']);
|
|
|
|
|
$this->assertIsInt($response['body']['total']);
|
2023-03-06 14:24:02 +00:00
|
|
|
$this->assertArrayHasKey('prefs', $response['body']);
|
2022-12-19 11:21:09 +00:00
|
|
|
$dateValidator = new DatetimeValidator();
|
|
|
|
|
$this->assertEquals(true, $dateValidator->isValid($response['body']['$createdAt']));
|
2020-01-18 14:00:15 +00:00
|
|
|
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamUid, array_merge([
|
2020-01-18 14:00:15 +00:00
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-18 14:00:15 +00:00
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for FAILURE
|
|
|
|
|
*/
|
2022-05-23 14:54:50 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid, array_merge([
|
2020-01-18 14:00:15 +00:00
|
|
|
'content-type' => 'application/json',
|
2020-02-17 07:16:11 +00:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-18 14:00:15 +00:00
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2023-03-06 14:24:02 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateTeam
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateAndGetUserPrefs(array $data): void
|
|
|
|
|
{
|
|
|
|
|
$id = $data['teamUid'] ?? '';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for SUCCESS
|
|
|
|
|
*/
|
2023-03-13 23:10:17 +00:00
|
|
|
$team = $this->client->call(Client::METHOD_PUT, '/teams/' . $id . '/prefs', array_merge([
|
2023-03-06 14:24:02 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'prefs' => [
|
|
|
|
|
'funcKey1' => 'funcValue1',
|
|
|
|
|
'funcKey2' => 'funcValue2',
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($team['headers']['status-code'], 200);
|
|
|
|
|
$this->assertEquals($team['body']['funcKey1'], 'funcValue1');
|
|
|
|
|
$this->assertEquals($team['body']['funcKey2'], 'funcValue2');
|
|
|
|
|
|
|
|
|
|
$team = $this->client->call(Client::METHOD_GET, '/teams/' . $id . '/prefs', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($team['headers']['status-code'], 200);
|
|
|
|
|
$this->assertEquals($team['body'], [
|
|
|
|
|
'funcKey1' => 'funcValue1',
|
|
|
|
|
'funcKey2' => 'funcValue2',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$team = $this->client->call(Client::METHOD_GET, '/teams/' . $id, array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($team['headers']['status-code'], 200);
|
|
|
|
|
$this->assertEquals($team['body']['prefs'], [
|
|
|
|
|
'funcKey1' => 'funcValue1',
|
|
|
|
|
'funcKey2' => 'funcValue2',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for FAILURE
|
|
|
|
|
*/
|
2023-03-13 23:10:17 +00:00
|
|
|
$user = $this->client->call(Client::METHOD_PUT, '/teams/' . $id . '/prefs', array_merge([
|
2023-03-06 14:24:02 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
|
'prefs' => 'bad-string',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($user['headers']['status-code'], 400);
|
|
|
|
|
}
|
2022-05-23 14:54:50 +00:00
|
|
|
}
|