1
0
Fork 0
mirror of synced 2024-05-17 11:12:41 +12:00
appwrite/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php

2470 lines
99 KiB
PHP
Raw Normal View History

2020-07-08 21:11:12 +12:00
<?php
2020-12-27 01:10:14 +13:00
namespace Tests\E2E\Services\Projects;
2020-07-08 21:11:12 +12:00
2022-07-06 06:55:20 +12:00
use Appwrite\Auth\Auth;
2020-07-08 21:11:12 +12:00
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\ProjectConsole;
use Tests\E2E\Scopes\SideClient;
use Tests\E2E\Services\Projects\ProjectsBase;
use Tests\E2E\Client;
use Utopia\Database\Database;
use Utopia\Database\DateTime;
2022-08-14 22:33:36 +12:00
use Utopia\Database\ID;
2020-07-08 21:11:12 +12:00
class ProjectsConsoleClientTest extends Scope
{
use ProjectsBase;
use ProjectConsole;
use SideClient;
public function testCreateProject(): array
{
/**
* Test for SUCCESS
*/
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
2022-08-14 22:33:36 +12:00
'teamId' => ID::unique(),
2020-07-08 21:11:12 +12:00
'name' => 'Project Test',
]);
$this->assertEquals(201, $team['headers']['status-code']);
$this->assertEquals('Project Test', $team['body']['name']);
$this->assertNotEmpty($team['body']['$id']);
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
2022-08-14 22:33:36 +12:00
'projectId' => ID::unique(),
2020-07-08 21:11:12 +12:00
'name' => 'Project Test',
'teamId' => $team['body']['$id'],
'region' => 'default',
2020-07-08 21:11:12 +12:00
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('Project Test', $response['body']['name']);
$this->assertEquals($team['body']['$id'], $response['body']['teamId']);
$this->assertArrayHasKey('platforms', $response['body']);
$this->assertArrayHasKey('webhooks', $response['body']);
$this->assertArrayHasKey('keys', $response['body']);
$projectId = $response['body']['$id'];
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
2022-08-14 22:33:36 +12:00
'projectId' => ID::unique(),
2020-07-08 21:11:12 +12:00
'name' => '',
'teamId' => $team['body']['$id'],
'region' => 'default'
2020-07-08 21:11:12 +12:00
]);
$this->assertEquals(400, $response['headers']['status-code']);
2020-07-08 21:11:12 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
2022-08-14 22:33:36 +12:00
'projectId' => ID::unique(),
2020-07-08 21:11:12 +12:00
'name' => 'Project Test',
'region' => 'default'
2020-07-08 21:11:12 +12:00
]);
$this->assertEquals(400, $response['headers']['status-code']);
return ['projectId' => $projectId];
}
2020-07-09 03:20:18 +12:00
/**
* @depends testCreateProject
*/
2022-04-19 04:21:45 +12:00
public function testListProject($data): array
2020-07-09 03:20:18 +12:00
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2020-07-09 03:20:18 +12:00
/**
* Test for SUCCESS
*/
2021-09-23 19:01:10 +12:00
2020-07-09 03:20:18 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects', 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']);
$this->assertEquals($id, $response['body']['projects'][0]['$id']);
$this->assertEquals('Project Test', $response['body']['projects'][0]['name']);
2021-09-23 19:01:10 +12:00
/**
* Test search queries
*/
2021-09-21 20:22:13 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(), [
'search' => $id
]));
2021-09-23 19:01:10 +12:00
$this->assertEquals($response['headers']['status-code'], 200);
2022-02-27 22:57:09 +13:00
$this->assertEquals($response['body']['total'], 1);
2021-09-23 19:01:10 +12:00
$this->assertIsArray($response['body']['projects']);
$this->assertCount(1, $response['body']['projects']);
$this->assertEquals($response['body']['projects'][0]['name'], 'Project Test');
2021-09-21 20:22:13 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(), [
'search' => 'Project Test'
]));
2021-09-23 19:01:10 +12:00
$this->assertEquals($response['headers']['status-code'], 200);
2022-02-27 22:57:09 +13:00
$this->assertEquals($response['body']['total'], 1);
2021-09-23 19:01:10 +12:00
$this->assertIsArray($response['body']['projects']);
$this->assertCount(1, $response['body']['projects']);
$this->assertEquals($response['body']['projects'][0]['$id'], $data['projectId']);
2021-09-21 20:22:13 +12:00
/**
2022-09-01 04:00:14 +12:00
* Test pagination
*/
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
2022-08-14 22:33:36 +12:00
'teamId' => ID::unique(),
'name' => 'Project Test 2',
]);
$this->assertEquals(201, $team['headers']['status-code']);
$this->assertEquals('Project Test 2', $team['body']['name']);
$this->assertNotEmpty($team['body']['$id']);
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
2022-08-14 22:33:36 +12:00
'projectId' => ID::unique(),
'name' => 'Project Test 2',
'teamId' => $team['body']['$id'],
'region' => 'default'
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('Project Test 2', $response['body']['name']);
$this->assertEquals($team['body']['$id'], $response['body']['teamId']);
$this->assertArrayHasKey('platforms', $response['body']);
$this->assertArrayHasKey('webhooks', $response['body']);
$this->assertArrayHasKey('keys', $response['body']);
2022-09-01 04:00:14 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
'content-type' => 'application/json',
2022-10-03 20:16:49 +13:00
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [ 'equal("teamId", "' . $team['body']['$id'] . '")' ],
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']);
$this->assertCount(1, $response['body']['projects']);
2022-10-03 20:54:55 +13:00
$this->assertEquals($team['body']['$id'], $response['body']['projects'][0]['teamId']);
2022-10-03 20:16:49 +13:00
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
'content-type' => 'application/json',
2022-09-01 04:00:14 +12:00
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [ 'limit(1)' ],
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']);
$this->assertCount(1, $response['body']['projects']);
$this->assertEquals('Project Test', $response['body']['projects'][0]['name']);
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [ 'offset(1)' ],
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']);
$this->assertCount(1, $response['body']['projects']);
$this->assertEquals('Project Test 2', $response['body']['projects'][0]['name']);
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [ 'equal("name", "Project Test 2")' ],
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']);
$this->assertCount(1, $response['body']['projects']);
$this->assertEquals('Project Test 2', $response['body']['projects'][0]['name']);
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [ 'orderDesc("")' ],
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']);
$this->assertCount(2, $response['body']['projects']);
$this->assertEquals('Project Test 2', $response['body']['projects'][0]['name']);
$this->assertEquals('Project Test', $response['body']['projects'][1]['name']);
$response = $this->client->call(Client::METHOD_GET, '/projects', 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']);
$this->assertCount(2, $response['body']['projects']);
$this->assertEquals('Project Test', $response['body']['projects'][0]['name']);
$this->assertEquals('Project Test 2', $response['body']['projects'][1]['name']);
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
2022-04-19 04:21:45 +12:00
], $this->getHeaders()), [
2022-09-01 04:00:14 +12:00
'queries' => [ 'cursorAfter("' . $response['body']['projects'][0]['$id'] . '")' ],
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']);
$this->assertCount(1, $response['body']['projects']);
$this->assertEquals('Project Test 2', $response['body']['projects'][0]['name']);
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
2022-04-19 04:21:45 +12:00
], $this->getHeaders()), [
2022-09-01 04:00:14 +12:00
'queries' => [ 'cursorBefore("' . $response['body']['projects'][0]['$id'] . '")' ],
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']);
$this->assertCount(1, $response['body']['projects']);
$this->assertEquals('Project Test', $response['body']['projects'][0]['name']);
2020-07-09 03:20:18 +12:00
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
2022-04-19 04:21:45 +12:00
], $this->getHeaders()), [
2022-09-01 04:00:14 +12:00
'queries' => [ 'cursorAfter("unknown")' ],
]);
$this->assertEquals(400, $response['headers']['status-code']);
2020-07-09 03:20:18 +12:00
2020-07-09 21:13:14 +12:00
return $data;
2020-07-09 03:20:18 +12:00
}
2020-07-08 21:11:12 +12:00
/**
* @depends testCreateProject
*/
2022-04-19 04:21:45 +12:00
public function testGetProject($data): array
2020-07-08 21:11:12 +12:00
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2020-07-08 21:11:12 +12:00
/**
* Test for SUCCESS
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
2020-07-08 21:11:12 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']);
$this->assertEquals($id, $response['body']['$id']);
$this->assertEquals('Project Test', $response['body']['name']);
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_GET, '/projects/empty', 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, '/projects/id-is-really-long-id-is-really-long-id-is-really-long-id-is-really-long', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(400, $response['headers']['status-code']);
2020-10-28 08:48:38 +13:00
return $data;
2020-07-08 21:11:12 +12:00
}
2020-07-09 03:20:18 +12:00
/**
* @depends testCreateProject
*/
2022-04-19 04:21:45 +12:00
public function testGetProjectUsage($data): array
2020-07-09 03:20:18 +12:00
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2020-07-09 03:20:18 +12:00
/**
* Test for SUCCESS
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/usage', array_merge([
2020-07-09 03:20:18 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $response['headers']['status-code']);
2022-11-09 02:38:43 +13:00
$this->assertEquals(count($response['body']), 9);
2020-07-09 03:20:18 +12:00
$this->assertNotEmpty($response['body']);
$this->assertEquals('30d', $response['body']['range']);
$this->assertIsArray($response['body']['requests']);
$this->assertIsArray($response['body']['network']);
2022-08-14 23:16:54 +12:00
$this->assertIsArray($response['body']['executions']);
$this->assertIsArray($response['body']['documents']);
$this->assertIsArray($response['body']['databases']);
$this->assertIsArray($response['body']['buckets']);
$this->assertIsArray($response['body']['users']);
$this->assertIsArray($response['body']['storage']);
2020-07-09 03:20:18 +12:00
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_GET, '/projects/empty', 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, '/projects/id-is-really-long-id-is-really-long-id-is-really-long-id-is-really-long', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(400, $response['headers']['status-code']);
2020-10-28 08:48:38 +13:00
return $data;
2020-07-09 21:13:14 +12:00
}
/**
* @depends testGetProjectUsage
*/
2022-04-19 04:21:45 +12:00
public function testUpdateProject($data): array
2020-07-09 21:13:14 +12:00
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2020-07-09 21:13:14 +12:00
/**
* Test for SUCCESS
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id, array_merge([
2020-07-09 21:13:14 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
2022-08-14 22:33:36 +12:00
'projectId' => ID::unique(),
2020-07-09 21:13:14 +12:00
'name' => 'Project Test 2',
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('Project Test 2', $response['body']['name']);
2020-11-21 12:31:17 +13:00
$this->assertArrayHasKey('platforms', $response['body']);
$this->assertArrayHasKey('webhooks', $response['body']);
$this->assertArrayHasKey('keys', $response['body']);
2020-07-09 21:13:14 +12:00
$projectId = $response['body']['$id'];
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
2020-07-09 21:13:14 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
2022-08-14 22:33:36 +12:00
'projectId' => ID::unique(),
2020-07-09 21:13:14 +12:00
'name' => '',
]);
$this->assertEquals(400, $response['headers']['status-code']);
return ['projectId' => $projectId];
}
/**
* @depends testGetProjectUsage
*/
2022-04-19 04:21:45 +12:00
public function testUpdateProjectOAuth($data): array
2020-07-09 21:13:14 +12:00
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2020-07-09 21:13:14 +12:00
$providers = require('app/config/providers.php');
/**
* Test for SUCCESS
*/
2020-10-28 08:48:38 +13:00
foreach ($providers as $key => $provider) {
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([
2020-07-09 21:13:14 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'provider' => $key,
2022-04-19 04:21:45 +12:00
'appId' => 'AppId-' . ucfirst($key),
'secret' => 'Secret-' . ucfirst($key),
2020-07-09 21:13:14 +12:00
]);
2022-04-19 04:21:45 +12:00
2020-07-09 21:13:14 +12:00
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
}
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
2020-07-09 21:13:14 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']);
$this->assertEquals($id, $response['body']['$id']);
2020-10-28 08:48:38 +13:00
foreach ($providers as $key => $provider) {
2022-08-19 21:43:03 +12:00
$asserted = false;
foreach ($response['body']['providers'] as $responseProvider) {
if ($responseProvider['name'] === ucfirst($key)) {
$this->assertEquals('AppId-' . ucfirst($key), $responseProvider['appId']);
$this->assertEquals('Secret-' . ucfirst($key), $responseProvider['secret']);
$this->assertFalse($responseProvider['enabled']);
$asserted = true;
break;
}
}
$this->assertTrue($asserted);
}
// Enable providers
$i = 0;
foreach ($providers as $key => $provider) {
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'provider' => $key,
'enabled' => $i === 0 ? false : true // On first provider, test enabled=false
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$i++;
}
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, 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']);
$this->assertEquals($id, $response['body']['$id']);
$i = 0;
foreach ($providers as $key => $provider) {
$asserted = false;
foreach ($response['body']['providers'] as $responseProvider) {
if ($responseProvider['name'] === ucfirst($key)) {
// On first provider, test enabled=false
$this->assertEquals($i !== 0, $responseProvider['enabled']);
$asserted = true;
break;
}
}
$this->assertTrue($asserted);
$i++;
2020-07-09 21:13:14 +12:00
}
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([
2020-07-09 21:13:14 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'provider' => 'unknown',
2022-08-27 15:16:37 +12:00
'appId' => 'AppId',
2020-07-09 21:13:14 +12:00
'secret' => 'Secret',
]);
$this->assertEquals(400, $response['headers']['status-code']);
return $data;
}
2021-03-01 10:22:03 +13:00
/**
* @depends testGetProjectUsage
*/
2022-04-19 04:21:45 +12:00
public function testUpdateProjectAuthStatus($data): array
2021-03-01 10:22:03 +13:00
{
$id = $data['projectId'] ?? '';
$auth = require('app/config/auth.php');
2022-04-19 04:21:45 +12:00
$originalEmail = uniqid() . 'user@localhost.test';
2021-03-01 10:22:03 +13:00
$originalPassword = 'password';
$originalName = 'User Name';
2022-04-19 04:21:45 +12:00
2021-03-01 10:22:03 +13:00
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $id,
]), [
2022-08-14 22:33:36 +12:00
'userId' => ID::unique(),
2021-03-01 10:22:03 +13:00
'email' => $originalEmail,
'password' => $originalPassword,
'name' => $originalName,
]);
2022-06-14 20:17:50 +12:00
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
2021-03-01 10:22:03 +13:00
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $id,
]), [
'email' => $originalEmail,
'password' => $originalPassword,
]);
2022-04-19 04:21:45 +12:00
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_' . $id];
2021-03-01 10:22:03 +13:00
/**
* Test for SUCCESS
*/
foreach ($auth as $index => $method) {
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/' . $index, array_merge([
2021-03-01 10:22:03 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'status' => false,
]);
2022-04-19 04:21:45 +12:00
2021-03-01 10:22:03 +13:00
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
2021-03-01 10:22:03 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
2022-04-19 04:21:45 +12:00
$this->assertEquals(false, $response['body']['auth' . ucfirst($method['key'])]);
2021-03-01 10:22:03 +13:00
}
2022-04-19 04:21:45 +12:00
$email = uniqid() . 'user@localhost.test';
2021-03-01 10:22:03 +13:00
$password = 'password';
$name = 'User Name';
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $id,
]), [
2022-08-14 22:33:36 +12:00
'userId' => ID::unique(),
2021-03-01 10:22:03 +13:00
'email' => $email,
'password' => $password,
'name' => $name,
]);
$this->assertEquals($response['headers']['status-code'], 501);
$response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $id,
2022-04-19 04:21:45 +12:00
'cookie' => 'a_session_' . $id . '=' . $session,
2021-03-01 10:22:03 +13:00
]), [
2022-08-14 22:33:36 +12:00
'teamId' => ID::unique(),
2021-03-01 10:22:03 +13:00
'name' => 'Arsenal'
]);
$this->assertEquals(201, $response['headers']['status-code']);
$teamUid = $response['body']['$id'];
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
2021-03-01 10:22:03 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $id,
2022-04-19 04:21:45 +12:00
'cookie' => 'a_session_' . $id . '=' . $session,
2021-03-01 10:22:03 +13:00
]), [
'email' => $email,
'name' => 'Friend User',
'roles' => ['admin', 'editor'],
'url' => 'http://localhost:5000/join-us#title'
]);
$this->assertEquals($response['headers']['status-code'], 501);
$response = $this->client->call(Client::METHOD_POST, '/account/jwt', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $id,
2022-04-19 04:21:45 +12:00
'cookie' => 'a_session_' . $id . '=' . $session,
2021-03-01 10:22:03 +13:00
]));
$this->assertEquals($response['headers']['status-code'], 501);
2022-06-14 20:17:50 +12:00
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
2021-03-01 10:22:03 +13:00
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $id,
]), [
'email' => $originalEmail,
'password' => $originalPassword,
]);
2022-04-19 04:21:45 +12:00
2021-03-01 10:22:03 +13:00
$this->assertEquals($response['headers']['status-code'], 501);
2021-04-03 21:56:32 +13:00
$response = $this->client->call(Client::METHOD_POST, '/account/anonymous', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $id,
]), []);
$this->assertEquals($response['headers']['status-code'], 501);
2021-03-01 10:22:03 +13:00
// Cleanup
foreach ($auth as $index => $method) {
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/' . $index, array_merge([
2021-03-01 10:22:03 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'status' => true,
]);
}
return $data;
}
/**
* @depends testGetProjectUsage
*/
2022-04-19 04:21:45 +12:00
public function testUpdateProjectAuthLimit($data): array
2021-03-01 10:22:03 +13:00
{
$id = $data['projectId'] ?? '';
2022-04-19 04:21:45 +12:00
2021-03-01 10:22:03 +13:00
/**
* Test for SUCCESS
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/limit', array_merge([
2021-03-01 10:22:03 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'limit' => 1,
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
2022-04-19 04:21:45 +12:00
$email = uniqid() . 'user@localhost.test';
2021-03-01 10:22:03 +13:00
$password = 'password';
$name = 'User Name';
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $id,
]), [
2022-08-14 22:33:36 +12:00
'userId' => ID::unique(),
2021-03-01 10:22:03 +13:00
'email' => $email,
'password' => $password,
'name' => $name,
]);
$this->assertEquals($response['headers']['status-code'], 501);
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/limit', array_merge([
2021-03-01 10:22:03 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'limit' => 0,
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
2022-04-19 04:21:45 +12:00
2021-03-01 10:22:03 +13:00
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $id,
]), [
2022-08-14 22:33:36 +12:00
'userId' => ID::unique(),
2021-03-01 10:22:03 +13:00
'email' => $email,
'password' => $password,
'name' => $name,
]);
$this->assertEquals($response['headers']['status-code'], 201);
return $data;
}
2021-07-29 22:56:25 +12:00
public function testUpdateProjectServiceStatusAdmin(): array
2021-07-29 22:28:17 +12:00
{
2021-07-29 22:56:25 +12:00
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]), [
2022-08-14 22:33:36 +12:00
'teamId' => ID::unique(),
2021-07-29 22:56:25 +12:00
'name' => 'Project Test',
]);
$this->assertEquals(201, $team['headers']['status-code']);
$this->assertNotEmpty($team['body']['$id']);
$project = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]), [
2022-08-14 22:33:36 +12:00
'projectId' => ID::unique(),
2021-07-29 22:56:25 +12:00
'name' => 'Project Test',
'teamId' => $team['body']['$id'],
'region' => 'default'
2021-07-29 22:56:25 +12:00
]);
$this->assertEquals(201, $project['headers']['status-code']);
$this->assertNotEmpty($project['body']['$id']);
$id = $project['body']['$id'];
2021-08-01 20:00:13 +12:00
$services = require('app/config/services.php');
2021-07-29 22:28:17 +12:00
/**
* Test for Disabled
*/
foreach ($services as $service) {
2022-04-19 04:21:45 +12:00
if (!$service['optional']) {
2021-08-01 20:00:13 +12:00
continue;
}
2021-08-01 22:15:06 +12:00
$key = $service['key'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([
2021-07-29 22:28:17 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
2021-07-29 22:56:25 +12:00
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]), [
2021-08-01 22:15:06 +12:00
'service' => $key,
2021-07-29 22:28:17 +12:00
'status' => false,
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
2021-07-29 22:28:17 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
2021-07-29 22:56:25 +12:00
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]));
2021-07-29 22:28:17 +12:00
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
2022-04-19 04:21:45 +12:00
$this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]);
2021-07-29 22:28:17 +12:00
}
2022-04-19 04:21:45 +12:00
2021-07-29 22:28:17 +12:00
/**
2021-07-29 22:56:25 +12:00
* Admin request must succeed
2021-07-29 22:28:17 +12:00
*/
2022-04-19 04:21:45 +12:00
2021-07-29 22:28:17 +12:00
$response = $this->client->call(Client::METHOD_GET, '/functions', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
2021-07-29 22:56:25 +12:00
// 'x-appwrite-project' => $this->getProject()['$id'],
2021-07-29 22:28:17 +12:00
'x-appwrite-project' => $id,
2021-07-29 22:56:25 +12:00
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
'x-appwrite-mode' => 'admin'
]));
2022-04-19 04:21:45 +12:00
2021-07-29 22:56:25 +12:00
$this->assertEquals(200, $response['headers']['status-code']);
2021-07-29 22:28:17 +12:00
foreach ($services as $service) {
2022-04-19 04:21:45 +12:00
if (!$service['optional']) {
2021-08-01 22:15:06 +12:00
continue;
}
$key = $service['key'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([
2021-07-29 22:28:17 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
2021-08-01 22:15:06 +12:00
'service' => $key,
2021-07-29 22:28:17 +12:00
'status' => true,
]);
}
2021-07-29 22:56:25 +12:00
return ['projectId' => $id];
2021-07-29 22:28:17 +12:00
}
2021-07-29 22:56:25 +12:00
/** @depends testUpdateProjectServiceStatusAdmin */
2022-04-19 04:21:45 +12:00
public function testUpdateProjectServiceStatus($data): void
2021-07-29 22:28:17 +12:00
{
2021-07-29 22:56:25 +12:00
$id = $data['projectId'];
2021-07-29 22:28:17 +12:00
2021-08-01 22:15:06 +12:00
$services = require('app/config/services.php');
2021-07-29 22:28:17 +12:00
/**
* Test for Disabled
*/
foreach ($services as $service) {
2022-04-19 04:21:45 +12:00
if (!$service['optional']) {
2021-08-01 22:15:06 +12:00
continue;
}
$key = $service['key'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([
2021-07-29 22:28:17 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]), [
2021-08-01 22:15:06 +12:00
'service' => $key,
2021-07-29 22:28:17 +12:00
'status' => false,
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
2021-07-29 22:28:17 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]));
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
2022-04-19 04:21:45 +12:00
$this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]);
2021-07-29 22:28:17 +12:00
}
/**
2021-07-29 22:56:25 +12:00
* Test for FAILURE
2021-07-29 22:28:17 +12:00
*/
$response = $this->client->call(Client::METHOD_GET, '/functions', array_merge([
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $id,
2021-07-29 22:56:25 +12:00
], $this->getHeaders()));
2021-07-29 22:28:17 +12:00
2021-07-29 22:56:25 +12:00
$this->assertEquals(503, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $id,
]), [
2022-08-14 22:33:36 +12:00
'teamId' => ID::unique(),
2021-07-29 22:56:25 +12:00
'name' => 'Arsenal'
]);
$this->assertEquals(503, $response['headers']['status-code']);
// Cleanup
foreach ($services as $service) {
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([
2021-07-29 22:56:25 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'service' => $service,
'status' => true,
]);
}
2021-07-29 22:28:17 +12:00
}
/** @depends testUpdateProjectServiceStatusAdmin */
public function testUpdateProjectServiceStatusServer($data): void
{
$id = $data['projectId'];
$services = require('app/config/services.php');
/**
* Test for Disabled
*/
foreach ($services as $service) {
if (!$service['optional']) {
continue;
}
$key = $service['key'] ?? '';
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]), [
'service' => $key,
'status' => false,
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]));
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]);
}
// Create API Key
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]), [
'name' => 'Key Test',
'scopes' => ['functions.read', 'teams.write'],
]);
$this->assertEquals(201, $response['headers']['status-code']);
$keyId = $response['body']['$id'];
$keySecret = $response['body']['secret'];
/**
* Request with API Key must succeed
*/
$response = $this->client->call(Client::METHOD_GET, '/functions', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $id,
'x-appwrite-key' => $keySecret,
2022-08-31 02:04:42 +12:00
'x-sdk-name' => 'python'
]));
$this->assertEquals(200, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $id,
'x-appwrite-key' => $keySecret,
2022-08-31 02:04:42 +12:00
'x-sdk-name' => 'php'
]), [
2022-08-14 22:33:36 +12:00
'teamId' => ID::unique(),
'name' => 'Arsenal'
]);
$this->assertEquals(201, $response['headers']['status-code']);
2022-08-31 02:04:42 +12:00
/** Check that the API key has been updated */
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertArrayHasKey('sdks', $response['body']);
$this->assertCount(2, $response['body']['sdks']);
2022-08-31 05:33:54 +12:00
$this->assertContains('python', $response['body']['sdks']);
$this->assertContains('php', $response['body']['sdks']);
2022-08-31 02:04:42 +12:00
$this->assertArrayHasKey('accessedAt', $response['body']);
$this->assertNotEmpty($response['body']['accessedAt']);
2022-08-31 06:26:02 +12:00
// Cleanup
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/' . $keyId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
]), []);
$this->assertEquals(204, $response['headers']['status-code']);
foreach ($services as $service) {
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'service' => $service,
'status' => true,
]);
}
}
2020-07-09 21:13:14 +12:00
/**
* @depends testCreateProject
*/
public function testCreateProjectWebhook($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2020-07-09 21:13:14 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/webhooks', array_merge([
2020-07-09 21:13:14 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Webhook Test',
2022-04-19 04:21:45 +12:00
'events' => ['users.*.create', 'users.*.update.email'],
2020-07-09 21:13:14 +12:00
'url' => 'https://appwrite.io',
'security' => true,
'httpUser' => 'username',
'httpPass' => 'password',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
2022-04-19 04:21:45 +12:00
$this->assertContains('users.*.create', $response['body']['events']);
$this->assertContains('users.*.update.email', $response['body']['events']);
2020-07-09 21:13:14 +12:00
$this->assertCount(2, $response['body']['events']);
$this->assertEquals('https://appwrite.io', $response['body']['url']);
2020-07-12 01:01:04 +12:00
$this->assertIsBool($response['body']['security']);
$this->assertEquals(true, $response['body']['security']);
2020-07-09 21:13:14 +12:00
$this->assertEquals('username', $response['body']['httpUser']);
2022-04-19 04:21:45 +12:00
$data = array_merge($data, ['webhookId' => $response['body']['$id'], 'signatureKey' => $response['body']['signatureKey']]);
2020-07-09 21:13:14 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/webhooks', array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Webhook Test',
2022-04-19 04:21:45 +12:00
'events' => ['account.unknown', 'users.*.update.email'],
2020-07-12 01:01:04 +12:00
'url' => 'https://appwrite.io',
'security' => true,
'httpUser' => 'username',
'httpPass' => 'password',
]);
$this->assertEquals(400, $response['headers']['status-code']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/webhooks', array_merge([
2022-02-17 04:16:37 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Webhook Test',
2022-04-19 04:21:45 +12:00
'events' => ['users.*.create', 'users.*.update.email'],
2022-02-17 04:16:37 +13:00
'url' => 'invalid://appwrite.io',
]);
$this->assertEquals(400, $response['headers']['status-code']);
2020-07-12 01:01:04 +12:00
return $data;
}
2020-07-13 01:43:47 +12:00
/**
* @depends testCreateProjectWebhook
*/
public function testListProjectWebhook($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2020-07-13 01:43:47 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/webhooks', array_merge([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
2022-02-27 22:57:09 +13:00
$this->assertEquals(1, $response['body']['total']);
2022-04-19 04:21:45 +12:00
2020-07-13 01:43:47 +12:00
/**
* Test for FAILURE
*/
return $data;
}
2020-07-12 01:01:04 +12:00
/**
* @depends testCreateProjectWebhook
*/
public function testGetProjectWebhook($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
$webhookId = $data['webhookId'] ?? '';
2020-07-12 01:01:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($webhookId, $response['body']['$id']);
2022-04-19 04:21:45 +12:00
$this->assertContains('users.*.create', $response['body']['events']);
$this->assertContains('users.*.update.email', $response['body']['events']);
2020-07-12 01:01:04 +12:00
$this->assertCount(2, $response['body']['events']);
$this->assertEquals('https://appwrite.io', $response['body']['url']);
$this->assertEquals('username', $response['body']['httpUser']);
$this->assertEquals('password', $response['body']['httpPass']);
2022-04-19 04:21:45 +12:00
2020-07-12 01:01:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/webhooks/error', array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
return $data;
}
/**
* @depends testCreateProjectWebhook
*/
public function testUpdateProjectWebhook($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
$webhookId = $data['webhookId'] ?? '';
2020-07-12 01:01:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Webhook Test Update',
2022-04-19 04:21:45 +12:00
'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.create'],
2020-07-12 01:01:04 +12:00
'url' => 'https://appwrite.io/new',
'security' => false,
'httpUser' => '',
'httpPass' => ''
2020-07-12 01:01:04 +12:00
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($webhookId, $response['body']['$id']);
$this->assertEquals('Webhook Test Update', $response['body']['name']);
2022-04-19 04:21:45 +12:00
$this->assertContains('users.*.delete', $response['body']['events']);
$this->assertContains('users.*.sessions.*.delete', $response['body']['events']);
$this->assertContains('buckets.*.files.*.create', $response['body']['events']);
2020-07-12 01:01:04 +12:00
$this->assertCount(3, $response['body']['events']);
$this->assertEquals('https://appwrite.io/new', $response['body']['url']);
$this->assertIsBool($response['body']['security']);
$this->assertEquals(false, $response['body']['security']);
$this->assertEquals('', $response['body']['httpUser']);
2020-11-21 12:31:17 +13:00
$this->assertEquals('', $response['body']['httpPass']);
2020-07-12 01:01:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($webhookId, $response['body']['$id']);
$this->assertEquals('Webhook Test Update', $response['body']['name']);
2022-04-19 04:21:45 +12:00
$this->assertContains('users.*.delete', $response['body']['events']);
$this->assertContains('users.*.sessions.*.delete', $response['body']['events']);
$this->assertContains('buckets.*.files.*.create', $response['body']['events']);
2020-07-12 01:01:04 +12:00
$this->assertCount(3, $response['body']['events']);
$this->assertEquals('https://appwrite.io/new', $response['body']['url']);
$this->assertIsBool($response['body']['security']);
$this->assertEquals(false, $response['body']['security']);
$this->assertEquals('', $response['body']['httpUser']);
2020-11-21 12:31:17 +13:00
$this->assertEquals('', $response['body']['httpPass']);
2022-04-19 04:21:45 +12:00
2020-07-12 01:01:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Webhook Test Update',
2022-04-19 04:21:45 +12:00
'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.unknown'],
2020-07-12 01:01:04 +12:00
'url' => 'https://appwrite.io/new',
'security' => false,
'httpUser' => '',
'httpPass' => '',
]);
$this->assertEquals(400, $response['headers']['status-code']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Webhook Test Update',
2022-04-19 04:21:45 +12:00
'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.create'],
2020-07-12 01:01:04 +12:00
'url' => 'appwrite.io/new',
'security' => false,
'httpUser' => '',
'httpPass' => '',
]);
$this->assertEquals(400, $response['headers']['status-code']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
2022-02-17 04:16:37 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Webhook Test Update',
2022-04-19 04:21:45 +12:00
'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.create'],
2022-02-17 04:16:37 +13:00
'url' => 'invalid://appwrite.io/new',
]);
$this->assertEquals(400, $response['headers']['status-code']);
2020-07-12 01:01:04 +12:00
return $data;
}
/**
* @depends testCreateProjectWebhook
*/
public function testUpdateProjectWebhookSignature($data): void
{
$id = $data['projectId'] ?? '';
$webhookId = $data['webhookId'] ?? '';
$signatureKey = $data['signatureKey'] ?? '';
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/webhooks/' . $webhookId . '/signature', 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']['signatureKey']);
$this->assertNotEquals($signatureKey, $response['body']['signatureKey']);
}
2020-07-12 01:01:04 +12:00
/**
* @depends testCreateProjectWebhook
*/
public function testDeleteProjectWebhook($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
$webhookId = $data['webhookId'] ?? '';
2020-07-12 01:01:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
2022-04-19 04:21:45 +12:00
2020-07-12 01:01:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/webhooks/error', array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
2020-07-09 21:13:14 +12:00
2020-07-12 01:01:04 +12:00
$this->assertEquals(404, $response['headers']['status-code']);
2020-07-09 21:13:14 +12:00
return $data;
2020-07-09 03:20:18 +12:00
}
2020-07-12 01:01:04 +12:00
// Keys
/**
* @depends testCreateProject
*/
public function testCreateProjectKey($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2020-07-12 01:01:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Key Test',
'scopes' => ['teams.read', 'teams.write'],
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('Key Test', $response['body']['name']);
$this->assertContains('teams.read', $response['body']['scopes']);
$this->assertContains('teams.write', $response['body']['scopes']);
$this->assertNotEmpty($response['body']['secret']);
2022-08-31 02:04:42 +12:00
$this->assertArrayHasKey('sdks', $response['body']);
$this->assertEmpty($response['body']['sdks']);
$this->assertArrayHasKey('accessedAt', $response['body']);
$this->assertEmpty($response['body']['accessedAt']);
2022-04-19 04:21:45 +12:00
2022-06-01 03:41:12 +12:00
$data = array_merge($data, [
'keyId' => $response['body']['$id'],
'secret' => $response['body']['secret']
]);
2020-07-12 01:01:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Key Test',
'scopes' => ['unknown'],
]);
$this->assertEquals(400, $response['headers']['status-code']);
return $data;
}
2022-06-01 03:41:12 +12:00
2020-07-13 01:43:47 +12:00
/**
* @depends testCreateProjectKey
*/
public function testListProjectKey($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2020-07-13 01:43:47 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
2022-06-01 18:26:55 +12:00
2020-07-13 01:43:47 +12:00
$this->assertEquals(200, $response['headers']['status-code']);
2022-02-27 22:57:09 +13:00
$this->assertEquals(1, $response['body']['total']);
2022-04-19 04:21:45 +12:00
2020-07-13 01:43:47 +12:00
/**
* Test for FAILURE
*/
return $data;
}
2022-06-01 03:41:12 +12:00
2020-07-12 01:01:04 +12:00
/**
* @depends testCreateProjectKey
*/
public function testGetProjectKey($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
$keyId = $data['keyId'] ?? '';
2020-07-12 01:01:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
2022-06-01 18:26:55 +12:00
'x-appwrite-key' => $keyId
2020-07-12 01:01:04 +12:00
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($keyId, $response['body']['$id']);
$this->assertEquals('Key Test', $response['body']['name']);
$this->assertContains('teams.read', $response['body']['scopes']);
$this->assertContains('teams.write', $response['body']['scopes']);
$this->assertCount(2, $response['body']['scopes']);
$this->assertNotEmpty($response['body']['secret']);
2022-08-31 02:04:42 +12:00
$this->assertArrayHasKey('sdks', $response['body']);
$this->assertEmpty($response['body']['sdks']);
$this->assertArrayHasKey('accessedAt', $response['body']);
$this->assertEmpty($response['body']['accessedAt']);
2022-04-19 04:21:45 +12:00
2020-07-12 01:01:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/error', array_merge([
2020-07-12 01:01:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
return $data;
}
2022-06-01 03:41:12 +12:00
/**
2022-06-01 18:26:55 +12:00
* @depends testCreateProject
2022-06-01 03:41:12 +12:00
*/
public function testValidateProjectKey($data): void
{
$id = $data['projectId'] ?? '';
2022-06-01 18:26:55 +12:00
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
2022-06-01 03:41:12 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
2022-06-01 18:26:55 +12:00
], $this->getHeaders()), [
'name' => 'Key Test',
'scopes' => ['health.read'],
2022-07-14 02:02:49 +12:00
'expire' => DateTime::addSeconds(new \DateTime(), 3600),
2022-06-01 18:26:55 +12:00
]);
2022-06-03 21:12:19 +12:00
$response = $this->client->call(Client::METHOD_GET, '/health', [
2022-06-01 18:26:55 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $id,
'x-appwrite-key' => $response['body']['secret']
], []);
$this->assertEquals(200, $response['headers']['status-code']);
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Key Test',
'scopes' => ['health.read'],
2022-07-06 06:55:20 +12:00
'expire' => null,
2022-06-01 18:26:55 +12:00
]);
2022-06-03 21:12:19 +12:00
$response = $this->client->call(Client::METHOD_GET, '/health', [
2022-06-01 18:26:55 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $id,
'x-appwrite-key' => $response['body']['secret']
], []);
$this->assertEquals(200, $response['headers']['status-code']);
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Key Test',
'scopes' => ['health.read'],
2022-07-14 02:02:49 +12:00
'expire' => DateTime::addSeconds(new \DateTime(), -3600),
2022-06-01 18:26:55 +12:00
]);
2022-06-03 21:12:19 +12:00
$response = $this->client->call(Client::METHOD_GET, '/health', [
2022-06-01 18:26:55 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $id,
'x-appwrite-key' => $response['body']['secret']
], []);
$this->assertEquals(401, $response['headers']['status-code']);
2022-06-01 03:41:12 +12:00
}
2020-07-12 01:26:04 +12:00
/**
* @depends testCreateProjectKey
*/
public function testUpdateProjectKey($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
$keyId = $data['keyId'] ?? '';
2020-07-12 01:26:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/keys/' . $keyId, array_merge([
2020-07-12 01:26:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Key Test Update',
'scopes' => ['users.read', 'users.write', 'collections.read'],
2022-07-14 02:02:49 +12:00
'expire' => DateTime::addSeconds(new \DateTime(), 360),
2020-07-12 01:26:04 +12:00
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($keyId, $response['body']['$id']);
$this->assertEquals('Key Test Update', $response['body']['name']);
$this->assertContains('users.read', $response['body']['scopes']);
$this->assertContains('users.write', $response['body']['scopes']);
$this->assertContains('collections.read', $response['body']['scopes']);
$this->assertCount(3, $response['body']['scopes']);
2022-08-31 02:04:42 +12:00
$this->assertArrayHasKey('sdks', $response['body']);
$this->assertEmpty($response['body']['sdks']);
$this->assertArrayHasKey('accessedAt', $response['body']);
$this->assertEmpty($response['body']['accessedAt']);
2020-07-12 01:26:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([
2020-07-12 01:26:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($keyId, $response['body']['$id']);
$this->assertEquals('Key Test Update', $response['body']['name']);
$this->assertContains('users.read', $response['body']['scopes']);
$this->assertContains('users.write', $response['body']['scopes']);
$this->assertContains('collections.read', $response['body']['scopes']);
$this->assertCount(3, $response['body']['scopes']);
2022-08-31 02:04:42 +12:00
$this->assertArrayHasKey('sdks', $response['body']);
$this->assertEmpty($response['body']['sdks']);
$this->assertArrayHasKey('accessedAt', $response['body']);
$this->assertEmpty($response['body']['accessedAt']);
2022-04-19 04:21:45 +12:00
2020-07-12 01:26:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/keys/' . $keyId, array_merge([
2020-07-12 01:26:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Key Test Update',
'scopes' => ['users.read', 'users.write', 'collections.read', 'unknown'],
]);
$this->assertEquals(400, $response['headers']['status-code']);
return $data;
}
/**
* @depends testCreateProjectKey
*/
public function testDeleteProjectKey($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
$keyId = $data['keyId'] ?? '';
2020-07-12 01:26:04 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/' . $keyId, array_merge([
2020-07-12 01:26:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([
2020-07-12 01:26:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
2022-04-19 04:21:45 +12:00
2020-07-12 01:26:04 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/error', array_merge([
2020-07-12 01:26:04 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
return $data;
}
2020-07-12 07:40:58 +12:00
2020-07-12 23:57:31 +12:00
// Platforms
/**
* @depends testCreateProject
*/
public function testCreateProjectPlatform($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'type' => 'web',
'name' => 'Web App',
'key' => '',
'store' => '',
'hostname' => 'localhost',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('web', $response['body']['type']);
$this->assertEquals('Web App', $response['body']['name']);
$this->assertEquals('', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('localhost', $response['body']['hostname']);
2022-04-19 04:21:45 +12:00
2020-07-12 23:57:31 +12:00
$data = array_merge($data, ['platformWebId' => $response['body']['$id']]);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'type' => 'flutter-ios',
'name' => 'Flutter App (iOS)',
'key' => 'com.example.ios',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('flutter-ios', $response['body']['type']);
$this->assertEquals('Flutter App (iOS)', $response['body']['name']);
$this->assertEquals('com.example.ios', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
2022-04-19 04:21:45 +12:00
2020-07-12 23:57:31 +12:00
$data = array_merge($data, ['platformFultteriOSId' => $response['body']['$id']]);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'type' => 'flutter-android',
'name' => 'Flutter App (Android)',
'key' => 'com.example.android',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('flutter-android', $response['body']['type']);
$this->assertEquals('Flutter App (Android)', $response['body']['name']);
$this->assertEquals('com.example.android', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
2022-04-19 04:21:45 +12:00
2020-07-12 23:57:31 +12:00
$data = array_merge($data, ['platformFultterAndroidId' => $response['body']['$id']]);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'type' => 'apple-ios',
'name' => 'iOS App',
'key' => 'com.example.ios',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('apple-ios', $response['body']['type']);
$this->assertEquals('iOS App', $response['body']['name']);
$this->assertEquals('com.example.ios', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
$data = array_merge($data, ['platformAppleIosId' => $response['body']['$id']]);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'type' => 'apple-macos',
'name' => 'macOS App',
'key' => 'com.example.macos',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('apple-macos', $response['body']['type']);
$this->assertEquals('macOS App', $response['body']['name']);
$this->assertEquals('com.example.macos', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
$data = array_merge($data, ['platformAppleMacOsId' => $response['body']['$id']]);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'type' => 'apple-watchos',
'name' => 'watchOS App',
'key' => 'com.example.watchos',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('apple-watchos', $response['body']['type']);
$this->assertEquals('watchOS App', $response['body']['name']);
$this->assertEquals('com.example.watchos', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
$data = array_merge($data, ['platformAppleWatchOsId' => $response['body']['$id']]);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'type' => 'apple-tvos',
'name' => 'tvOS App',
'key' => 'com.example.tvos',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('apple-tvos', $response['body']['type']);
$this->assertEquals('tvOS App', $response['body']['name']);
$this->assertEquals('com.example.tvos', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
$data = array_merge($data, ['platformAppleTvOsId' => $response['body']['$id']]);
2020-07-12 23:57:31 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'type' => 'unknown',
'name' => 'Web App',
'key' => '',
'store' => '',
'hostname' => 'localhost',
]);
2021-12-02 00:48:23 +13:00
$this->assertEquals(400, $response['headers']['status-code']);
2020-07-12 23:57:31 +12:00
return $data;
}
2020-07-13 01:43:47 +12:00
/**
* @depends testCreateProjectPlatform
*/
public function testListProjectPlatform($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2021-12-02 00:48:23 +13:00
sleep(1);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms', array_merge([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
2022-02-27 22:57:09 +13:00
$this->assertEquals(7, $response['body']['total']);
2020-07-13 01:43:47 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
2020-07-13 01:43:47 +12:00
return $data;
}
2020-07-12 23:57:31 +12:00
/**
* @depends testCreateProjectPlatform
*/
public function testGetProjectPlatform($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2021-12-02 00:48:23 +13:00
2020-10-15 10:11:12 +13:00
$platformWebId = $data['platformWebId'] ?? '';
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformWebId, $response['body']['$id']);
$this->assertEquals('web', $response['body']['type']);
$this->assertEquals('Web App', $response['body']['name']);
$this->assertEquals('', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('localhost', $response['body']['hostname']);
2022-04-19 04:21:45 +12:00
2020-10-15 10:11:12 +13:00
$platformFultteriOSId = $data['platformFultteriOSId'] ?? '';
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformFultteriOSId, $response['body']['$id']);
$this->assertEquals('flutter-ios', $response['body']['type']);
$this->assertEquals('Flutter App (iOS)', $response['body']['name']);
$this->assertEquals('com.example.ios', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
2022-04-19 04:21:45 +12:00
2020-10-15 10:11:12 +13:00
$platformFultterAndroidId = $data['platformFultterAndroidId'] ?? '';
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformFultterAndroidId, $response['body']['$id']);
$this->assertEquals('flutter-android', $response['body']['type']);
$this->assertEquals('Flutter App (Android)', $response['body']['name']);
$this->assertEquals('com.example.android', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
2021-10-14 02:44:52 +13:00
$platformAppleIosId = $data['platformAppleIosId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformAppleIosId, $response['body']['$id']);
$this->assertEquals('apple-ios', $response['body']['type']);
$this->assertEquals('iOS App', $response['body']['name']);
$this->assertEquals('com.example.ios', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
$platformAppleMacOsId = $data['platformAppleMacOsId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformAppleMacOsId, $response['body']['$id']);
$this->assertEquals('apple-macos', $response['body']['type']);
$this->assertEquals('macOS App', $response['body']['name']);
$this->assertEquals('com.example.macos', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
$platformAppleWatchOsId = $data['platformAppleWatchOsId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformAppleWatchOsId, $response['body']['$id']);
$this->assertEquals('apple-watchos', $response['body']['type']);
$this->assertEquals('watchOS App', $response['body']['name']);
$this->assertEquals('com.example.watchos', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
$platformAppleTvOsId = $data['platformAppleTvOsId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformAppleTvOsId, $response['body']['$id']);
$this->assertEquals('apple-tvos', $response['body']['type']);
$this->assertEquals('tvOS App', $response['body']['name']);
$this->assertEquals('com.example.tvos', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
2020-07-12 23:57:31 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/error', array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
return $data;
}
/**
* @depends testCreateProjectPlatform
*/
public function testUpdateProjectPlatform($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2020-07-12 23:57:31 +12:00
2020-10-15 10:11:12 +13:00
$platformWebId = $data['platformWebId'] ?? '';
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Web App 2',
'key' => '',
'store' => '',
'hostname' => 'localhost-new',
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformWebId, $response['body']['$id']);
$this->assertEquals('web', $response['body']['type']);
$this->assertEquals('Web App 2', $response['body']['name']);
$this->assertEquals('', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('localhost-new', $response['body']['hostname']);
2020-10-15 10:11:12 +13:00
$platformFultteriOSId = $data['platformFultteriOSId'] ?? '';
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Flutter App (iOS) 2',
'key' => 'com.example.ios2',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformFultteriOSId, $response['body']['$id']);
$this->assertEquals('flutter-ios', $response['body']['type']);
$this->assertEquals('Flutter App (iOS) 2', $response['body']['name']);
$this->assertEquals('com.example.ios2', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
2022-04-19 04:21:45 +12:00
2020-10-15 10:11:12 +13:00
$platformFultterAndroidId = $data['platformFultterAndroidId'] ?? '';
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Flutter App (Android) 2',
'key' => 'com.example.android2',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformFultterAndroidId, $response['body']['$id']);
$this->assertEquals('flutter-android', $response['body']['type']);
$this->assertEquals('Flutter App (Android) 2', $response['body']['name']);
$this->assertEquals('com.example.android2', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
2021-10-14 02:44:52 +13:00
$platformAppleIosId = $data['platformAppleIosId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'iOS App 2',
'key' => 'com.example.ios2',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformAppleIosId, $response['body']['$id']);
$this->assertEquals('apple-ios', $response['body']['type']);
$this->assertEquals('iOS App 2', $response['body']['name']);
$this->assertEquals('com.example.ios2', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
$platformAppleMacOsId = $data['platformAppleMacOsId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'macOS App 2',
'key' => 'com.example.macos2',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformAppleMacOsId, $response['body']['$id']);
$this->assertEquals('apple-macos', $response['body']['type']);
$this->assertEquals('macOS App 2', $response['body']['name']);
$this->assertEquals('com.example.macos2', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
$platformAppleWatchOsId = $data['platformAppleWatchOsId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'watchOS App 2',
'key' => 'com.example.watchos2',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformAppleWatchOsId, $response['body']['$id']);
$this->assertEquals('apple-watchos', $response['body']['type']);
$this->assertEquals('watchOS App 2', $response['body']['name']);
$this->assertEquals('com.example.watchos2', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
$platformAppleTvOsId = $data['platformAppleTvOsId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'tvOS App 2',
'key' => 'com.example.tvos2',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($platformAppleTvOsId, $response['body']['$id']);
$this->assertEquals('apple-tvos', $response['body']['type']);
$this->assertEquals('tvOS App 2', $response['body']['name']);
$this->assertEquals('com.example.tvos2', $response['body']['key']);
$this->assertEquals('', $response['body']['store']);
$this->assertEquals('', $response['body']['hostname']);
2020-07-12 23:57:31 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/error', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Flutter App (Android) 2',
'key' => 'com.example.android2',
'store' => '',
'hostname' => '',
]);
$this->assertEquals(404, $response['headers']['status-code']);
2020-07-12 23:57:31 +12:00
return $data;
}
/**
* @depends testCreateProjectPlatform
*/
public function testDeleteProjectPlatform($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2022-04-19 04:21:45 +12:00
2020-10-15 10:11:12 +13:00
$platformWebId = $data['platformWebId'] ?? '';
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
2020-10-15 10:11:12 +13:00
$platformFultteriOSId = $data['platformFultteriOSId'] ?? '';
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
2020-10-15 10:11:12 +13:00
$platformFultterAndroidId = $data['platformFultterAndroidId'] ?? '';
2020-07-12 23:57:31 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
2021-10-14 02:44:52 +13:00
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
$platformAppleIosId = $data['platformAppleIosId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
$platformAppleMacOsId = $data['platformAppleMacOsId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
$platformAppleWatchOsId = $data['platformAppleWatchOsId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
$platformAppleTvOsId = $data['platformAppleTvOsId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([
2021-10-14 02:44:52 +13:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
2020-07-12 23:57:31 +12:00
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/webhooks/error', array_merge([
2020-07-12 23:57:31 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
return $data;
}
2020-07-13 01:43:47 +12:00
// Domains
/**
* @depends testCreateProject
*/
public function testCreateProjectDomain($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2020-07-13 01:43:47 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/domains', array_merge([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'domain' => 'sub.example.com',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
2020-10-31 08:53:27 +13:00
// $this->assertIsInt($response['body']['updated']);
2020-07-13 01:43:47 +12:00
$this->assertEquals('sub.example.com', $response['body']['domain']);
$this->assertEquals('com', $response['body']['tld']);
$this->assertEquals('example.com', $response['body']['registerable']);
$this->assertEquals(false, $response['body']['verification']);
2022-04-19 04:21:45 +12:00
2020-07-13 01:43:47 +12:00
$data = array_merge($data, ['domainId' => $response['body']['$id']]);
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'domain' => '123',
]);
2022-04-19 04:21:45 +12:00
2020-07-13 01:43:47 +12:00
$this->assertEquals(400, $response['headers']['status-code']);
2022-05-13 06:53:54 +12:00
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'type' => 'web',
'name' => 'Too Long Hostname',
'key' => '',
'store' => '',
'hostname' => \str_repeat("bestdomain", 25) . '.com' // 250 + 4 chars total (exactly above limit)
]);
2020-07-13 01:43:47 +12:00
return $data;
}
/**
* @depends testCreateProjectDomain
*/
public function testListProjectDomain($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/domains', array_merge([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
2022-02-27 22:57:09 +13:00
$this->assertEquals(1, $response['body']['total']);
2020-07-13 01:43:47 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
2020-07-13 01:43:47 +12:00
return $data;
}
/**
* @depends testCreateProjectDomain
*/
public function testGetProjectDomain($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
$domainId = $data['domainId'] ?? '';
2020-07-13 01:43:47 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/domains/' . $domainId, array_merge([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($domainId, $response['body']['$id']);
2020-10-31 08:53:27 +13:00
// $this->assertIsInt($response['body']['updated']);
2020-07-13 01:43:47 +12:00
$this->assertEquals('sub.example.com', $response['body']['domain']);
$this->assertEquals('com', $response['body']['tld']);
$this->assertEquals('example.com', $response['body']['registerable']);
$this->assertEquals(false, $response['body']['verification']);
2022-04-19 04:21:45 +12:00
2020-07-13 01:43:47 +12:00
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/domains/error', array_merge([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
return $data;
}
/**
* @depends testCreateProjectDomain
*/
public function testUpdateProjectDomain($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
$domainId = $data['domainId'] ?? '';
2020-07-13 01:43:47 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/domains/' . $domainId . '/verification', array_merge([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(401, $response['headers']['status-code']);
/**
* Test for FAILURE
*/
return $data;
}
/**
* @depends testCreateProjectDomain
*/
public function testDeleteProjectDomain($data): array
{
2020-10-15 10:11:12 +13:00
$id = $data['projectId'] ?? '';
$domainId = $data['domainId'] ?? '';
2020-07-13 01:43:47 +12:00
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/domains/' . $domainId, array_merge([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/domains/' . $domainId, array_merge([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
/**
* Test for FAILURE
*/
2022-04-19 04:21:45 +12:00
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/domains/error', array_merge([
2020-07-13 01:43:47 +12:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
return $data;
}
2022-10-03 21:06:48 +13:00
public function testDeleteProject(): array
{
$data = [];
// Create a team and a project
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'teamId' => ID::unique(),
'name' => 'Amating Team',
]);
$this->assertEquals(201, $team['headers']['status-code']);
$this->assertEquals('Amating Team', $team['body']['name']);
$this->assertNotEmpty($team['body']['$id']);
$teamId = $team['body']['$id'];
$project = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'projectId' => ID::unique(),
'name' => 'Amazing Project',
'teamId' => $teamId,
'region' => 'default'
]);
$this->assertEquals(201, $project['headers']['status-code']);
$this->assertEquals('Amazing Project', $project['body']['name']);
$this->assertEquals($teamId, $project['body']['teamId']);
$this->assertNotEmpty($project['body']['$id']);
$projectId = $project['body']['$id'];
// Ensure I can get both team and project
$team = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $team['headers']['status-code']);
$project = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $project['headers']['status-code']);
// Delete team
$team = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'password' => 'password'
]);
$this->assertEquals(204, $team['headers']['status-code']);
// Ensure I can get team but not a project
$team = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $team['headers']['status-code']);
$project = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(404, $project['headers']['status-code']);
return $data;
}
2020-07-12 07:40:58 +12:00
}