1
0
Fork 0
mirror of synced 2024-10-04 04:06:16 +13:00

Client database test fixes

This commit is contained in:
Jake Barnby 2022-07-07 12:53:58 +12:00
parent 67807f8c6f
commit d0f81c9621
2 changed files with 383 additions and 102 deletions

View file

@ -2,6 +2,7 @@
namespace Tests\E2E\Services\GraphQL;
use Tests\E2E\Client;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideClient;
@ -11,4 +12,284 @@ class GraphQLDatabaseClientTest extends Scope
use ProjectCustom;
use SideClient;
use GraphQLBase;
public function testCreateDatabase(): array
{
$projectId = $this->getProject()['$id'];
$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' => $this->getProject()['apiKey'],
], $gqlPayload);
$this->assertIsArray($database['body']['data']);
$this->assertArrayNotHasKey('errors', $database['body']);
$database = $database['body']['data']['databasesCreate'];
$this->assertEquals('Actors', $database['name']);
return $database;
}
/**
* @depends testCreateDatabase
*/
public function testCreateCollection($database): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_COLLECTION);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
'collectionId' => 'actors',
'name' => 'Actors',
'permission' => 'collection',
'read' => ['role:all'],
'write' => ['role:member'],
]
];
$collection = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-key' => $this->getProject()['apiKey'],
], $gqlPayload);
$this->assertIsArray($collection['body']['data']);
$this->assertArrayNotHasKey('errors', $collection['body']);
$collection = $collection['body']['data']['databasesCreateCollection'];
$this->assertEquals('Actors', $collection['name']);
return [
'database' => $database,
'collection' => $collection,
];
}
/**
* @depends testCreateCollection
*/
public function testCreateStringAttribute($data): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_STRING_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'name',
'size' => 256,
'required' => true,
]
];
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-key' => $this->getProject()['apiKey'],
], $gqlPayload);
$this->assertArrayNotHasKey('errors', $attribute['body']);
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databasesCreateStringAttribute']);
return $data;
}
/**
* @depends testCreateCollection
*/
public function testCreateIntegerAttribute($data): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_INTEGER_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'age',
'min' => 18,
'max' => 150,
'required' => true,
]
];
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-key' => $this->getProject()['apiKey'],
], $gqlPayload);
$this->assertArrayNotHasKey('errors', $attribute['body']);
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databasesCreateIntegerAttribute']);
return $data;
}
/**
* @depends testCreateStringAttribute
* @depends testCreateIntegerAttribute
*/
public function testCreateDocument($data): array
{
sleep(1);
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_DOCUMENT);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'documentId' => 'unique()',
'data' => [
'name' => 'John Doe',
'age' => 35,
],
'read' => ['role:all'],
'write' => ['role:all'],
]
];
$document = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
\var_dump($document);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$document = $document['body']['data']['databasesCreateDocument'];
$this->assertIsArray($document);
return [
'database' => $data['database'],
'collection' => $data['collection'],
'document' => $document,
];
}
/**
* @depends testCreateCollection
* @throws \Exception
*/
public function testGetDocuments($data): void
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_DOCUMENTS);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
]
];
$documents = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertArrayNotHasKey('errors', $documents['body']);
$this->assertIsArray($documents['body']['data']);
$this->assertIsArray($documents['body']['data']['databasesListDocuments']);
}
/**
* @depends testCreateDocument
* @throws \Exception
*/
public function testGetDocument($data): void
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_DOCUMENT);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'documentId' => $data['document']['_id'],
]
];
$document = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['databasesGetDocument']);
}
/**
* @depends testCreateDocument
* @throws \Exception
*/
public function testUpdateDocument($data): void
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$UPDATE_DOCUMENT);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'documentId' => $data['document']['_id'],
'data' => [
'name' => 'New Document Name',
],
]
];
$document = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$document = $document['body']['data']['databasesUpdateDocument'];
$this->assertIsArray($document);
$this->assertStringContainsString('New Document Name', $document['data']);
}
/**
* @depends testCreateDocument
* @throws \Exception
*/
public function testDeleteDocument($data): void
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$DELETE_DOCUMENT);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'documentId' => $data['document']['_id'],
]
];
$document = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertEquals(200, $document['headers']['status-code']);
}
}

View file

@ -371,13 +371,13 @@ class GraphQLDatabaseServerTest extends Scope
/**
* @depends testCreateStringAttribute
* @depends testCreateIntegerAttribute
* @depends testCreateBooleanAttribute
* @depends testCreateEnumAttribute
* @throws Exception
*/
public function testCreateDocument($data): array
{
// Wait for attributes to be available
sleep(3);
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_DOCUMENT);
$gqlPayload = [
@ -817,103 +817,103 @@ class GraphQLDatabaseServerTest extends Scope
$this->assertStringContainsString('New Document Name', $document['data']);
}
// /**
// * @depends testCreateDocument
// * @throws Exception
// */
// public function testDeleteDocument($data): void
// {
// $projectId = $this->getProject()['$id'];
// $query = $this->getQuery(self::$DELETE_DOCUMENT);
// $gqlPayload = [
// 'query' => $query,
// 'variables' => [
// 'databaseId' => $data['database']['_id'],
// 'collectionId' => $data['collection']['_id'],
// 'documentId' => $data['document']['_id'],
// ]
// ];
//
// $document = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $projectId,
// ], $this->getHeaders()), $gqlPayload);
//
// $this->assertEquals(204, $document['headers']['status-code']);
// }
//
// /**
// * @depends testCreateStringAttribute
// * @throws Exception
// */
// public function testDeleteAttribute($data): void
// {
// // Wait for attributes to be available
// sleep(3);
//
// $projectId = $this->getProject()['$id'];
// $query = $this->getQuery(self::$DELETE_ATTRIBUTE);
// $gqlPayload = [
// 'query' => $query,
// 'variables' => [
// 'databaseId' => $data['database']['_id'],
// 'collectionId' => $data['collection']['_id'],
// 'key' => 'name',
// ]
// ];
//
// $attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $projectId,
// ], $this->getHeaders()), $gqlPayload);
//
// $this->assertEquals(204, $attribute['headers']['status-code']);
// }
//
// /**
// * @depends testCreateCollection
// * @throws Exception
// */
// public function testDeleteCollection($data)
// {
// $projectId = $this->getProject()['$id'];
// $query = $this->getQuery(self::$DELETE_COLLECTION);
// $gqlPayload = [
// 'query' => $query,
// 'variables' => [
// 'databaseId' => $data['database']['_id'],
// 'collectionId' => $data['collection']['_id'],
// ]
// ];
//
// $collection = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $projectId,
// ], $this->getHeaders()), $gqlPayload);
//
// $this->assertEquals(204, $collection['headers']['status-code']);
// }
//
// /**
// * @depends testCreateDatabase
// * @throws Exception
// */
// public function testDeleteDatabase($database)
// {
// $projectId = $this->getProject()['$id'];
// $query = $this->getQuery(self::$DELETE_DATABASE);
// $gqlPayload = [
// 'query' => $query,
// 'variables' => [
// 'databaseId' => $database['_id'],
// ]
// ];
//
// $database = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $projectId,
// ], $this->getHeaders()), $gqlPayload);
//
// $this->assertEquals(204, $database['headers']['status-code']);
// }
/**
* @depends testCreateDocument
* @throws Exception
*/
public function testDeleteDocument($data): void
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$DELETE_DOCUMENT);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'documentId' => $data['document']['_id'],
]
];
$document = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertEquals(200, $document['headers']['status-code']);
}
/**
* @depends testCreateStringAttribute
* @throws Exception
*/
public function testDeleteAttribute($data): void
{
// Wait for attributes to be available
sleep(3);
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$DELETE_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'name',
]
];
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertEquals(204, $attribute['headers']['status-code']);
}
/**
* @depends testCreateCollection
* @throws Exception
*/
public function testDeleteCollection($data)
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$DELETE_COLLECTION);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
]
];
$collection = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertEquals(204, $collection['headers']['status-code']);
}
/**
* @depends testCreateDatabase
* @throws Exception
*/
public function testDeleteDatabase($database)
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$DELETE_DATABASE);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
]
];
$database = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertEquals(204, $database['headers']['status-code']);
}
}