From a193f96b8d0b3849be51b8af3bed3cf1a65663f3 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 7 Jul 2022 17:50:49 +1200 Subject: [PATCH] Functions tests fixes --- tests/e2e/Services/GraphQL/GraphQLBase.php | 17 +- .../Services/GraphQL/GraphQLClientTest.php | 438 ------------------ .../GraphQL/GraphQLDatabaseClientTest.php | 2 - .../GraphQL/GraphQLFunctionsClientTest.php | 31 +- .../GraphQL/GraphQLFunctionsServerTest.php | 138 ++++-- .../Services/GraphQL/GraphQLServerTest.php | 60 --- 6 files changed, 110 insertions(+), 576 deletions(-) delete mode 100644 tests/e2e/Services/GraphQL/GraphQLClientTest.php delete mode 100644 tests/e2e/Services/GraphQL/GraphQLServerTest.php diff --git a/tests/e2e/Services/GraphQL/GraphQLBase.php b/tests/e2e/Services/GraphQL/GraphQLBase.php index ba3bfd6d5d..6ed8a1a362 100644 --- a/tests/e2e/Services/GraphQL/GraphQLBase.php +++ b/tests/e2e/Services/GraphQL/GraphQLBase.php @@ -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 } }'; diff --git a/tests/e2e/Services/GraphQL/GraphQLClientTest.php b/tests/e2e/Services/GraphQL/GraphQLClientTest.php deleted file mode 100644 index 3a2d9ed8c8..0000000000 --- a/tests/e2e/Services/GraphQL/GraphQLClientTest.php +++ /dev/null @@ -1,438 +0,0 @@ -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']); -// -// } -} diff --git a/tests/e2e/Services/GraphQL/GraphQLDatabaseClientTest.php b/tests/e2e/Services/GraphQL/GraphQLDatabaseClientTest.php index 3a37948f2a..f56c10228a 100644 --- a/tests/e2e/Services/GraphQL/GraphQLDatabaseClientTest.php +++ b/tests/e2e/Services/GraphQL/GraphQLDatabaseClientTest.php @@ -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']); diff --git a/tests/e2e/Services/GraphQL/GraphQLFunctionsClientTest.php b/tests/e2e/Services/GraphQL/GraphQLFunctionsClientTest.php index e1c106a394..c420730fc0 100644 --- a/tests/e2e/Services/GraphQL/GraphQLFunctionsClientTest.php +++ b/tests/e2e/Services/GraphQL/GraphQLFunctionsClientTest.php @@ -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']; } /** diff --git a/tests/e2e/Services/GraphQL/GraphQLFunctionsServerTest.php b/tests/e2e/Services/GraphQL/GraphQLFunctionsServerTest.php index e181ac72b3..18588b4093 100644 --- a/tests/e2e/Services/GraphQL/GraphQLFunctionsServerTest.php +++ b/tests/e2e/Services/GraphQL/GraphQLFunctionsServerTest.php @@ -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']); - } } diff --git a/tests/e2e/Services/GraphQL/GraphQLServerTest.php b/tests/e2e/Services/GraphQL/GraphQLServerTest.php deleted file mode 100644 index 19f1bd274e..0000000000 --- a/tests/e2e/Services/GraphQL/GraphQLServerTest.php +++ /dev/null @@ -1,60 +0,0 @@ -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']); -// } -}