Functions tests fixes

This commit is contained in:
Jake Barnby
2022-07-07 17:50:49 +12:00
parent 380dbb32e9
commit a193f96b8d
6 changed files with 110 additions and 576 deletions
+6 -11
View File
@@ -1060,12 +1060,9 @@ trait GraphQLBase
case self::$GET_DEPLOYMENT:
return 'query getDeployment($functionId: String!, $deploymentId: String!) {
functionsGetDeployment(functionId: $functionId, deploymentId: $deploymentId) {
total
deployments {
_id
buildStdout
buildStderr
}
_id
buildStdout
buildStderr
}
}';
case self::$CREATE_FUNCTION:
@@ -1103,6 +1100,7 @@ trait GraphQLBase
return 'mutation createDeployment($functionId: String!, $entrypoint: String!, $code: InputFile!, $activate: Boolean!) {
functionsCreateDeployment(functionId: $functionId, entrypoint: $entrypoint, code: $code, activate: $activate) {
_id
buildId
entrypoint
size
status
@@ -1119,7 +1117,6 @@ trait GraphQLBase
functionsGetExecution(functionId: $functionId, executionId: $executionId) {
_id
status
stdout
stderr
}
}';
@@ -1135,12 +1132,10 @@ trait GraphQLBase
}
}';
case self::$CREATE_EXECUTION:
return 'mutation createExecution($functionId: String!) {
functionsCreateExecution(functionId: $functionId) {
return 'mutation createExecution($functionId: String!, $data: String, $async: Boolean) {
functionsCreateExecution(functionId: $functionId, data: $data, async: $async) {
_id
status
response
stdout
stderr
}
}';
@@ -1,438 +0,0 @@
<?php
namespace Tests\E2E\Services\GraphQL;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideClient;
class GraphQLClientTest extends Scope
{
use ProjectCustom;
use SideClient;
use GraphQLBase;
// /**
// * @depends testCreateCollection
// * @depends testCreateStringAttribute
// * @depends testCreateIntegerAttribute
// * @depends testCreateBooleanAttribute
// * @depends testCreateAccounts
// */
// public function testWildCardPermissions(array $data, $str, $int, $bool, array $accounts)
// {
// $projectId = $this->getProject()['$id'];
//
// /*
// * Account 1 Creates a document with wildcard permissions
// */
// $query = $this->getQuery(self::$CREATE_DOCUMENT_REST);
//
// $docVariables = [
// 'documentId' => 'unique()',
// 'collectionId' => $data['collectionId'],
// 'data' => [
// 'name' => 'Robert',
// 'age' => 100,
// 'alive' => true,
// ],
// '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->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($docVariables['read'], $doc['_read']);
// $this->assertEquals($docVariables['write'], $doc['_write']);
//
// /*
// * Account 1 tries to access it
// */
// $query = $this->getQuery(self::$GET_DOCUMENT);
// $getDocumentVariables = [
// 'collectionId' => $data['collectionId'],
// 'documentId' => $doc['_id']
// ];
// $graphQLPayload = [
// 'query' => $query,
// 'variables' => $getDocumentVariables
// ];
// $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->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('Robert', $doc['name']);
// $this->assertEquals(100, $doc['age']);
// $this->assertEquals($docVariables['read'], $doc['_read']);
// $this->assertEquals($docVariables['write'], $doc['write']);
//
// /*
// * Account 2 tries to access it
// */
// $document = $this->client->call(Client::METHOD_POST, '/graphql', [
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $projectId,
// 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session2Cookie'],
// ], $graphQLPayload);
//
// $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('Robert', $doc['name']);
// $this->assertEquals(100, $doc['age']);
// $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, $str, $int, $bool, array $accounts)
// {
// $projectId = $this->getProject()['$id'];
//
// /*
// * Account 1 Creates a document with user permissions
// */
// $query = $this->getQuery(self::$CREATE_DOCUMENT_REST);
// $createDocumentVariables = [
// 'collectionId' => $data['collectionId'],
// 'documentId' => 'unique()',
// 'data' => [
// 'name' => 'Robert',
// 'age' => '100',
// 'alive' => true,
// ],
// 'read' => ["user:{$accounts['user1Id']}"],
// 'write' => ["user:{$accounts['user1Id']}"],
// ];
//
// $graphQLPayload = [
// 'query' => $query,
// 'variables' => $createDocumentVariables
// ];
//
// $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->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['read'], $doc['_read']);
// $this->assertEquals($createDocumentVariables['write'], $doc['_write']);
//
// /*
// * Account 1 tries to access it
// */
// $query = $this->getQuery(self::$GET_DOCUMENT);
// $getDocumentVariables = [
// 'collectionId' => $data['collectionId'],
// 'documentId' => $doc['_id']
// ];
// $graphQLPayload = [
// 'query' => $query,
// 'variables' => $getDocumentVariables
// ];
// $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->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->assertEquals($createDocumentVariables['write'], $doc['write']);
//
// /*
// * Account 2 tries to access it
// */
// $document = $this->client->call(Client::METHOD_POST, '/graphql', [
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $projectId,
// 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session2Cookie'],
// ], $graphQLPayload);
//
// $this->assertEquals('No document found', $document['body']['errors'][0]['message']);
//
// /*
// * Account 1 Updates the document permissions
// */
// $query = $this->getQuery(self::$UPDATE_DOCUMENT);
// $updateDocumentVariables = [
// 'collectionId' => $data['collectionId'],
// 'documentId' => $doc['$id'],
// 'data' => [],
// 'read' => ['role:all'],
// 'write' => ['role:all']
// ];
// $graphQLPayload = [
// 'query' => $query,
// 'variables' => $updateDocumentVariables
// ];
// $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->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($updateDocumentVariables['read'], $doc['_read']);
// $this->assertEquals($updateDocumentVariables['write'], $doc['write']);
//
// /*
// * Account 2 tries to access it
// */
// $query = $this->getQuery(self::$GET_DOCUMENT);
// $getDocumentVariables = [
// 'collectionId' => $data['collectionId'],
// 'documentId' => $doc['$id']
// ];
// $graphQLPayload = [
// 'query' => $query,
// 'variables' => $getDocumentVariables
// ];
// $document = $this->client->call(Client::METHOD_POST, '/graphql', [
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $projectId,
// 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $accounts['session2Cookie'],
// ], $graphQLPayload);
//
// $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($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, $str, $int, $bool, array $accounts)
// {
// $projectId = $this->getProject()['$id'];
// /**
// * Account 1 creates a team
// */
// $query = $this->getQuery(self::$CREATE_TEAM);
// $createTeamVariables = [
// 'teamId' => 'unique()',
// 'name' => 'Test Team',
// ];
// $graphQLPayload = [
// 'query' => $query,
// 'variables' => $createTeamVariables
// ];
// $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->assertArrayNotHasKey('errors', $document['body']);
// $this->assertIsArray($document['body']['data']);
// $this->assertIsArray($document['body']['data']['teamsCreate']);
//
// $team = $document['body']['data']['teamsCreate'];
// $this->assertArrayHasKey('_id', $team);
// $this->assertEquals($createTeamVariables['name'], $team['name']);
//
// /*
// * Account 1 Creates a document with team permissions
// */
// $query = $this->getQuery(self::$CREATE_DOCUMENT_REST);
// $createDocumentVariables = [
// 'collectionId' => $data['collectionId'],
// 'data' => [
// 'name' => 'Robert',
// 'age' => 100
// ],
// 'read' => ["team:{$team['_id']}"],
// 'write' => ["team:{$team['_id']}"],
// ];
// $graphQLPayload = [
// 'query' => $query,
// 'variables' => $createDocumentVariables
// ];
// $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->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['read'], $doc['_read']);
// $this->assertEquals($createDocumentVariables['write'], $doc['write']);
//
// /*
// * Account 1 tries to access it
// */
// $query = $this->getQuery(self::$GET_DOCUMENT);
// $getDocumentVariables = [
// 'collectionId' => $data['collectionId'],
// 'documentId' => $doc['$id']
// ];
// $graphQLPayload = [
// 'query' => $query,
// 'variables' => $getDocumentVariables
// ];
// $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->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['read'], $doc['_read']);
// $this->assertEquals($createDocumentVariables['write'], $doc['write']);
//
// /*
// * Create a membership
// */
// $email = \rand() . 'friend@localhost.test';
// $query = $this->getQuery(self::$CREATE_TEAM_MEMBERSHIP);
// $createMembershipVariable = [
// 'teamId' => $team['id'],
// 'name' => 'Friend User',
// 'email' => $email,
// 'roles' => ['owner'],
// 'url' => 'http://localhost:5000/join-us#title'
// ];
// $graphQLPayload = [
// 'query' => $query,
// 'variables' => $createMembershipVariable
// ];
// $membership = $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($membership['body']['errors']);
// $this->assertIsArray($membership['body']['data']);
// $this->assertIsArray($membership['body']['data']['teamsCreateMembership']);
//
// $membership = $membership['body']['data']['teamsCreateMembership'];
// $this->assertNotEmpty($membership['id']);
// $this->assertNotEmpty($membership['userId']);
// $this->assertNotEmpty($membership['teamId']);
// $this->assertCount(1, $membership['roles']);
// $this->assertIsInt($membership['joined']);
// $this->assertEquals(false, $membership['confirm']);
//
// $lastEmail = $this->getLastEmail();
//
// $this->assertEquals($email, $lastEmail['to'][0]['address']);
// $this->assertEquals('Friend User', $lastEmail['to'][0]['name']);
// $this->assertEquals('Invitation to ' . $createTeamVariables['name'] . ' Team at ' . $this->getProject()['name'], $lastEmail['subject']);
//
// $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
// $inviteUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?inviteId=', 0) + 10, 13);
// $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13);
//
// /** Update membership status */
// $query = $this->getQuery(self::$UPDATE_TEAM_MEMBERSHIP_STATUS);
// $updateMembershipStatus = [
// 'teamId' => $team['id'],
// 'inviteId' => $inviteUid,
// 'userId' => $userUid,
// 'secret' => $secret,
// ];
// $graphQLPayload = [
// 'query' => $query,
// 'variables' => $updateMembershipStatus
// ];
// $updatedMembership = $this->client->call(Client::METHOD_POST, '/graphql', [
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $projectId,
// ], $graphQLPayload);
//
// $this->assertNull($updatedMembership['body']['errors']);
// $this->assertIsArray($updatedMembership['body']['data']);
// $this->assertIsArray($updatedMembership['body']['data']['teamsUpdateMembershipStatus']);
//
// $updatedMembership = $updatedMembership['body']['data']['teamsUpdateMembershipStatus'];
// $this->assertNotEmpty($membership['id'], $updatedMembership['id']);
// $this->assertEquals($membership['userId'], $updatedMembership['userId']);
// $this->assertEquals($membership['teamId'], $updatedMembership['teamId']);
// $this->assertCount(1, $updatedMembership['roles']);
// $this->assertIsInt($updatedMembership['joined']);
// $this->assertEquals(true, $updatedMembership['confirm']);
//
// }
}
@@ -168,8 +168,6 @@ class GraphQLDatabaseClientTest extends Scope
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
\var_dump($document);
$this->assertArrayNotHasKey('errors', $document['body']);
$this->assertIsArray($document['body']['data']);
@@ -56,27 +56,30 @@ class GraphQLFunctionsClientTest extends Scope
$query = $this->getQuery(self::$CREATE_DEPLOYMENT);
$code = realpath(__DIR__ . '/../../../resources/functions') . "/ruby/code.tar.gz";
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'entrypoint' => 'main.rb',
'code' => new CURLFile($code, 'application/x-gzip', \basename($code)),
'activate' => true,
]
'operations' => \json_encode([
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'entrypoint' => 'main.rb',
'activate' => true,
'code' => null,
]
]),
'map' => \json_encode([
'code' => ["variables.code"]
]),
'code' => new CURLFile($code, 'application/gzip', 'code.tar.gz'),
];
$deployment = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json',
$deployment = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $projectId,
'x-appwrite-key' => $this->getProject()['apiKey'],
], $gqlPayload);
], $this->getHeaders()), $gqlPayload);
$this->assertIsArray($deployment['body']['data']);
$this->assertArrayNotHasKey('errors', $deployment['body']);
$deployment = $deployment['body']['data']['functionsCreateDeployment'];
$this->assertEquals('actor.json', $deployment['deploymentId']);
return $deployment;
return $deployment['body']['data']['functionsCreateDeployment'];
}
/**
@@ -56,39 +56,42 @@ class GraphQLFunctionsServerTest extends Scope
$query = $this->getQuery(self::$CREATE_DEPLOYMENT);
$code = realpath(__DIR__ . '/../../../resources/functions') . "/ruby/code.tar.gz";
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'entrypoint' => 'main.rb',
'code' => new CURLFile($code, 'application/x-gzip', \basename($code)),
'activate' => true,
]
'operations' => \json_encode([
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'entrypoint' => 'main.rb',
'activate' => true,
'code' => null,
]
]),
'map' => \json_encode([
'code' => ["variables.code"]
]),
'code' => new CURLFile($code, 'application/gzip', 'code.tar.gz'),
];
$deployment = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
\var_dump($deployment);
$this->assertIsArray($deployment['body']['data']);
$this->assertArrayNotHasKey('errors', $deployment['body']);
$deployment = $deployment['body']['data']['functionsCreateDeployment'];
$this->assertEquals('actor.json', $deployment['deploymentId']);
return $deployment;
sleep(10);
return $deployment['body']['data']['functionsCreateDeployment'];
}
/**
* * @depends testCreateFunction
* @depends testCreateDeployment
* @param $function
* @param $deployment
* @return array
* @throws \Exception
*/
public function testCreateExecution($function, $deployment): array
public function testCreateExecution($function): array
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_EXECUTION);
@@ -106,30 +109,30 @@ class GraphQLFunctionsServerTest extends Scope
$this->assertIsArray($execution['body']['data']);
$this->assertArrayNotHasKey('errors', $execution['body']);
$execution = $execution['body']['data']['functionsCreateExecution'];
$this->assertEquals('actor.json', $execution['executionId']);
return $execution;
return $execution['body']['data']['functionsCreateExecution'];
}
/**
* @depends testCreateFunction
* @depends testCreateDeployment
* @depends testCreateExecution
* @depends testGetDeployment
* @param $function
* @param $deployment
* @param $execution
* @return array
* @throws \Exception
*/
public function testCreateRetryBuild($function): array
public function testCreateRetryBuild($function, $deployment): array
{
\var_dump($deployment);
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$RETRY_BUILD);
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'deploymentId' => $deployment['_id'],
'buildId' => $deployment['buildId'],
]
];
@@ -138,6 +141,8 @@ class GraphQLFunctionsServerTest extends Scope
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
\var_dump($retryBuild);
$this->assertIsArray($retryBuild['body']['data']);
$this->assertArrayNotHasKey('errors', $retryBuild['body']);
$retryBuild = $retryBuild['body']['data']['functionsRetryBuild'];
@@ -248,6 +253,38 @@ class GraphQLFunctionsServerTest extends Scope
return $deployments;
}
/**
* @depends testCreateFunction
* @depends testCreateDeployment
* @param $function
* @return array
* @throws \Exception
*/
public function testGetDeployment($function, $deployment)
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_DEPLOYMENT);
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'deploymentId' => $deployment['_id'],
]
];
$deployment = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertIsArray($deployment['body']['data']);
$this->assertArrayNotHasKey('errors', $deployment['body']);
$deployment = $deployment['body']['data']['functionsGetDeployment'];
$this->assertIsArray($deployment);
return $deployment;
}
/**
* @depends testCreateFunction
* @param $function
@@ -349,8 +386,35 @@ class GraphQLFunctionsServerTest extends Scope
/**
* @depends testCreateFunction
* @depends testCreateDeployment
* @param $function
* @param $deployment
* @throws \Exception
*/
public function testDeleteDeployment($function, $deployment): void
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$DELETE_DEPLOYMENT);
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'deploymentId' => $deployment['_id'],
]
];
$response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertEquals(200, $response['headers']['status-code']);
}
/**
* @depends testCreateFunction
* @depends testDeleteDeployment
* @param $function
* @return array
* @throws \Exception
*/
public function testDeleteFunction($function): void
@@ -371,32 +435,4 @@ class GraphQLFunctionsServerTest extends Scope
$this->assertEquals(200, $response['headers']['status-code']);
}
/**
* @depends testCreateFunction
* @depends testCreateDeployment
* @param $function
* @param $deployment
* @return array
* @throws \Exception
*/
public function testDeleteDeployment($function, $deployment): void
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$DELETE_DEPLOYMENT);
$gqlPayload = [
'query' => $query,
'variables' => [
'functionId' => $function['_id'],
'deploymentId' => $deployment['_id'],
]
];
$response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertEquals(204, $response['headers']['status-code']);
}
}
@@ -1,60 +0,0 @@
<?php
namespace Tests\E2E\Services\GraphQL;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideServer;
class GraphQLServerTest extends Scope
{
use ProjectCustom;
use SideServer;
use GraphQLBase;
//
// public function testScopeBasedAuth()
// {
// $key = $this->getNewKey(['locale.read']);
// $projectId = $this->getProject()['$id'];
//
// /**
// * Check that countries can be fetched
// */
// $query = $this->getQuery(self::$LIST_COUNTRIES);
// $variables = [];
// $graphQLPayload = [
// 'query' => $query,
// 'variables' => $variables
// ];
// $countries = $this->client->call(Client::METHOD_POST, '/graphql', [
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $projectId,
// 'x-appwrite-key' => $key
// ], $graphQLPayload);
//
// $this->assertIsArray($countries['body']['data']);
// $this->assertIsArray($countries['body']['data']['localeGetCountries']);
//
// $data = $countries['body']['data']['localeGetCountries'];
// $this->assertEquals(194, count($data['countries']));
// $this->assertEquals(194, $data['total']);
//
//
// /**
// * Create a key without any scopes
// */
// $key = $this->getNewKey([]);
// $countries = $this->client->call(Client::METHOD_POST, '/graphql', [
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $projectId,
// 'x-appwrite-key' => $key
// ], $graphQLPayload);
//
// $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']['localeGetCountries']);
// }
}