1
0
Fork 0
mirror of synced 2024-07-21 14:25:44 +12:00
appwrite/tests/e2e/Services/Teams/TeamsConsoleClientTest.php

130 lines
4.6 KiB
PHP
Raw Normal View History

2020-01-17 03:06:28 +13:00
<?php
namespace Tests\E2E\Services\Teams;
2022-01-03 05:08:27 +13:00
use Tests\E2E\Client;
2020-01-17 03:06:28 +13:00
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\ProjectConsole;
use Tests\E2E\Scopes\SideClient;
2022-12-15 04:42:25 +13:00
use Utopia\Database\Helpers\ID;
2020-01-17 03:06:28 +13:00
class TeamsConsoleClientTest extends Scope
{
use TeamsBase;
use TeamsBaseClient;
use ProjectConsole;
use SideClient;
2022-01-03 05:08:27 +13:00
2022-05-24 02:54:50 +12:00
public function testRequestHeader()
{
2022-01-03 05:08:27 +13:00
/**
* Test without header
*/
$response = $this->client->call(Client::METHOD_POST, '/teams', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => 'console'
], $this->getHeaders()), [
'name' => 'Latest version Team',
2022-08-14 22:33:36 +12:00
'teamId' => ID::unique()
2022-01-03 05:08:27 +13:00
]);
$this->assertEquals(201, $response['headers']['status-code']);
$team1Id = $response['body']['$id'];
/**
* Test with header
*/
$response = $this->client->call(Client::METHOD_POST, '/teams', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => 'console',
'x-appwrite-response-format' => '0.11.0'
], $this->getHeaders()), [
'name' => 'Latest version Team'
// Notice "teamId' is not defined
]);
$this->assertEquals(201, $response['headers']['status-code']);
$team2Id = $response['body']['$id'];
/**
* Cleanup, so I don't invalidate some listTeams requests by mistake
*/
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $team1Id, \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => 'console',
], $this->getHeaders()));
$this->assertEquals(204, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $team2Id, \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => 'console',
], $this->getHeaders()));
$this->assertEquals(204, $response['headers']['status-code']);
}
2022-09-01 05:27:32 +12:00
/**
* @depends testCreateTeam
*/
2022-09-01 21:09:28 +12:00
public function testTeamMembershipPerms($data): array
2022-09-01 05:27:32 +12:00
{
$teamUid = $data['teamUid'] ?? '';
$teamName = $data['teamName'] ?? '';
$email = uniqid() . 'friend@localhost.test';
$name = 'Friend User';
$password = 'password';
// Create a user account before we create a invite so we can check if the user has permissions when it shouldn't
$user = $this->client->call(Client::METHOD_POST, '/account', [
'content-type' => 'application/json',
'x-appwrite-project' => 'console'], [
'userId' => 'unique()',
'email' => $email,
2022-09-01 21:09:28 +12:00
'password' => $password,
2022-09-01 05:27:32 +12:00
'name' => $name,
2022-09-01 21:15:43 +12:00
], false);
2022-09-01 05:27:32 +12:00
$this->assertEquals(201, $user['headers']['status-code']);
/**
* Test for SUCCESS
*/
2022-09-01 21:09:28 +12:00
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
2022-09-01 05:27:32 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
2022-09-01 21:09:28 +12:00
'email' => $email,
'name' => $name,
2022-09-01 05:27:32 +12:00
'roles' => ['admin', 'editor'],
'url' => 'http://localhost:5000/join-us#title'
]);
$this->assertEquals(201, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_GET, '/users', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(401, $response['headers']['status-code']);
2022-09-01 21:09:28 +12:00
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
2022-09-01 05:27:32 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $response['headers']['status-code']);
$ownerMembershipUid = $response['body']['memberships'][1]['$id'];
2022-09-01 21:09:28 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamUid . '/memberships/' . $ownerMembershipUid, array_merge([
2022-09-01 05:27:32 +12:00
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(204, $response['headers']['status-code']);
2022-09-01 21:09:28 +12:00
2022-09-01 05:27:32 +12:00
return $data;
}
2022-05-24 02:54:50 +12:00
}