From f0edf47f4fb74fd421d6373d43a246deb11da8c6 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 16 Jan 2020 16:06:28 +0200 Subject: [PATCH] Added e2e tests to teams service --- tests/e2e/Scopes/Scope.php | 2 + tests/e2e/Services/Teams/TeamsBase.php | 264 ++++++++++++++++++ tests/e2e/Services/Teams/TeamsBaseClient.php | 37 +++ tests/e2e/Services/Teams/TeamsBaseServer.php | 33 +++ .../Services/Teams/TeamsConsoleClientTest.php | 15 + .../Services/Teams/TeamsCustomClientTest.php | 15 + .../Services/Teams/TeamsCustomServerTest.php | 16 ++ 7 files changed, 382 insertions(+) create mode 100644 tests/e2e/Services/Teams/TeamsBase.php create mode 100644 tests/e2e/Services/Teams/TeamsBaseClient.php create mode 100644 tests/e2e/Services/Teams/TeamsBaseServer.php create mode 100644 tests/e2e/Services/Teams/TeamsConsoleClientTest.php create mode 100644 tests/e2e/Services/Teams/TeamsCustomClientTest.php create mode 100644 tests/e2e/Services/Teams/TeamsCustomServerTest.php diff --git a/tests/e2e/Scopes/Scope.php b/tests/e2e/Scopes/Scope.php index d9b6881cd1..d31e5ed490 100644 --- a/tests/e2e/Scopes/Scope.php +++ b/tests/e2e/Scopes/Scope.php @@ -97,6 +97,7 @@ abstract class Scope extends TestCase self::$root = [ '$uid' => $root['body']['$uid'], 'name' => $root['body']['name'], + 'email' => $root['body']['email'], 'session' => $session, ]; @@ -147,6 +148,7 @@ abstract class Scope extends TestCase self::$user[$this->getProject()['$uid']] = [ '$uid' => $user['body']['$uid'], 'name' => $user['body']['name'], + 'email' => $user['body']['email'], 'session' => $session, ]; diff --git a/tests/e2e/Services/Teams/TeamsBase.php b/tests/e2e/Services/Teams/TeamsBase.php new file mode 100644 index 0000000000..f85c36d21c --- /dev/null +++ b/tests/e2e/Services/Teams/TeamsBase.php @@ -0,0 +1,264 @@ +client->call(Client::METHOD_POST, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + 'name' => 'Arsenal' + ]); + + $this->assertEquals(201, $response1['headers']['status-code']); + $this->assertNotEmpty($response1['body']['$uid']); + $this->assertEquals('Arsenal', $response1['body']['name']); + $this->assertGreaterThan(-1, $response1['body']['sum']); + $this->assertIsInt($response1['body']['sum']); + $this->assertIsInt($response1['body']['dateCreated']); + + $teamUid = $response1['body']['$uid']; + + $response2 = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + 'name' => 'Manchester United' + ]); + + $this->assertEquals(201, $response2['headers']['status-code']); + $this->assertNotEmpty($response2['body']['$uid']); + $this->assertEquals('Manchester United', $response2['body']['name']); + $this->assertGreaterThan(-1, $response2['body']['sum']); + $this->assertIsInt($response2['body']['sum']); + $this->assertIsInt($response2['body']['dateCreated']); + + $response3 = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + 'name' => 'Newcastle' + ]); + + $this->assertEquals(201, $response3['headers']['status-code']); + $this->assertNotEmpty($response3['body']['$uid']); + $this->assertEquals('Newcastle', $response3['body']['name']); + $this->assertGreaterThan(-1, $response3['body']['sum']); + $this->assertIsInt($response3['body']['sum']); + $this->assertIsInt($response3['body']['dateCreated']); + + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + return ['teamUid' => $teamUid]; + } + + /** + * @depends testCreateTeam + */ + public function testGetTeam($data):array + { + $uid = (isset($data['teamUid'])) ? $data['teamUid'] : ''; + + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/teams/'.$uid, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$uid']); + $this->assertEquals('Arsenal', $response['body']['name']); + $this->assertGreaterThan(-1, $response['body']['sum']); + $this->assertIsInt($response['body']['sum']); + $this->assertIsInt($response['body']['dateCreated']); + + /** + * Test for FAILURE + */ + + return []; + } + + /** + * @depends testCreateTeam + */ + public function testListTeams($data):array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertGreaterThan(0, $response['body']['sum']); + $this->assertIsInt($response['body']['sum']); + $this->assertCount(3, $response['body']['teams']); + + $response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + 'limit' => 2, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertGreaterThan(0, $response['body']['sum']); + $this->assertIsInt($response['body']['sum']); + $this->assertCount(2, $response['body']['teams']); + + $response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + 'offset' => 1, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertGreaterThan(0, $response['body']['sum']); + $this->assertIsInt($response['body']['sum']); + $this->assertCount(2, $response['body']['teams']); + + $response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + 'search' => 'Manchester', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertGreaterThan(0, $response['body']['sum']); + $this->assertIsInt($response['body']['sum']); + $this->assertCount(1, $response['body']['teams']); + $this->assertEquals('Manchester United', $response['body']['teams'][0]['name']); + + $response = $this->client->call(Client::METHOD_GET, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + 'search' => 'United', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertGreaterThan(0, $response['body']['sum']); + $this->assertIsInt($response['body']['sum']); + $this->assertCount(1, $response['body']['teams']); + $this->assertEquals('Manchester United', $response['body']['teams'][0]['name']); + + /** + * Test for FAILURE + */ + + return []; + } + + public function testUpdateTeam():array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + 'name' => 'Demo' + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$uid']); + $this->assertEquals('Demo', $response['body']['name']); + $this->assertGreaterThan(-1, $response['body']['sum']); + $this->assertIsInt($response['body']['sum']); + $this->assertIsInt($response['body']['dateCreated']); + + $response = $this->client->call(Client::METHOD_PUT, '/teams/'.$response['body']['$uid'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + 'name' => 'Demo New' + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$uid']); + $this->assertEquals('Demo New', $response['body']['name']); + $this->assertGreaterThan(-1, $response['body']['sum']); + $this->assertIsInt($response['body']['sum']); + $this->assertIsInt($response['body']['dateCreated']); + + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_PUT, '/teams/'.$response['body']['$uid'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + return []; + } + + public function testDeleteTeam():array + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders()), [ + 'name' => 'Demo' + ]); + + $teamUid = $response['body']['$uid']; + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$uid']); + $this->assertEquals('Demo', $response['body']['name']); + $this->assertGreaterThan(-1, $response['body']['sum']); + $this->assertIsInt($response['body']['sum']); + $this->assertIsInt($response['body']['dateCreated']); + + $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); + + $this->assertEquals(204, $response['headers']['status-code']); + $this->assertEmpty($response['body']); + + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); + + $this->assertEquals(404, $response['headers']['status-code']); + + return []; + } +} \ No newline at end of file diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php new file mode 100644 index 0000000000..2f741ffaa8 --- /dev/null +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -0,0 +1,37 @@ +client->call(Client::METHOD_GET, '/teams/'.$uid.'/members', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body'][0]['$uid']); + $this->assertEquals($this->getUser()['$uid'], $response['body'][0]['$uid']); + $this->assertEquals($this->getUser()['name'], $response['body'][0]['name']); + $this->assertEquals($this->getUser()['email'], $response['body'][0]['email']); + $this->assertEquals('owner', $response['body'][0]['roles'][0]); + + /** + * Test for FAILURE + */ + + return []; + } +} \ No newline at end of file diff --git a/tests/e2e/Services/Teams/TeamsBaseServer.php b/tests/e2e/Services/Teams/TeamsBaseServer.php new file mode 100644 index 0000000000..98af82647b --- /dev/null +++ b/tests/e2e/Services/Teams/TeamsBaseServer.php @@ -0,0 +1,33 @@ +client->call(Client::METHOD_GET, '/teams/'.$uid.'/members', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$uid'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(0, $response['body']); + + /** + * Test for FAILURE + */ + + return []; + } +} \ No newline at end of file diff --git a/tests/e2e/Services/Teams/TeamsConsoleClientTest.php b/tests/e2e/Services/Teams/TeamsConsoleClientTest.php new file mode 100644 index 0000000000..7ced83c4e4 --- /dev/null +++ b/tests/e2e/Services/Teams/TeamsConsoleClientTest.php @@ -0,0 +1,15 @@ +