1
0
Fork 0
mirror of synced 2024-05-18 19:52:39 +12:00
appwrite/tests/e2e/Scopes/ProjectCustom.php

151 lines
4.9 KiB
PHP
Raw Normal View History

2019-09-16 08:17:10 +12:00
<?php
2020-01-12 02:58:02 +13:00
namespace Tests\E2E\Scopes;
2019-09-16 08:17:10 +12:00
use Tests\E2E\Client;
2020-01-12 02:58:02 +13:00
trait ProjectCustom
2019-09-16 08:17:10 +12:00
{
2020-01-12 02:58:02 +13:00
/**
* @var array
*/
2020-01-12 10:53:57 +13:00
protected static $project = [];
2019-09-16 08:17:10 +12:00
2020-01-12 02:58:02 +13:00
/**
* @return array
*/
public function getProject(): array
2019-09-16 08:17:10 +12:00
{
2020-10-28 08:48:38 +13:00
if (!empty(self::$project)) {
2020-01-12 10:53:57 +13:00
return self::$project;
2020-01-12 02:58:02 +13:00
}
2019-09-16 08:17:10 +12:00
2019-10-21 19:01:07 +13:00
$team = $this->client->call(Client::METHOD_POST, '/teams', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
2020-01-13 10:28:26 +13:00
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
2019-11-30 07:26:06 +13:00
'x-appwrite-project' => 'console',
2019-10-21 19:01:07 +13:00
], [
2021-07-19 19:50:51 +12:00
'teamId' => 'unique()',
2019-10-21 19:01:07 +13:00
'name' => 'Demo Project Team',
]);
$this->assertEquals(201, $team['headers']['status-code']);
$this->assertEquals('Demo Project Team', $team['body']['name']);
2020-02-17 20:16:11 +13:00
$this->assertNotEmpty($team['body']['$id']);
2019-10-21 19:01:07 +13:00
$project = $this->client->call(Client::METHOD_POST, '/projects', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
2020-01-13 10:28:26 +13:00
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
2019-11-30 07:26:06 +13:00
'x-appwrite-project' => 'console',
2019-10-21 19:01:07 +13:00
], [
2021-07-19 20:55:20 +12:00
'projectId' => 'unique()',
2019-10-21 19:01:07 +13:00
'name' => 'Demo Project',
2020-02-17 20:16:11 +13:00
'teamId' => $team['body']['$id'],
2019-10-21 19:01:07 +13:00
'description' => 'Demo Project Description',
'logo' => '',
'url' => 'https://appwrite.io',
'legalName' => '',
'legalCountry' => '',
'legalState' => '',
'legalCity' => '',
'legalAddress' => '',
'legalTaxId' => '',
]);
$this->assertEquals(201, $project['headers']['status-code']);
$this->assertNotEmpty($project['body']);
2020-02-17 20:16:11 +13:00
$key = $this->client->call(Client::METHOD_POST, '/projects/' . $project['body']['$id'] . '/keys', [
2019-10-21 19:01:07 +13:00
'origin' => 'http://localhost',
'content-type' => 'application/json',
2020-01-13 10:28:26 +13:00
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
2019-11-30 07:26:06 +13:00
'x-appwrite-project' => 'console',
2019-10-21 19:01:07 +13:00
], [
'name' => 'Demo Project Key',
2020-01-12 02:58:02 +13:00
'scopes' => [
'users.read',
'users.write',
'teams.read',
'teams.write',
Database layer (#3338) * database response model * database collection config * new database scopes * database service update * database execption codes * remove read write permission from database model * updating tests and fixing some bugs * server side tests are now passing * databases api * tests for database endpoint * composer update * fix error * formatting * formatting fixes * get database test * more updates to events and usage * more usage updates * fix delete type * fix test * delete database * more fixes * databaseId in attributes and indexes * more fixes * fix issues * fix index subquery * fix console scope and index query * updating tests as required * fix phpcs errors and warnings * updates to review suggestions * UI progress * ui updates and cleaning up * fix type * rework database events * update tests * update types * event generation fixed * events config updated * updating context to support multiple * realtime updates * fix ids * update context * validator updates * fix naming conflict * fix tests * fix lint errors * fix wprler and realtime tests * fix webhooks test * fix event validator and other tests * formatting fixes * removing leftover var_dumps * remove leftover comment * update usage params * usage metrics updates * update database usage * fix usage * specs update * updates to usage * fix UI and usage * fix lints * internal id fixes * fixes for internal Id * renaming services and related files * rename tests * rename doc link * rename readme * fix test name * tests: fixes for 0.15.x sync Co-authored-by: Torsten Dittmann <torsten.dittmann@googlemail.com>
2022-06-22 22:51:49 +12:00
'databases.read',
'databases.write',
'collections.read',
'collections.write',
'documents.read',
'documents.write',
2020-01-12 10:53:57 +13:00
'files.read',
'files.write',
2021-06-16 18:07:35 +12:00
'buckets.read',
2021-06-15 18:38:05 +12:00
'buckets.write',
2020-05-06 08:37:59 +12:00
'functions.read',
'functions.write',
2020-12-30 20:26:01 +13:00
'execution.read',
'execution.write',
'locale.read',
'avatars.read',
2020-06-07 18:01:35 +12:00
'health.read',
2020-01-12 02:58:02 +13:00
],
2019-10-21 19:01:07 +13:00
]);
2020-11-21 01:35:16 +13:00
$this->assertEquals(201, $key['headers']['status-code']);
2019-10-21 19:01:07 +13:00
$this->assertNotEmpty($key['body']);
$this->assertNotEmpty($key['body']['secret']);
2022-05-24 02:54:50 +12:00
$webhook = $this->client->call(Client::METHOD_POST, '/projects/' . $project['body']['$id'] . '/webhooks', [
2020-11-21 10:03:14 +13:00
'origin' => 'http://localhost',
2020-11-21 01:35:16 +13:00
'content-type' => 'application/json',
2020-11-21 10:03:14 +13:00
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
'x-appwrite-project' => 'console',
], [
2020-11-21 01:35:16 +13:00
'name' => 'Webhook Test',
'events' => [
Database layer (#3338) * database response model * database collection config * new database scopes * database service update * database execption codes * remove read write permission from database model * updating tests and fixing some bugs * server side tests are now passing * databases api * tests for database endpoint * composer update * fix error * formatting * formatting fixes * get database test * more updates to events and usage * more usage updates * fix delete type * fix test * delete database * more fixes * databaseId in attributes and indexes * more fixes * fix issues * fix index subquery * fix console scope and index query * updating tests as required * fix phpcs errors and warnings * updates to review suggestions * UI progress * ui updates and cleaning up * fix type * rework database events * update tests * update types * event generation fixed * events config updated * updating context to support multiple * realtime updates * fix ids * update context * validator updates * fix naming conflict * fix tests * fix lint errors * fix wprler and realtime tests * fix webhooks test * fix event validator and other tests * formatting fixes * removing leftover var_dumps * remove leftover comment * update usage params * usage metrics updates * update database usage * fix usage * specs update * updates to usage * fix UI and usage * fix lints * internal id fixes * fixes for internal Id * renaming services and related files * rename tests * rename doc link * rename readme * fix test name * tests: fixes for 0.15.x sync Co-authored-by: Torsten Dittmann <torsten.dittmann@googlemail.com>
2022-06-22 22:51:49 +12:00
'databases.*',
2022-04-04 18:30:07 +12:00
'functions.*',
'buckets.*',
'teams.*',
'users.*'
2020-11-21 01:35:16 +13:00
],
'url' => 'http://request-catcher:5000/webhook',
'security' => false,
'httpUser' => '',
'httpPass' => '',
]);
$this->assertEquals(201, $webhook['headers']['status-code']);
$this->assertNotEmpty($webhook['body']);
2020-01-12 02:58:02 +13:00
2020-01-12 10:53:57 +13:00
self::$project = [
2020-02-17 20:16:11 +13:00
'$id' => $project['body']['$id'],
2020-01-12 02:58:02 +13:00
'name' => $project['body']['name'],
'apiKey' => $key['body']['secret'],
2020-12-04 06:56:07 +13:00
'webhookId' => $webhook['body']['$id'],
2022-06-08 03:11:07 +12:00
'signatureKey' => $webhook['body']['signatureKey'],
2020-01-12 02:58:02 +13:00
];
2019-11-04 08:05:26 +13:00
2020-01-12 10:53:57 +13:00
return self::$project;
2019-10-21 19:01:07 +13:00
}
2021-05-14 02:47:35 +12:00
2022-05-24 02:54:50 +12:00
public function getNewKey(array $scopes)
{
2021-05-14 02:47:35 +12:00
$projectId = self::$project['$id'];
$key = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
'x-appwrite-project' => 'console',
], [
'name' => 'Demo Project Key',
'scopes' => $scopes,
]);
$this->assertEquals(201, $key['headers']['status-code']);
$this->assertNotEmpty($key['body']);
$this->assertNotEmpty($key['body']['secret']);
return $key['body']['secret'];
}
}