1
0
Fork 0
mirror of synced 2024-07-07 23:46:11 +12:00

Database test fixes

This commit is contained in:
Jake Barnby 2022-07-01 18:58:03 +12:00
parent bdd65ed448
commit fb53acbf2a
2 changed files with 475 additions and 164 deletions

View file

@ -2,8 +2,6 @@
namespace Tests\E2E\Services\GraphQL;
use Tests\E2E\Client;
trait GraphQLBase
{
// Databases
@ -13,9 +11,9 @@ trait GraphQLBase
public static string $UPDATE_DATABASE = 'update_database';
public static string $DELETE_DATABASE = 'delete_database';
// Collections
public static string $CREATE_COLLECTION = 'create_collection';
public static string $GET_COLLECTION = 'get_collection';
public static string $GET_COLLECTIONS = 'list_collections';
public static string $CREATE_COLLECTION = 'create_collection';
public static string $UPDATE_COLLECTION = 'update_collection';
public static string $DELETE_COLLECTION = 'delete_collection';
// Attributes
@ -29,13 +27,17 @@ trait GraphQLBase
public static string $CREATE_ENUM_ATTRIBUTE = 'create_enum_attribute';
public static string $GET_ATTRIBUTES = 'get_attributes';
public static string $GET_ATTRIBUTE = 'get_attribute';
public static string $UPDATE_ATTRIBUTE = 'update_attribute';
public static string $DELETE_ATTRIBUTE = 'delete_attribute';
// Indexes
public static string $CREATE_INDEX = 'create_index';
public static string $GET_INDEXES = 'get_indexes';
public static string $GET_INDEX = 'get_index';
public static string $DELETE_INDEX = 'delete_index';
// Documents
public static string $GET_DOCUMENT = 'get_document';
public static string $LIST_DOCUMENTS = 'list_documents';
public static string $CREATE_DOCUMENT_REST = 'create_document_rest';
public static string $CREATE_DOCUMENT = 'create_document_rest';
public static string $CREATE_CUSTOM_ENTITY = 'create_document_hooks';
public static string $GET_DOCUMENTS = 'list_documents';
public static string $GET_DOCUMENT = 'get_document';
public static string $UPDATE_DOCUMENT = 'update_document';
public static string $DELETE_DOCUMENT = 'delete_document';
@ -122,40 +124,56 @@ trait GraphQLBase
public static string $DELETE_EXECUTION = 'delete_execution';
public static string $RETRY_BUILD = 'retry_build';
// Buckets
public static string $CREATE_BUCKET = 'create_bucket';
public static string $GET_BUCKETS = 'list_buckets';
public static string $GET_BUCKET = 'get_bucket';
public static string $UPDATE_BUCKET = 'update_bucket';
public static string $DELETE_BUCKET = 'delete_bucket';
// Files
public static string $CREATE_FILE = 'create_file';
public static string $GET_FILES = 'list_files';
public static string $GET_FILE = 'get_file';
public static string $UPDATE_FILE = 'update_file';
public static string $DELETE_FILE = 'delete_file';
public function getQuery(string $name): string
{
switch ($name) {
case self::$CREATE_DATABASE:
return 'mutation createDatabase($databaseId: String!, $name: String!) {
databasesCreateDatabase(databaseId: $databaseId, name: $name) {
databasesCreate(databaseId: $databaseId, name: $name) {
_id
name
}
}';
case self::$GET_DATABASES:
return 'query getDatabases {
databasesGetDatabases {
_id
name
databasesList {
total
databases {
_id
name
}
}
}';
case self::$GET_DATABASE:
return 'query getDatabase($databaseId: String!) {
databasesGetDatabase(databaseId: $databaseId) {
databasesGet(databaseId: $databaseId) {
_id
name
}
}';
case self::$UPDATE_DATABASE:
return 'mutation updateDatabase($databaseId: String!, $name: String!) {
databasesUpdateDatabase(databaseId: $databaseId, name: $name) {
databasesUpdate(databaseId: $databaseId, name: $name) {
_id
name
}
}';
case self::$DELETE_DATABASE:
return 'mutation deleteDatabase($databaseId: String!) {
databasesDeleteDatabase(databaseId: $databaseId)
databasesDelete(databaseId: $databaseId)
}';
case self::$GET_COLLECTION:
return 'query getCollection($databaseId: String!, $collectionId: String!) {
@ -275,15 +293,47 @@ trait GraphQLBase
array
}
}';
case self::$CREATE_INDEX:
return 'mutation createIndex($databaseId: String!, $collectionId: String!, $key: String!, $type: String!, $attributes: [String!]!, $orders: [String!]){
databasesCreateIndex(databaseId: $databaseId, collectionId: $collectionId, key: $key, type: $type, attributes: $attributes, orders: $orders) {
key
type
status
}
}';
case self::$GET_INDEXES:
return 'query getIndexes($databaseId: String!, $collectionId: String!) {
databasesGetIndexes(databaseId: $databaseId, collectionId: $collectionId) {
total
indexes {
key
type
status
}
}
}';
case self::$GET_INDEX:
return 'query getIndex($databaseId: String!, $collectionId: String!, $key: String!) {
databasesGetIndex(databaseId: $databaseId, collectionId: $collectionId, key: $key) {
key
type
status
}
}';
case self::$DELETE_INDEX:
return 'mutation deleteIndex($databaseId: String!, $collectionId: String!, $key: String!){
databasesDeleteIndex(databaseId: $databaseId, collectionId: $collectionId, key: $key)
}';
case self::$GET_ATTRIBUTES:
return 'query getAttributes($databaseId: String!, $collectionId: String!) {
databasesGetAttributes(databaseId: $databaseId, collectionId: $collectionId) {
databasesListAttributes(databaseId: $databaseId, collectionId: $collectionId) {
total
attributes {
key
required
default
array
status
}
}
}';
@ -301,8 +351,8 @@ trait GraphQLBase
databasesDeleteAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key)
}';
case self::$GET_DOCUMENT:
return 'query getDocument($collectionId: String!, $documentId: String!){
databasesGetDocument(collectionId: $collectionId, documentId: $documentId) {
return 'query getDocument($databaseId: String!, $collectionId: String!, $documentId: String!){
databasesGetDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId) {
_id
_collection
_read
@ -310,7 +360,7 @@ trait GraphQLBase
data
}
}';
case self::$LIST_DOCUMENTS:
case self::$GET_DOCUMENTS:
return 'query listDocuments($collectionId: String, $filters: [Json]){
databasesListDocuments(collectionId: $collectionId, filters: $filters) {
total
@ -321,9 +371,9 @@ trait GraphQLBase
}
}
}';
case self::$CREATE_DOCUMENT_REST:
return 'mutation createDocument($collectionId: String!, $documentId: String!, $data: Json!, $read: [String!]!, $write: [String!]!){
databasesCreateDocument(collectionId: $collectionId, documentId: $documentId, data: $data, read: $read, write: $write) {
case self::$CREATE_DOCUMENT:
return 'mutation createDocument($databaseId: String!, $collectionId: String!, $documentId: String!, $data: Json!, $read: [String!]!, $write: [String!]!){
databasesCreateDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId, data: $data, read: $read, write: $write) {
_id
_collection
_read
@ -962,6 +1012,84 @@ trait GraphQLBase
return 'mutation retryBuild($functionId: String!, $deploymentId: String!) {
functionsRetryBuild(functionId: $functionId, deploymentId: $deploymentId)
}';
case self::$CREATE_BUCKET:
return 'mutation createBucket($bucketId: String!, $name: String!, $permission: String!, $read: [String!]!, $write: [String!]!) {
storageCreateBucket(bucketId: $bucketId, name: $name, permission: $permission, read: $read, write: $write) {
_id
name
enabled
}
}';
case self::$GET_BUCKETS:
return 'query getBuckets {
storageListBuckets {
total
buckets {
_id
name
enabled
}
}
}';
case self::$GET_BUCKET:
return 'query getBucket($bucketId: String!) {
storageGetBucket(bucketId: $bucketId) {
_id
name
enabled
}
}';
case self::$UPDATE_BUCKET:
return 'mutation updateBucket($bucketId: String!, $name: String!, $permission: String!, $read: [String!]!, $write: [String!]!) {
storageUpdateBucket(bucketId: $bucketId, name: $name, permission: $permission, read: $read, write: $write) {
_id
name
enabled
}
}';
case self::$DELETE_BUCKET:
return 'mutation deleteBucket($bucketId: String!) {
storageDeleteBucket(bucketId: $bucketId)
}';
case self::$CREATE_FILE:
return 'mutation createFile($bucketId: String!, $fileId: String!, $file: InputFile!, $read: [String!]!, $write: [String!]!) {
storageCreateFile(bucketId: $bucketId, fileId: $fileId, file: $file, read: $read, write: $write) {
_id
name
content
}
}';
case self::$GET_FILES:
return 'query getFiles($bucketId: String!) {
storageListFiles(bucketId: $bucketId) {
total
files {
_id
name
content
}
}
}';
case self::$GET_FILE:
return 'query getFile($bucketId: String!, $fileId: String!) {
storageGetFile(bucketId: $bucketId, fileId: $fileId) {
_id
name
content
}
}';
case self::$UPDATE_FILE:
return 'mutation updateFile($bucketId: String!, $fileId: String!, $file: InputFile!, $read: [String!]!, $write: [String!]!) {
storageUpdateFile(bucketId: $bucketId, fileId: $fileId, file: $file, read: $read, write: $write) {
_id
name
content
}
}';
case self::$DELETE_FILE:
return 'mutation deleteFile($bucketId: String!, $fileId: String!) {
storageDeleteFile(bucketId: $bucketId, fileId: $fileId)
}';
}
throw new \InvalidArgumentException('Invalid query type');

View file

@ -21,7 +21,7 @@ class GraphQLDatabaseServerTest extends Scope
$gqlPayload = [
'query' => $query,
'variables' => [
'databasesId' => 'actors',
'databaseId' => 'actors',
'name' => 'Actors',
]
];
@ -33,7 +33,7 @@ class GraphQLDatabaseServerTest extends Scope
$this->assertIsArray($database['body']['data']);
$this->assertArrayNotHasKey('errors', $database['body']);
$database = $database['body']['data']['databasesCreateCollection'];
$database = $database['body']['data']['databasesCreate'];
$this->assertEquals('Actors', $database['name']);
return $database;
@ -42,14 +42,14 @@ class GraphQLDatabaseServerTest extends Scope
/**
* @depends testCreateDatabase
*/
public function testCreateCollection($data): array
public function testCreateCollection($database): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_COLLECTION);
$gqlPayload = [
'query' => $query,
'variables' => [
'databasesId' => $data['_id'],
'databaseId' => $database['_id'],
'collectionId' => 'actors',
'name' => 'Actors',
'permission' => 'collection',
@ -68,21 +68,25 @@ class GraphQLDatabaseServerTest extends Scope
$collection = $collection['body']['data']['databasesCreateCollection'];
$this->assertEquals('Actors', $collection['name']);
return $collection;
return [
'database' => $database,
'collection' => $collection,
];
}
/**
* @depends testCreateCollection
* @throws Exception
*/
public function testCreateStringAttribute(array $data): void
public function testCreateStringAttribute($data): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_STRING_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'collectionId' => $data['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'name',
'size' => 256,
'required' => true,
@ -98,22 +102,22 @@ class GraphQLDatabaseServerTest extends Scope
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databasesCreateStringAttribute']);
// Wait for attribute to be ready
sleep(2);
return $data;
}
/**
* @depends testCreateCollection
* @throws Exception
*/
public function testCreateIntegerAttribute(array $data): void
public function testCreateIntegerAttribute($data): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_INTEGER_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'collectionId' => $data['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'age',
'min' => 18,
'max' => 150,
@ -130,22 +134,22 @@ class GraphQLDatabaseServerTest extends Scope
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databasesCreateIntegerAttribute']);
// Wait for attribute to be ready
sleep(2);
return $data;
}
/**
* @depends testCreateCollection
* @throws Exception
*/
public function testCreateBooleanAttribute(array $data): void
public function testCreateBooleanAttribute($data): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_BOOLEAN_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'collectionId' => $data['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'alive',
'required' => true,
]
@ -160,22 +164,22 @@ class GraphQLDatabaseServerTest extends Scope
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databasesCreateBooleanAttribute']);
// Wait for attribute to be ready
sleep(2);
return $data;
}
/**
* @depends testCreateCollection
* @throws Exception
*/
public function testCreateFloatAttribute(array $data): void
public function testCreateFloatAttribute($data): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_FLOAT_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'collectionId' => $data['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'salary',
'min' => 1000.0,
'max' => 999999.99,
@ -193,24 +197,22 @@ class GraphQLDatabaseServerTest extends Scope
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databasesCreateFloatAttribute']);
// Wait for attribute to be ready
sleep(2);
return $data;
}
/**
* @depends testCreateDatabase
* @depends testCreateCollection
* @throws Exception
*/
public function testCreateEmailAttribute($database, $collection): void
public function testCreateEmailAttribute($data): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_EMAIL_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
'collectionId' => $collection['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'email',
'required' => true,
]
@ -225,28 +227,26 @@ class GraphQLDatabaseServerTest extends Scope
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databasesCreateEmailAttribute']);
// Wait for attribute to be ready
sleep(2);
return $data;
}
/**
* @depends testCreateDatabase
* @depends testCreateCollection
* @throws Exception
*/
public function testCreateEnumAttribute($database, $collection): void
public function testCreateEnumAttribute($data): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_ENUM_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
'collectionId' => $collection['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'role',
'elements' => [
'admin',
'user',
'crew',
'actor',
'guest',
],
'required' => true,
@ -262,26 +262,25 @@ class GraphQLDatabaseServerTest extends Scope
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databasesCreateEnumAttribute']);
// Wait for attribute to be ready
sleep(2);
return $data;
}
/**
* @depends testCreateDatabase
* @depends testCreateCollection
* @throws Exception
*/
public function testCreateIPAttribute($database, $collection): void
public function testCreateIPAttribute($data): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_IP_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
'collectionId' => $collection['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'ip',
'required' => true,
'required' => false,
'default' => '::1',
]
];
@ -292,28 +291,26 @@ class GraphQLDatabaseServerTest extends Scope
$this->assertArrayNotHasKey('errors', $attribute['body']);
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databasesCreateIPAttribute']);
$this->assertIsArray($attribute['body']['data']['databasesCreateIpAttribute']);
// Wait for attribute to be ready
sleep(2);
return $data;
}
/**
* @depends testCreateDatabase
* @depends testCreateCollection
* @throws Exception
*/
public function testCreateURLAttribute($database, $collection): void
public function testCreateURLAttribute($data): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_URL_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
'collectionId' => $collection['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'url',
'required' => true,
'required' => false,
'default' => 'https://appwrite.io',
]
];
@ -324,95 +321,108 @@ class GraphQLDatabaseServerTest extends Scope
$this->assertArrayNotHasKey('errors', $attribute['body']);
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databasesCreateURLAttribute']);
$this->assertIsArray($attribute['body']['data']['databasesCreateUrlAttribute']);
// Wait for attribute to be ready
sleep(2);
return $data;
}
/**
* @depends testCreateDatabase
* @depends testCreateCollection
* @depends testCreateStringAttribute
* @depends testCreateIntegerAttribute
* @throws Exception
*/
public function testCreateIndex($database, $collection): void
public function testCreateIndex($data1, $data2): array
{
$projectId = $this->getProject()['$id'];
// Wait for attributes to be available
sleep(10);
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_INDEX);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
'collectionId' => $collection['_id'],
'key' => 'nameIdx',
'databaseId' => $data2['database']['_id'],
'collectionId' => $data2['collection']['_id'],
'key' => 'index',
'type' => 'key',
'attributes' => [
'name',
'int',
'age',
],
]
];
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
$index = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertArrayNotHasKey('errors', $attribute['body']);
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databasesCreateIndex']);
\var_dump($index);
$this->assertArrayNotHasKey('errors', $index['body']);
$this->assertIsArray($index['body']['data']);
$this->assertIsArray($index['body']['data']['databasesCreateIndex']);
return $data2;
}
// /**
// * @depends testCreateCollection
// * @depends testCreateStringAttribute
// * @depends testCreateIntegerAttribute
// * @depends testCreateBooleanAttribute
// * @depends testCreateFloatAttribute
// * @throws \Exception
// */
// public function testCreateDocument(array $data): void
// {
// $projectId = $this->getProject()['$id'];
// $query = $this->getQuery(self::$CREATE_DOCUMENT_REST);
// $gqlPayload = [
// 'query' => $query,
// 'variables' => [
// 'collectionId' => $data['_id'],
// 'documentId' => 'unique()',
// 'data' => [
// 'name' => 'John Doe',
// 'age' => 30,
// 'alive' => true,
// 'salary' => 9999.5
// ],
// '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);
//
// $this->assertArrayNotHasKey('errors', $document['body']);
// $this->assertIsArray($document['body']['data']);
// $this->assertIsArray($document['body']['data']['databasesCreateDocument']);
// }
/**
* @depends testCreateStringAttribute
* @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 = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'documentId' => 'unique()',
'data' => [
'name' => 'John Doe',
'email' => 'example@appwrite.io',
'age' => 30,
'alive' => true,
'salary' => 9999.9,
'role' => 'crew',
],
'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);
$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
* @depends testCreateStringAttribute
* @depends testCreateIntegerAttribute
* @depends testCreateBooleanAttribute
* @depends testCreateFloatAttribute
* @throws Exception
*/
public function testCreateCustomEntity(): void
public function testCreateCustomEntity($data): void
{
// Wait for attributes to be available
sleep(3);
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_CUSTOM_ENTITY);
$gqlPayload = [
@ -421,7 +431,7 @@ $projectId = $this->getProject()['$id'];
'name' => 'John Doe',
'age' => 35,
'alive' => true,
'salary' => 9999.5,
'salary' => 9999.9,
]
];
@ -430,7 +440,7 @@ $projectId = $this->getProject()['$id'];
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
\var_dump($actor);
//\var_dump($actor);
$this->assertArrayNotHasKey('errors', $actor['body']);
$this->assertIsArray($actor['body']['data']);
@ -452,7 +462,7 @@ $projectId = $this->getProject()['$id'];
$this->assertArrayNotHasKey('errors', $databases['body']);
$this->assertIsArray($databases['body']['data']);
$this->assertIsArray($databases['body']['data']['databasesGetDatabases']);
$this->assertIsArray($databases['body']['data']['databasesList']);
}
/**
@ -477,17 +487,21 @@ $projectId = $this->getProject()['$id'];
$this->assertArrayNotHasKey('errors', $database['body']);
$this->assertIsArray($database['body']['data']);
$this->assertIsArray($database['body']['data']['databasesGetDatabase']);
$this->assertIsArray($database['body']['data']['databasesGet']);
}
public function testGetCollections($database): void
/**
* @depends testCreateCollection
* @throws Exception
*/
public function testGetCollections($data): void
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_COLLECTIONS);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
'databaseId' => $data['database']['_id'],
]
];
@ -498,23 +512,22 @@ $projectId = $this->getProject()['$id'];
$this->assertArrayNotHasKey('errors', $collections['body']);
$this->assertIsArray($collections['body']['data']);
$this->assertIsArray($collections['body']['data']['databasesGetCollections']);
$this->assertIsArray($collections['body']['data']['databasesListCollections']);
}
/**
* @depends testCreateDatabase
* @depends testCreateCollection
* @throws Exception
*/
public function testGetCollection($database, $collection): void
public function testGetCollection($data): void
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_COLLECTION);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
'collectionId' => $collection['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
]
];
@ -529,21 +542,22 @@ $projectId = $this->getProject()['$id'];
}
/**
* @depends testCreateDatabase
* @depends testCreateCollection
* @depends testCreateStringAttribute
* @depends testCreateIntegerAttribute
* @throws Exception
*/
public function testGetAttributes($database, $collection): void
public function testGetAttributes($data): void
{
// Wait for attributes to be available
sleep(5);
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_ATTRIBUTES);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
'collectionId' => $collection['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
]
];
@ -552,27 +566,29 @@ $projectId = $this->getProject()['$id'];
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
\var_dump($attributes);
$this->assertArrayNotHasKey('errors', $attributes['body']);
$this->assertIsArray($attributes['body']['data']);
$this->assertIsArray($attributes['body']['data']['databasesGetAttributes']);
$this->assertIsArray($attributes['body']['data']['databasesListAttributes']);
}
/**
* @depends testCreateDatabase
* @depends testCreateCollection
* @depends testCreateStringAttribute
* @depends testCreateIntegerAttribute
* @throws Exception
*/
public function testGetAttribute($database, $collection): void
public function testGetAttribute($data): void
{
// Wait for attributes to be available
sleep(3);
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
'collectionId' => $collection['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'name',
]
];
@ -587,6 +603,118 @@ $projectId = $this->getProject()['$id'];
$this->assertIsArray($attribute['body']['data']['databasesGetAttribute']);
}
/**
* @depends testCreateCollection
* @throws Exception
*/
public function testGetIndexes($data): void
{
// Wait for attributes to be available
sleep(3);
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_INDEXES);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
]
];
$indices = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertArrayNotHasKey('errors', $indices['body']);
$this->assertIsArray($indices['body']['data']);
$this->assertIsArray($indices['body']['data']['databasesGetIndices']);
}
/**
* @depends testCreateCollection
* @throws Exception
*/
public function testGetIndex($data): void
{
// Wait for attributes to be available
sleep(3);
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_INDEX);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'index',
]
];
$index = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertArrayNotHasKey('errors', $index['body']);
$this->assertIsArray($index['body']['data']);
$this->assertIsArray($index['body']['data']['databasesGetIndex']);
}
/**
* @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 testCreateDatabase
* @throws Exception
@ -610,23 +738,22 @@ $projectId = $this->getProject()['$id'];
$this->assertArrayNotHasKey('errors', $database['body']);
$this->assertIsArray($database['body']['data']);
$this->assertIsArray($database['body']['data']['databasesUpdateDatabase']);
$this->assertIsArray($database['body']['data']['databasesUpdate']);
}
/**
* @depends testCreateDatabase
* @depends testCreateCollection
* @throws Exception
*/
public function testUpdateCollection($database, $collection)
public function testUpdateCollection($data)
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$UPDATE_COLLECTION);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
'collectionId' => $collection['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'name' => 'New Collection Name',
'permission' => 'collection',
]
@ -642,6 +769,38 @@ $projectId = $this->getProject()['$id'];
$this->assertIsArray($collection['body']['data']['databasesUpdateCollection']);
}
/**
* @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->assertEquals('New Document Name', $document['name']);
}
/**
* @depends testCreateDatabase
* @throws Exception
@ -662,9 +821,7 @@ $projectId = $this->getProject()['$id'];
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertArrayNotHasKey('errors', $database['body']);
$this->assertIsArray($database['body']['data']);
$this->assertIsArray($database['body']['data']['databasesDeleteDatabase']);
$this->assertEquals(204, $database['headers']['status-code']);
}
/**
@ -693,20 +850,21 @@ $projectId = $this->getProject()['$id'];
}
/**
* @depends testCreateDatabase
* @depends testCreateCollection
* @depends testCreateStringAttribute
* @throws Exception
*/
public function testDeleteAttribute($database, $collection): void
public function testDeleteAttribute($datab): void
{
// Wait for attributes to be available
sleep(3);
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$DELETE_ATTRIBUTE);
$gqlPayload = [
'query' => $query,
'variables' => [
'databaseId' => $database['_id'],
'collectionId' => $collection['_id'],
'databaseId' => $data['database']['_id'],
'collectionId' => $data['collection']['_id'],
'key' => 'name',
]
];
@ -718,4 +876,29 @@ $projectId = $this->getProject()['$id'];
$this->assertEquals(204, $attribute['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(204, $document['headers']['status-code']);
}
}