1
0
Fork 0
mirror of synced 2024-06-02 10:54:44 +12:00
appwrite/tests/e2e/Scopes/ProjectCustom.php

179 lines
6.1 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
], [
'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
], [
'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',
'collections.read',
'collections.write',
'documents.read',
'documents.write',
2020-01-12 10:53:57 +13:00
'files.read',
'files.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']);
2020-11-21 10:03:14 +13:00
$webhook = $this->client->call(Client::METHOD_POST, '/projects/'.$project['body']['$id'].'/webhooks', [
'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' => [
'account.create',
'account.update.email',
'account.update.name',
'account.update.password',
'account.update.prefs',
'account.recovery.create',
'account.recovery.update',
2020-11-21 10:03:14 +13:00
'account.verification.create',
'account.verification.update',
2020-11-21 01:35:16 +13:00
'account.delete',
'account.sessions.create',
'account.sessions.delete',
'database.collections.create',
'database.collections.update',
'database.collections.delete',
'database.documents.create',
2020-12-01 10:41:58 +13:00
'database.documents.update',
2020-11-21 01:35:16 +13:00
'database.documents.delete',
2021-03-13 10:23:37 +13:00
'functions.create',
'functions.update',
'functions.delete',
'functions.tags.create',
'functions.tags.update',
'functions.tags.delete',
'functions.executions.create',
'functions.executions.update',
2020-11-21 01:35:16 +13:00
'storage.files.create',
'storage.files.update',
'storage.files.delete',
'users.create',
2021-03-13 02:06:53 +13:00
'users.update.prefs',
2020-11-21 01:35:16 +13:00
'users.update.status',
'users.delete',
'users.sessions.delete',
2020-12-03 11:15:20 +13:00
'teams.create',
'teams.update',
'teams.delete',
'teams.memberships.create',
'teams.memberships.update.status',
'teams.memberships.delete',
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'],
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
public function getNewKey(array $scopes) {
$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'];
}
}