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

106 lines
3.4 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-01-12 10:53:57 +13:00
if(!empty(self::$project)) {
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',
'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
]);
$this->assertEquals(201, $project['headers']['status-code']);
$this->assertNotEmpty($key['body']);
$this->assertNotEmpty($key['body']['secret']);
2020-01-12 02:58:02 +13:00
// return [
// 'email' => $this->demoEmail,
// 'password' => $this->demoPassword,
// 'session' => $session,
2020-02-17 20:16:11 +13:00
// 'projectUid' => $project['body']['$id'],
2020-01-12 02:58:02 +13:00
// 'projectAPIKeySecret' => $key['body']['secret'],
2020-02-17 20:16:11 +13:00
// 'projectSession' => $this->client->parseCookie($user['headers']['set-cookie'])['a_session_' . $project['body']['$id']],
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'],
];
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
}
}