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

Test fixes

This commit is contained in:
Jake Barnby 2022-06-27 18:46:01 +12:00
parent d019937e4f
commit b09e5aac8a
4 changed files with 145 additions and 153 deletions

View file

@ -323,10 +323,12 @@ class Builder
if (str_starts_with($route->getPath(), '/v1/mock/')) {
continue;
}
$namespace = $route->getLabel('sdk.namespace', '');
$methodName = $namespace . \ucfirst($route->getLabel('sdk.method', ''));
$responseModelNames = $route->getLabel('sdk.response.model', "none");
// TODO: Handle "none" responses
if ($responseModelNames === "none") {
continue;
}
@ -363,10 +365,18 @@ class Builder
'resolve' => $resolve
];
if ($method == 'GET') {
$queryFields[$methodName] = $field;
} elseif ($method == 'POST' || $method == 'PUT' || $method == 'PATCH' || $method == 'DELETE') {
$mutationFields[$methodName] = $field;
switch ($method) {
case 'GET':
$queryFields[$methodName] = $field;
break;
case 'POST':
case 'PUT':
case 'PATCH':
case 'DELETE':
$mutationFields[$methodName] = $field;
break;
default:
throw new \Exception("Unsupported method: $method");
}
}
}
@ -508,7 +518,7 @@ class Builder
$wg->wait();
$time_elapsed_secs = (microtime(true) - $start) * 1000;
Console::info('[INFO] Built GraphQL Project Collection Schema (approx. ' . $count . ' attributes) in ' . $time_elapsed_secs . 'ms');
Console::info('[INFO] Built GraphQL Project Collection Schema (' . $count . ' attributes) in ' . $time_elapsed_secs . 'ms');
return [
'query' => $queryFields,

View file

@ -16,7 +16,7 @@ trait GraphQLBase
static string $CREATE_STRING_ATTRIBUTE = 'create_string_attribute';
static string $CREATE_INTEGER_ATTRIBUTE = 'create_integer_attribute';
static string $CREATE_FLOAT_ATTRIBUTE = 'create_float_attribute';
static string $CREATE_BOOLEAN_ATTRIBUTE = 'create_float_attribute';
static string $CREATE_BOOLEAN_ATTRIBUTE = 'create_boolean_attribute';
static string $CREATE_URL_ATTRIBUTE = 'create_string_attribute';
static string $CREATE_EMAIL_ATTRIBUTE = 'create_string_attribute';
static string $CREATE_IP_ATTRIBUTE = 'create_string_attribute';
@ -122,10 +122,10 @@ trait GraphQLBase
return 'mutation updateCollection($collectionId: String!, $name: String!, $permission: String!, $read: [String!]!, $write: [String!]!, $enabled: Boolean){
databaseUpdateCollection (collectionId: $collectionId, name: $name, permission: $permission, read: $read, write: $write, enabled: $enabled) {
_id
_read
_write
name
permission
read
write
}
}';
case self::$DELETE_COLLECTION:
@ -135,7 +135,6 @@ trait GraphQLBase
case self::$CREATE_STRING_ATTRIBUTE:
return 'mutation createStringAttribute($collectionId: String!, $key: String!, $size: Int!, $required: Boolean!, $default: String, $array: Boolean){
databaseCreateStringAttribute (collectionId: $collectionId, key: $key, size: $size, required: $required, default: $default, array: $array) {
_id
key
required
default
@ -145,7 +144,6 @@ trait GraphQLBase
case self::$CREATE_INTEGER_ATTRIBUTE:
return 'mutation createIntegerAttribute($collectionId: String!, $key: String!, $required: Boolean!, $min: Int, $max: Int, $default: Int, $array: Boolean){
databaseCreateIntegerAttribute (collectionId: $collectionId, key: $key, min: $min, max: $max, required: $required, default: $default, array: $array) {
_id
key
required
min
@ -157,7 +155,6 @@ trait GraphQLBase
case self::$CREATE_FLOAT_ATTRIBUTE:
return 'mutation createFloatAttribute($collectionId: String!, $key: String!, $required: Boolean!, $min: Float, $max: Float, $default: Float, $array: Boolean){
databaseCreateFloatAttribute (collectionId: $collectionId, key: $key, min: $min, max: $max, required: $required, default: $default, array: $array) {
_id
key
required
min
@ -169,7 +166,6 @@ trait GraphQLBase
case self::$CREATE_BOOLEAN_ATTRIBUTE:
return 'mutation createBooleanAttribute($collectionId: String!, $key: String!, $required: Boolean!, $default: Boolean, $array: Boolean){
databaseCreateBooleanAttribute (collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) {
_id
key
required
default
@ -179,7 +175,6 @@ trait GraphQLBase
case self::$CREATE_URL_ATTRIBUTE:
return 'mutation createUrlAttribute($collectionId: String!, $key: String!, $required: Boolean!, $default: String, $array: Boolean){
databaseCreateUrlAttribute (collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) {
_id
key
required
default
@ -189,7 +184,6 @@ trait GraphQLBase
case self::$CREATE_EMAIL_ATTRIBUTE:
return 'mutation createEmailAttribute($collectionId: String!, $key: String!, $required: Boolean!, $default: String, $array: Boolean){
databaseCreateEmailAttribute (collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) {
_id
key
required
default
@ -199,7 +193,6 @@ trait GraphQLBase
case self::$CREATE_IP_ATTRIBUTE:
return 'mutation createIpAttribute($collectionId: String!, $key: String!, $required: Boolean!, $default: String, $array: Boolean){
databaseCreateIpAttribute (collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) {
_id
key
required
default
@ -209,7 +202,6 @@ trait GraphQLBase
case self::$CREATE_ENUM_ATTRIBUTE:
return 'mutation createEnumAttribute($collectionId: String!, $key: String!, $elements: [String!]!, $required: Boolean!, $default: String, $array: Boolean){
databaseCreateEnumAttribute (collectionId: $collectionId, key: $key, elements: $elements, required: $required, default: $default, array: $array) {
_id
key
elements
required
@ -221,13 +213,9 @@ trait GraphQLBase
return 'query getDocument($collectionId: String!, $documentId: String!){
databaseGetDocument (collectionId: $collectionId, documentId: $documentId) {
_id
collectionId
data {
name
age
alive
salary
}
_collection
_read
_write
}
}';
case self::$LIST_DOCUMENTS :
@ -244,15 +232,9 @@ trait GraphQLBase
return 'mutation createDocument($collectionId: String!, $documentId: String!, $data: Json!, $read: [String!]!, $write: [String!]!){
databaseCreateDocument (collectionId: $collectionId, documentId: $documentId, data: $data, read: $read, write: $write) {
_id
documentId
data {
name
age
alive
salary
}
read
write
_collection
_read
_write
}
}';
case self::$CREATE_DOCUMENT_GQL_HOOKS:
@ -266,15 +248,9 @@ trait GraphQLBase
}';
case self::$UPDATE_DOCUMENT:
return 'mutation updateDocument($collectionId: String!, $documentId: String!, $data: Json!, $read: [String!]!, $write: [String!]!){
databaseUpdateDocument (collectionId: $collectionId, documentId: $documentId,data: $data, read: $read, write: $write) {
databaseUpdateDocument (collectionId: $collectionId, documentId: $documentId, data: $data, read: $read, write: $write) {
_id
collectionId
data {
name
age
alive
salary
}
_collection
}
}';
case self::$DELETE_DOCUMENT:
@ -517,7 +493,7 @@ trait GraphQLBase
}
}';
case self::$CREATE_TEAM:
return 'mutation createTeam($teamId: String!, $name: String!, $roles: [Json]){
return 'mutation createTeam($teamId: String!, $name: String!, $roles: [String]){
teamsCreate(teamId: $teamId, name : $name, roles: $roles) {
_id
name
@ -721,7 +697,6 @@ trait GraphQLBase
public function testCreateCollection(): array
{
$projectId = $this->getProject()['$id'];
$key = '';
$query = $this->getQuery(self::$CREATE_COLLECTION);
$collectionAttrs = [
@ -729,7 +704,7 @@ trait GraphQLBase
'name' => 'Actors',
'permission' => 'collection',
'read' => ['role:all'],
'write' => ['role:member', 'role:admin'],
'write' => ['role:member'],
];
$gqlPayload = [
@ -741,7 +716,6 @@ trait GraphQLBase
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-key' => $key
], $gqlPayload);
$errorMessage = 'User (role: guest) missing scope (collections.write)';
@ -750,30 +724,26 @@ trait GraphQLBase
$this->assertIsArray($actors['body']['data']);
$this->assertNull($actors['body']['data']['databaseCreateCollection']);
$key = $this->createKey('test', ['collections.write']);
$actors = $this->client->call(Client::METHOD_POST, '/graphql', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-key' => $key
'x-appwrite-key' => $this->getProject()['apiKey']
], $gqlPayload);
$this->assertEquals(201, $actors['headers']['status-code']);
$this->assertNull($actors['body']['errors']);
$this->assertArrayNotHasKey('errors', $actors['body']);
$this->assertIsArray($actors['body']['data']);
$data = $actors['body']['data']['databaseCreateCollection'];
$this->assertEquals('Actors', $data['name']);
$this->assertArrayHasKey('id', $data);
$this->assertArrayHasKey('permissions', $data);
$this->assertContains('role:all', $data['read']);
$this->assertContains('role:member', $data['write']);
$this->assertContains('role:admin', $data['write']);
$this->assertArrayHasKey('_id', $data);
$this->assertArrayHasKey('permission', $data);
$this->assertContains('role:all', $data['_read']);
$this->assertContains('role:member', $data['_write']);
return [
'collectionId' => $data['id'],
'key' => $key
'collectionId' => $data['_id'],
];
}
@ -784,10 +754,10 @@ trait GraphQLBase
public function testCreateStringAttribute(array $data): void
{
$projectId = $this->getProject()['$id'];
$key = $data['key'];
$key = $this->getProject()['apiKey'];
$query = $this->getQuery(self::$CREATE_STRING_ATTRIBUTE);
$attributeAttrs = [
$stringAttrs = [
'collectionId' => $data['collectionId'],
'key' => 'name',
'size' => 256,
@ -796,7 +766,7 @@ trait GraphQLBase
$gqlPayload = [
'query' => $query,
'variables' => $attributeAttrs
'variables' => $stringAttrs
];
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', [
@ -806,9 +776,12 @@ trait GraphQLBase
'x-appwrite-key' => $key
], $gqlPayload);
$this->assertNull($attribute['body']['errors']);
$this->assertArrayNotHasKey('errors', $attribute['body']);
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databaseCreateStringAttribute']);
// Wait for attribute to be ready
sleep(2);
}
/**
@ -818,20 +791,20 @@ trait GraphQLBase
public function testCreateIntegerAttribute(array $data): void
{
$projectId = $this->getProject()['$id'];
$key = $data['key'];
$key = $this->getProject()['apiKey'];
$query = $this->getQuery(self::$CREATE_INTEGER_ATTRIBUTE);
$attributeAttrs = [
$intAttrs = [
'collectionId' => $data['collectionId'],
'key' => 'age',
'min' => 18,
'max' => 99,
'max' => 150,
'required' => true,
];
$gqlPayload = [
'query' => $query,
'variables' => $attributeAttrs
'variables' => $intAttrs
];
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', [
@ -841,9 +814,12 @@ trait GraphQLBase
'x-appwrite-key' => $key
], $gqlPayload);
$this->assertNull($attribute['body']['errors']);
$this->assertArrayNotHasKey('errors', $attribute['body']);
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databaseCreateIntegerAttribute']);
// Wait for attribute to be ready
sleep(2);
}
/**
@ -853,10 +829,10 @@ trait GraphQLBase
public function testCreateBooleanAttribute(array $data): void
{
$projectId = $this->getProject()['$id'];
$key = $data['key'];
$key = $this->getProject()['apiKey'];
$query = $this->getQuery(self::$CREATE_BOOLEAN_ATTRIBUTE);
$attributeAttrs = [
$booleanAttrs = [
'collectionId' => $data['collectionId'],
'key' => 'alive',
'required' => true,
@ -864,7 +840,7 @@ trait GraphQLBase
$gqlPayload = [
'query' => $query,
'variables' => $attributeAttrs
'variables' => $booleanAttrs
];
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', [
@ -874,9 +850,12 @@ trait GraphQLBase
'x-appwrite-key' => $key
], $gqlPayload);
$this->assertNull($attribute['body']['errors']);
$this->assertArrayNotHasKey('errors', $attribute['body']);
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databaseCreateBooleanAttribute']);
// Wait for attribute to be ready
sleep(2);
}
/**
@ -886,10 +865,10 @@ trait GraphQLBase
public function testCreateFloatAttribute(array $data): void
{
$projectId = $this->getProject()['$id'];
$key = $data['key'];
$key = $this->getProject()['apiKey'];
$query = $this->getQuery(self::$CREATE_FLOAT_ATTRIBUTE);
$attributeAttrs = [
$floatAttrs = [
'collectionId' => $data['collectionId'],
'key' => 'salary',
'min' => 1000.0,
@ -900,7 +879,7 @@ trait GraphQLBase
$gqlPayload = [
'query' => $query,
'variables' => $attributeAttrs
'variables' => $floatAttrs
];
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', [
@ -910,9 +889,12 @@ trait GraphQLBase
'x-appwrite-key' => $key
], $gqlPayload);
$this->assertNull($attribute['body']['errors']);
$this->assertArrayNotHasKey('errors', $attribute['body']);
$this->assertIsArray($attribute['body']['data']);
$this->assertIsArray($attribute['body']['data']['databaseCreateFloatAttribute']);
// Wait for attribute to be ready
sleep(2);
}
/**
@ -926,7 +908,7 @@ trait GraphQLBase
public function testCreateDocumentREST(array $data): void
{
$projectId = $this->getProject()['$id'];
$key = $data['key'];
$key = $this->getProject()['apiKey'];
$query = $this->getQuery(self::$CREATE_DOCUMENT_REST);
$documentAttrs = [
@ -951,7 +933,7 @@ trait GraphQLBase
'x-appwrite-key' => $key
], $gqlPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['databaseCreateDocument']);
}
@ -989,7 +971,7 @@ trait GraphQLBase
'x-appwrite-key' => $key
], $gqlPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['actorCreate']);
}

View file

@ -47,6 +47,7 @@ class GraphQLClientTest extends Scope
'password' => 'password',
]
];
$session1 = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
@ -115,9 +116,12 @@ class GraphQLClientTest extends Scope
/**
* @depends testCreateCollection
* @depends testCreateStringAttribute
* @depends testCreateIntegerAttribute
* @depends testCreateBooleanAttribute
* @depends testCreateAccounts
*/
public function testWildCardPermissions(array $data, array $accounts)
public function testWildCardPermissions(array $data, $str, $int, $bool, array $accounts)
{
$projectId = $this->getProject()['$id'];
@ -137,28 +141,27 @@ class GraphQLClientTest extends Scope
'read' => ['role:all'],
'write' => ['role:all'],
];
$graphQLPayload = [
'query' => $query,
'variables' => $docVariables
];
$document = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session1Cookie'],
], $graphQLPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['databaseCreateDocument']);
$doc = $document['body']['data']['databaseCreateDocument'];
$this->assertArrayHasKey('$id', $doc);
$this->assertEquals($data['collectionId'], $doc['$collection']);
$this->assertEquals('Robert', $doc['name']);
$this->assertEquals(100, $doc['age']);
$this->assertEquals($docVariables['read'], $doc['read']);
$this->assertEquals($docVariables['write'], $doc['write']);
$this->assertArrayHasKey('_id', $doc);
$this->assertEquals($data['collectionId'], $doc['_collection']);
$this->assertEquals($docVariables['read'], $doc['_read']);
$this->assertEquals($docVariables['write'], $doc['_write']);
/*
* Account 1 tries to access it
@ -166,7 +169,7 @@ class GraphQLClientTest extends Scope
$query = $this->getQuery(self::$GET_DOCUMENT);
$getDocumentVariables = [
'collectionId' => $data['collectionId'],
'documentId' => $doc['$id']
'documentId' => $doc['_id']
];
$graphQLPayload = [
'query' => $query,
@ -178,16 +181,16 @@ class GraphQLClientTest extends Scope
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session1Cookie'],
], $graphQLPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['databaseGetDocument']);
$doc = $document['body']['data']['databaseGetDocument'];
$this->assertArrayHasKey('$id', $doc);
$this->assertEquals($data['collectionId'], $doc['$collection']);
$this->assertArrayHasKey('_id', $doc);
$this->assertEquals($data['collectionId'], $doc['_collection']);
$this->assertEquals('Robert', $doc['name']);
$this->assertEquals(100, $doc['age']);
$this->assertEquals($docVariables['read'], $doc['read']);
$this->assertEquals($docVariables['read'], $doc['_read']);
$this->assertEquals($docVariables['write'], $doc['write']);
/*
@ -199,25 +202,28 @@ class GraphQLClientTest extends Scope
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session2Cookie'],
], $graphQLPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['databaseGetDocument']);
$doc = $document['body']['data']['databaseGetDocument'];
$this->assertArrayHasKey('$id', $doc);
$this->assertEquals($data['collectionId'], $doc['$collection']);
$this->assertArrayHasKey('_id', $doc);
$this->assertEquals($data['collectionId'], $doc['_collection']);
$this->assertEquals('Robert', $doc['name']);
$this->assertEquals(100, $doc['age']);
$this->assertEquals($docVariables['read'], $doc['read']);
$this->assertEquals($docVariables['read'], $doc['_read']);
$this->assertEquals($docVariables['write'], $doc['write']);
}
/**
* @depends testCreateCollection
* @depends testCreateStringAttribute
* @depends testCreateIntegerAttribute
* @depends testCreateBooleanAttribute
* @depends testCreateAccounts
* @throws \Exception
*/
public function testUserRole(array $data, array $accounts)
public function testUserRole(array $data, $str, $int, $bool, array $accounts)
{
$projectId = $this->getProject()['$id'];
@ -227,6 +233,7 @@ class GraphQLClientTest extends Scope
$query = $this->getQuery(self::$CREATE_DOCUMENT_REST);
$createDocumentVariables = [
'collectionId' => $data['collectionId'],
'documentId' => 'unique()',
'data' => [
'name' => 'Robert',
'age' => '100',
@ -247,17 +254,15 @@ class GraphQLClientTest extends Scope
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session1Cookie'],
], $graphQLPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['databaseCreateDocument']);
$doc = $document['body']['data']['databaseCreateDocument'];
$this->assertArrayHasKey('$id', $doc);
$this->assertEquals($data['collectionId'], $doc['$collection']);
$this->assertEquals($createDocumentVariables['data']['name'], $doc['name']);
$this->assertEquals($createDocumentVariables['data']['age'], $doc['age']);
$this->assertEquals($createDocumentVariables['read'], $doc['read']);
$this->assertEquals($createDocumentVariables['write'], $doc['write']);
$this->assertArrayHasKey('_id', $doc);
$this->assertEquals($data['collectionId'], $doc['_collection']);
$this->assertEquals($createDocumentVariables['read'], $doc['_read']);
$this->assertEquals($createDocumentVariables['write'], $doc['_write']);
/*
* Account 1 tries to access it
@ -265,7 +270,7 @@ class GraphQLClientTest extends Scope
$query = $this->getQuery(self::$GET_DOCUMENT);
$getDocumentVariables = [
'collectionId' => $data['collectionId'],
'documentId' => $doc['$id']
'documentId' => $doc['_id']
];
$graphQLPayload = [
'query' => $query,
@ -277,16 +282,16 @@ class GraphQLClientTest extends Scope
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session1Cookie'],
], $graphQLPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['databaseGetDocument']);
$doc = $document['body']['data']['databaseGetDocument'];
$this->assertArrayHasKey('$id', $doc);
$this->assertEquals($data['collectionId'], $doc['$collection']);
$this->assertArrayHasKey('_id', $doc);
$this->assertEquals($data['collectionId'], $doc['_collection']);
$this->assertEquals($createDocumentVariables['data']['name'], $doc['name']);
$this->assertEquals($createDocumentVariables['data']['age'], $doc['age']);
$this->assertEquals($createDocumentVariables['read'], $doc['read']);
$this->assertEquals($createDocumentVariables['read'], $doc['_read']);
$this->assertEquals($createDocumentVariables['write'], $doc['write']);
/*
@ -321,16 +326,14 @@ class GraphQLClientTest extends Scope
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session1Cookie'],
], $graphQLPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['databaseUpdateDocument']);
$doc = $document['body']['data']['database_updateDocument'];
$this->assertArrayHasKey('$id', $doc);
$this->assertEquals($data['collectionId'], $doc['$collection']);
$this->assertEquals($createDocumentVariables['data']['name'], $doc['name']);
$this->assertEquals($createDocumentVariables['data']['age'], $doc['age']);
$this->assertEquals($updateDocumentVariables['read'], $doc['read']);
$this->assertArrayHasKey('_id', $doc);
$this->assertEquals($data['collectionId'], $doc['_collection']);
$this->assertEquals($updateDocumentVariables['read'], $doc['_read']);
$this->assertEquals($updateDocumentVariables['write'], $doc['write']);
/*
@ -351,25 +354,26 @@ class GraphQLClientTest extends Scope
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session2Cookie'],
], $graphQLPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['databaseGetDocument']);
$doc = $document['body']['data']['databaseGetDocument'];
$this->assertArrayHasKey('$id', $doc);
$this->assertEquals($data['collectionId'], $doc['$collection']);
$this->assertEquals($createDocumentVariables['data']['name'], $doc['name']);
$this->assertEquals($createDocumentVariables['data']['age'], $doc['age']);
$this->assertEquals($updateDocumentVariables['read'], $doc['read']);
$this->assertArrayHasKey('_id', $doc);
$this->assertEquals($data['collectionId'], $doc['_collection']);
$this->assertEquals($updateDocumentVariables['read'], $doc['_read']);
$this->assertEquals($updateDocumentVariables['write'], $doc['write']);
}
/**
* @depends testCreateCollection
* @depends testCreateStringAttribute
* @depends testCreateIntegerAttribute
* @depends testCreateBooleanAttribute
* @depends testCreateAccounts
* @throws \Exception
*/
public function testTeamRole(array $data, array $accounts)
public function testTeamRole(array $data, $str, $int, $bool, array $accounts)
{
$projectId = $this->getProject()['$id'];
/**
@ -377,7 +381,8 @@ class GraphQLClientTest extends Scope
*/
$query = $this->getQuery(self::$CREATE_TEAM);
$createTeamVariables = [
'name' => 'Test Team'
'teamId' => 'unique()',
'name' => 'Test Team',
];
$graphQLPayload = [
'query' => $query,
@ -389,12 +394,12 @@ class GraphQLClientTest extends Scope
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session1Cookie'],
], $graphQLPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['teams_create']);
$this->assertIsArray($document['body']['data']['teamsCreate']);
$team = $document['body']['data']['teams_create'];
$this->assertArrayHasKey('id', $team);
$team = $document['body']['data']['teamsCreate'];
$this->assertArrayHasKey('_id', $team);
$this->assertEquals($createTeamVariables['name'], $team['name']);
/*
@ -407,8 +412,8 @@ class GraphQLClientTest extends Scope
'name' => 'Robert',
'age' => 100
],
'read' => ["team:{$team['id']}"],
'write' => ["team:{$team['id']}"],
'read' => ["team:{$team['_id']}"],
'write' => ["team:{$team['_id']}"],
];
$graphQLPayload = [
'query' => $query,
@ -420,16 +425,14 @@ class GraphQLClientTest extends Scope
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session1Cookie'],
], $graphQLPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['databaseCreateDocument']);
$doc = $document['body']['data']['databaseCreateDocument'];
$this->assertArrayHasKey('$id', $doc);
$this->assertEquals($data['collectionId'], $doc['$collection']);
$this->assertEquals($createDocumentVariables['data']['name'], $doc['name']);
$this->assertEquals($createDocumentVariables['data']['age'], $doc['age']);
$this->assertEquals($createDocumentVariables['read'], $doc['read']);
$this->assertArrayHasKey('_id', $doc);
$this->assertEquals($data['collectionId'], $doc['_collection']);
$this->assertEquals($createDocumentVariables['read'], $doc['_read']);
$this->assertEquals($createDocumentVariables['write'], $doc['write']);
/*
@ -450,16 +453,14 @@ class GraphQLClientTest extends Scope
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session1Cookie'],
], $graphQLPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['databaseGetDocument']);
$doc = $document['body']['data']['databaseGetDocument'];
$this->assertArrayHasKey('$id', $doc);
$this->assertEquals($data['collectionId'], $doc['$collection']);
$this->assertEquals($createDocumentVariables['data']['name'], $doc['name']);
$this->assertEquals($createDocumentVariables['data']['age'], $doc['age']);
$this->assertEquals($createDocumentVariables['read'], $doc['read']);
$this->assertArrayHasKey('_id', $doc);
$this->assertEquals($data['collectionId'], $doc['_collection']);
$this->assertEquals($createDocumentVariables['read'], $doc['_read']);
$this->assertEquals($createDocumentVariables['write'], $doc['write']);
/*

View file

@ -16,6 +16,9 @@ class GraphQLServerTest extends Scope
/**
* @depends testCreateCollection
* @depends testCreateStringAttribute
* @depends testCreateIntegerAttribute
* @depends testCreateBooleanAttribute
*/
public function testDocumentCreate(array $data)
{
@ -24,10 +27,11 @@ class GraphQLServerTest extends Scope
$query = $this->getQuery(self::$CREATE_DOCUMENT_REST);
$variables = [
'documentId' => 'unique()',
'collectionId' => $data['collectionId'],
'data' => [
'name' => 'Robert',
'ago' => 100,
'age' => 100,
'alive' => true,
],
'read' => ['role:all'],
@ -58,17 +62,16 @@ class GraphQLServerTest extends Scope
'x-appwrite-key' => $key
]), $graphQLPayload);
$this->assertNull($document['body']['errors']);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
$this->assertIsArray($document['body']['data']['databaseCreateDocument']);
$doc = $document['body']['data']['databaseCreateDocument'];
$this->assertArrayHasKey('$id', $doc);
$this->assertEquals($data['collectionId'], $doc['$collection']);
$this->assertEquals($variables['data']['name'], $doc['name']);
$this->assertEquals($variables['data']['age'], $doc['age']);
$this->assertEquals($variables['read'], $doc['read']);
$this->assertEquals($variables['write'], $doc['write']);
$this->assertArrayHasKey('_id', $doc);
$this->assertEquals($data['collectionId'], $doc['_collection']);
$this->assertEquals($variables['read'], $doc['_read']);
$this->assertEquals($variables['write'], $doc['_write']);
}
/**
@ -80,7 +83,6 @@ class GraphQLServerTest extends Scope
* Try to create a user without the required scope
*/
$projectId = $this->getProject()['$id'];
$key = '';
$query = $this->getQuery(self::$CREATE_USER);
$variables = [
@ -98,7 +100,6 @@ class GraphQLServerTest extends Scope
$user = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-key' => $key
], $graphQLPayload);
$errorMessage = 'User (role: guest) missing scope (users.write)';
@ -239,13 +240,11 @@ class GraphQLServerTest extends Scope
'x-appwrite-key' => $key
], $graphQLPayload);
//\var_dump($countries);
$errorMessage = 'app.${projectId}@service.localhost (role: application) missing scope (locale.read)';
$this->assertEquals( 401, $countries['headers']['status-code']);
$errorMessage = 'app.' . $projectId . '@service.localhost (role: application) missing scope (locale.read)';
$this->assertEquals(401, $countries['headers']['status-code']);
$this->assertEquals($countries['body']['errors'][0]['message'], $errorMessage);
$this->assertIsArray($countries['body']['data']);
$this->assertNull($countries['body']['data']['locale_getCountries']);
$this->assertNull($countries['body']['data']['localeGetCountries']);
}
}