2021-03-13 07:00:41 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\GraphQL;
|
|
|
|
|
|
|
|
use Tests\E2E\Client;
|
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Scopes\SideClient;
|
2021-03-17 03:34:43 +13:00
|
|
|
use Tests\E2E\Scopes\SideServer;
|
2021-03-13 07:00:41 +13:00
|
|
|
|
|
|
|
class GraphQLBase extends Scope
|
|
|
|
{
|
|
|
|
use ProjectCustom;
|
2021-03-17 03:34:43 +13:00
|
|
|
use SideServer;
|
2021-03-13 07:00:41 +13:00
|
|
|
|
2021-03-17 03:34:43 +13:00
|
|
|
public function createKey(string $name, array $scopes): string {
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2021-03-13 07:00:41 +13:00
|
|
|
$query = "
|
2021-03-17 03:34:43 +13:00
|
|
|
mutation createKey(\$projectId: String!, \$name: String!, \$scopes: [Json]!){
|
|
|
|
projects_createKey (projectId: \$projectId, name: \$name, scopes: \$scopes) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
scopes
|
|
|
|
secret
|
2021-03-13 07:00:41 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
";
|
2021-03-17 03:34:43 +13:00
|
|
|
|
2021-03-13 07:00:41 +13:00
|
|
|
$variables = [
|
2021-03-17 03:34:43 +13:00
|
|
|
"projectId" => $projectId,
|
|
|
|
"name" => $name,
|
|
|
|
"scopes" => $scopes
|
2021-03-13 07:00:41 +13:00
|
|
|
];
|
|
|
|
|
|
|
|
$graphQLPayload = [
|
|
|
|
"query" => $query,
|
|
|
|
"variables" => $variables
|
|
|
|
];
|
2021-03-17 03:34:43 +13:00
|
|
|
|
|
|
|
$key = $this->client->call(Client::METHOD_POST, '/graphql', [
|
2021-03-13 07:00:41 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2021-03-17 03:34:43 +13:00
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
'x-appwrite-project' => 'console'
|
|
|
|
], $graphQLPayload);
|
2021-03-13 07:00:41 +13:00
|
|
|
|
2021-03-17 03:34:43 +13:00
|
|
|
$this->assertEquals($key['headers']['status-code'], 201);
|
|
|
|
$this->assertNull($key['body']['errors']);
|
|
|
|
$this->assertIsArray($key['body']['data']);
|
|
|
|
$this->assertIsArray($key['body']['data']['projects_createKey']);
|
|
|
|
|
|
|
|
return $key['body']['data']['projects_createKey']['secret'];
|
2021-03-13 07:00:41 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|