1
0
Fork 0
mirror of synced 2024-09-14 00:17:50 +12:00
appwrite/tests/e2e/Services/GraphQL/GraphQLBase.php

55 lines
1.6 KiB
PHP
Raw Normal View History

<?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;
class GraphQLBase extends Scope
{
use ProjectCustom;
2021-03-17 03:34:43 +13:00
use SideServer;
2021-03-17 03:34:43 +13:00
public function createKey(string $name, array $scopes): string {
$projectId = $this->getProject()['$id'];
$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-17 03:34:43 +13:00
$variables = [
2021-03-17 03:34:43 +13:00
"projectId" => $projectId,
"name" => $name,
"scopes" => $scopes
];
$graphQLPayload = [
"query" => $query,
"variables" => $variables
];
2021-03-17 03:34:43 +13:00
$key = $this->client->call(Client::METHOD_POST, '/graphql', [
'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-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'];
}
}