mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Add scope specific tests
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?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;
|
||||
|
||||
class GraphQLScopeTest extends Scope
|
||||
{
|
||||
use ProjectCustom;
|
||||
use SideServer;
|
||||
use GraphQLBase;
|
||||
|
||||
public function testInvalidScope()
|
||||
{
|
||||
$projectId = $this->getProject()['$id'];
|
||||
$apiKey = $this->getNewKey(['databases.read']);
|
||||
$query = $this->getQuery(self::$CREATE_DATABASE);
|
||||
$gqlPayload = [
|
||||
'query' => $query,
|
||||
'variables' => [
|
||||
'databaseId' => '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: application) 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' => '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']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user