1
0
Fork 0
mirror of synced 2024-07-27 09:15:56 +12:00
appwrite/tests/e2e/Services/GraphQL/ScopeTest.php
2024-01-10 16:39:14 +13:00

67 lines
2.1 KiB
PHP

<?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;
use Tests\E2E\Scopes\SideServer;
use Utopia\Database\Helpers\ID;
class ScopeTest extends Scope
{
use ProjectCustom;
use SideServer;
use Base;
public function testInvalidScope()
{
$projectId = $this->getProject()['$id'];
$apiKey = $this->getNewKey(['databases.read']);
$query = $this->getQuery(self::$CREATE_DATABASE);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => ID::unique(),
'name' => 'Actors',
]
];
$database = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-key' => $apiKey,
], $gqlPayload);
$message = "app.{$projectId}@service.localhost (role: applications) missing scope (databases.write)";
$this->assertArrayHasKey('errors', $database['body']);
$this->assertEquals($message, $database['body']['errors'][0]['message']);
}
public function testValidScope()
{
$projectId = $this->getProject()['$id'];
$apiKey = $this->getNewKey(['databases.read', 'databases.write']);
$query = $this->getQuery(self::$CREATE_DATABASE);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => ID::unique(),
'name' => 'Actors',
]
];
$database = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-key' => $apiKey,
], $gqlPayload);
$this->assertIsArray($database['body']['data']);
$this->assertArrayNotHasKey('errors', $database['body']);
$database = $database['body']['data']['databasesCreate'];
$this->assertEquals('Actors', $database['name']);
}
}