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

130 lines
4.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-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
2020-01-12 10:53:57 +13:00
$email = uniqid().'user@localhost.test';
$password = 'password';
$name = 'User Name';
2020-01-12 02:58:02 +13:00
$root = $this->client->call(Client::METHOD_POST, '/account', [
2019-09-16 08:17:10 +12:00
'origin' => 'http://localhost',
'content-type' => 'application/json',
2019-11-30 07:26:06 +13:00
'x-appwrite-project' => 'console',
2019-09-16 08:17:10 +12:00
], [
2020-01-12 10:53:57 +13:00
'email' => $email,
'password' => $password,
'name' => $name,
2019-09-16 08:17:10 +12:00
]);
2019-10-21 19:01:07 +13:00
2020-01-12 02:58:02 +13:00
$this->assertEquals(201, $root['headers']['status-code']);
2019-11-04 08:05:26 +13:00
2020-01-12 10:53:57 +13:00
$session = $this->client->call(Client::METHOD_POST, '/account/sessions', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => 'console',
], [
'email' => $email,
'password' => $password,
]);
$session = $this->client->parseCookie($session['headers']['set-cookie'])['a_session_console'];
2019-10-21 19:01:07 +13:00
$team = $this->client->call(Client::METHOD_POST, '/teams', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $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']);
$this->assertNotEmpty($team['body']['$uid']);
$project = $this->client->call(Client::METHOD_POST, '/projects', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $session,
2019-11-30 07:26:06 +13:00
'x-appwrite-project' => 'console',
2019-10-21 19:01:07 +13:00
], [
'name' => 'Demo Project',
'teamId' => $team['body']['$uid'],
'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']);
$key = $this->client->call(Client::METHOD_POST, '/projects/' . $project['body']['$uid'] . '/keys', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $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',
'locale.read',
'avatars.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,
// 'projectUid' => $project['body']['$uid'],
// 'projectAPIKeySecret' => $key['body']['secret'],
// 'projectSession' => $this->client->parseCookie($user['headers']['set-cookie'])['a_session_' . $project['body']['$uid']],
// ];
2020-01-12 10:53:57 +13:00
self::$project = [
2020-01-12 02:58:02 +13:00
'$uid' => $project['body']['$uid'],
'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
}
}