From 6836e3c91db4b51707fd116417f929b75998798b Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 11 May 2021 23:25:38 +0530 Subject: [PATCH 1/7] feat: move membership deletion to deletes worker --- app/controllers/api/teams.php | 25 +- app/workers/deletes.php | 15 + tests/e2e/Services/Teams/TeamsBaseClient.php | 469 +++++++++++-------- 3 files changed, 290 insertions(+), 219 deletions(-) diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 62836ea428..96d4d89822 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -212,7 +212,8 @@ App::delete('/v1/teams/:teamId') ->inject('response') ->inject('projectDB') ->inject('events') - ->action(function ($teamId, $response, $projectDB, $events) { + ->inject('deletes') + ->action(function ($teamId, $response, $projectDB, $events, $deletes) { /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $events */ @@ -223,25 +224,17 @@ App::delete('/v1/teams/:teamId') throw new Exception('Team not found', 404); } - $memberships = $projectDB->getCollection([ - 'limit' => 2000, // TODO add members limit - 'offset' => 0, - 'filters' => [ - '$collection='.Database::SYSTEM_COLLECTION_MEMBERSHIPS, - 'teamId='.$teamId, - ], - ]); - - foreach ($memberships as $member) { - if (!$projectDB->deleteDocument($member->getId())) { - throw new Exception('Failed to remove membership for team from DB', 500); - } - } - if (!$projectDB->deleteDocument($teamId)) { throw new Exception('Failed to remove team from DB', 500); } + var_dump("Deleting team". $teamId); + + $deletes + ->setParam('type', DELETE_TYPE_DOCUMENT) + ->setParam('document', $team) + ; + $events ->setParam('eventData', $response->output($team, Response::MODEL_TEAM)) ; diff --git a/app/workers/deletes.php b/app/workers/deletes.php index cda60b78e5..b384da5f75 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -5,6 +5,7 @@ use Appwrite\Database\Adapter\MySQL as MySQLAdapter; use Appwrite\Database\Adapter\Redis as RedisAdapter; use Appwrite\Database\Document; use Appwrite\Database\Validator\Authorization; +use Swoole\FastCGI\Record\Data; use Utopia\Storage\Device\Local; use Utopia\Abuse\Abuse; use Utopia\Abuse\Adapters\TimeLimit; @@ -34,6 +35,8 @@ class DeletesV1 { $projectId = $this->args['projectId']; $type = $this->args['type']; + + var_dump("In deletes worker with type ". $type); switch (strval($type)) { case DELETE_TYPE_DOCUMENT: @@ -52,6 +55,9 @@ class DeletesV1 case Database::SYSTEM_COLLECTION_COLLECTIONS: $this->deleteDocuments($document, $projectId); break; + case Database::SYSTEM_COLLECTION_TEAMS: + $this->deleteMemberships($document, $projectId); + break; default: Console::error('No lazy delete operation available for document of type: '.$document->getCollection()); break; @@ -97,6 +103,15 @@ class DeletesV1 ], $this->getProjectDB($projectId)); } + protected function deleteMemberships(Document $document, $projectId) { + var_dump("Deleting memberships"); + // Delete Memberships + $this->deleteByGroup([ + '$collection='.Database::SYSTEM_COLLECTION_MEMBERSHIPS, + 'teamId='.$document->getId(), + ], $this->getProjectDB($projectId)); + } + protected function deleteProject(Document $document) { // Delete all DBs diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index e41e5531ff..a5d96569aa 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -6,15 +6,275 @@ use Tests\E2E\Client; trait TeamsBaseClient { + // /** + // * @depends testCreateTeam + // */ + // public function testGetTeamMemberships($data):array + // { + // $teamUid = $data['teamUid'] ?? ''; + + // /** + // * Test for SUCCESS + // */ + // $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([ + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ], $this->getHeaders())); + + // $this->assertEquals(200, $response['headers']['status-code']); + // $this->assertIsInt($response['body']['sum']); + // $this->assertNotEmpty($response['body']['memberships'][0]['$id']); + // $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['name']); + // $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']); + // $this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]); + + // /** + // * Test for FAILURE + // */ + + // return $data; + // } + + // /** + // * @depends testCreateTeam + // */ + // public function testCreateTeamMembership($data):array + // { + // $teamUid = $data['teamUid'] ?? ''; + // $teamName = $data['teamName'] ?? ''; + // $email = uniqid().'friend@localhost.test'; + + // /** + // * Test for SUCCESS + // */ + // $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ], $this->getHeaders()), [ + // 'email' => $email, + // 'name' => 'Friend User', + // 'roles' => ['admin', 'editor'], + // 'url' => 'http://localhost:5000/join-us#title' + // ]); + + // $this->assertEquals(201, $response['headers']['status-code']); + // $this->assertNotEmpty($response['body']['$id']); + // $this->assertNotEmpty($response['body']['userId']); + // $this->assertNotEmpty($response['body']['teamId']); + // $this->assertCount(2, $response['body']['roles']); + // $this->assertIsInt($response['body']['joined']); + // $this->assertEquals(false, $response['body']['confirm']); + + // $lastEmail = $this->getLastEmail(); + + // $this->assertEquals($email, $lastEmail['to'][0]['address']); + // $this->assertEquals('Friend User', $lastEmail['to'][0]['name']); + // $this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']); + + // $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); + // $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 13); + // $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); + + // /** + // * Test for FAILURE + // */ + // $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ], $this->getHeaders()), [ + // 'email' => 'dasdkaskdjaskdjasjkd', + // 'name' => 'Friend User', + // 'roles' => ['admin', 'editor'], + // 'url' => 'http://localhost:5000/join-us#title' + // ]); + + // $this->assertEquals(400, $response['headers']['status-code']); + + // $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ], $this->getHeaders()), [ + // 'email' => $email, + // 'name' => 'Friend User', + // 'roles' => 'bad string', + // 'url' => 'http://localhost:5000/join-us#title' + // ]); + + // $this->assertEquals(400, $response['headers']['status-code']); + + // $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ], $this->getHeaders()), [ + // 'email' => $email, + // 'name' => 'Friend User', + // 'roles' => ['admin', 'editor'], + // 'url' => 'http://example.com/join-us#title' // bad url + // ]); + + // $this->assertEquals(400, $response['headers']['status-code']); + + // return [ + // 'teamUid' => $teamUid, + // 'secret' => $secret, + // 'membershipUid' => $membershipUid, + // 'userUid' => $userUid, + // ]; + // } + + // /** + // * @depends testCreateTeamMembership + // */ + // public function testUpdateTeamMembership($data):array + // { + // $teamUid = $data['teamUid'] ?? ''; + // $secret = $data['secret'] ?? ''; + // $membershipUid = $data['membershipUid'] ?? ''; + // $userUid = $data['userUid'] ?? ''; + + // /** + // * Test for SUCCESS + // */ + // $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + // 'origin' => 'http://localhost', + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ]), [ + // 'secret' => $secret, + // 'userId' => $userUid, + // ]); + + // $this->assertEquals(200, $response['headers']['status-code']); + // $this->assertNotEmpty($response['body']['$id']); + // $this->assertNotEmpty($response['body']['userId']); + // $this->assertNotEmpty($response['body']['teamId']); + // $this->assertCount(2, $response['body']['roles']); + // $this->assertIsInt($response['body']['joined']); + // $this->assertEquals(true, $response['body']['confirm']); + + // /** + // * Test for FAILURE + // */ + // $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + // 'origin' => 'http://localhost', + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ]), [ + // 'secret' => 'sdasdasd', + // 'userId' => $userUid, + // ]); + + // $this->assertEquals(401, $response['headers']['status-code']); + + // $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + // 'origin' => 'http://localhost', + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ]), [ + // 'secret' => '', + // 'userId' => $userUid, + // ]); + + // $this->assertEquals(400, $response['headers']['status-code']); + + // $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + // 'origin' => 'http://localhost', + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ]), [ + // 'secret' => $secret, + // 'userId' => 'sdasd', + // ]); + + // $this->assertEquals(401, $response['headers']['status-code']); + + // $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + // 'origin' => 'http://localhost', + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ]), [ + // 'secret' => $secret, + // 'userId' => '', + // ]); + + // $this->assertEquals(400, $response['headers']['status-code']); + + // return $data; + // } + + // /** + // * @depends testUpdateTeamMembership + // */ + // public function testDeleteTeamMembership($data):array + // { + // $teamUid = $data['teamUid'] ?? ''; + // $membershipUid = $data['membershipUid'] ?? ''; + + // /** + // * Test for SUCCESS + // */ + // $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ + // 'origin' => 'http://localhost', + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ], $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.'/memberships/'.$membershipUid, array_merge([ + // 'origin' => 'http://localhost', + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ], $this->getHeaders())); + + // $this->assertEquals(200, $response['headers']['status-code']); + // $this->assertCount(1, $response['body']['memberships']); + + // return []; + // } + + /** * @depends testCreateTeam */ - public function testGetTeamMemberships($data):array + public function testDeleteTeamMembershipsWorker($data):array { $teamUid = $data['teamUid'] ?? ''; + $count = 50; + + /* + * Create $count Team Memberships + */ + for ($i = 0; $i < $count; ++$i) { + $email = uniqid().'friend@localhost.test'; + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'email' => $email, + 'name' => 'Friend User ' . $i, + 'roles' => ['admin', 'editor'], + 'url' => 'http://localhost:5000/join-us#title' + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertNotEmpty($response['body']['userId']); + $this->assertNotEmpty($response['body']['teamId']); + $this->assertCount(2, $response['body']['roles']); + $this->assertIsInt($response['body']['joined']); + $this->assertEquals(false, $response['body']['confirm']); + } /** - * Test for SUCCESS + * Get team memberships */ $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([ 'content-type' => 'application/json', @@ -22,199 +282,12 @@ trait TeamsBaseClient ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsInt($response['body']['sum']); - $this->assertNotEmpty($response['body']['memberships'][0]['$id']); - $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['name']); - $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']); - $this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]); + $this->assertEquals($count + 1 /* +1 for Team owner */, $response['body']['sum']); /** - * Test for FAILURE + * Delete the team */ - - return $data; - } - - /** - * @depends testCreateTeam - */ - public function testCreateTeamMembership($data):array - { - $teamUid = $data['teamUid'] ?? ''; - $teamName = $data['teamName'] ?? ''; - $email = uniqid().'friend@localhost.test'; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'email' => $email, - 'name' => 'Friend User', - 'roles' => ['admin', 'editor'], - 'url' => 'http://localhost:5000/join-us#title' - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - $this->assertNotEmpty($response['body']['$id']); - $this->assertNotEmpty($response['body']['userId']); - $this->assertNotEmpty($response['body']['teamId']); - $this->assertCount(2, $response['body']['roles']); - $this->assertIsInt($response['body']['joined']); - $this->assertEquals(false, $response['body']['confirm']); - - $lastEmail = $this->getLastEmail(); - - $this->assertEquals($email, $lastEmail['to'][0]['address']); - $this->assertEquals('Friend User', $lastEmail['to'][0]['name']); - $this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']); - - $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); - $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 13); - $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'email' => 'dasdkaskdjaskdjasjkd', - 'name' => 'Friend User', - 'roles' => ['admin', 'editor'], - 'url' => 'http://localhost:5000/join-us#title' - ]); - - $this->assertEquals(400, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'email' => $email, - 'name' => 'Friend User', - 'roles' => 'bad string', - 'url' => 'http://localhost:5000/join-us#title' - ]); - - $this->assertEquals(400, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'email' => $email, - 'name' => 'Friend User', - 'roles' => ['admin', 'editor'], - 'url' => 'http://example.com/join-us#title' // bad url - ]); - - $this->assertEquals(400, $response['headers']['status-code']); - - return [ - 'teamUid' => $teamUid, - 'secret' => $secret, - 'membershipUid' => $membershipUid, - 'userUid' => $userUid, - ]; - } - - /** - * @depends testCreateTeamMembership - */ - public function testUpdateTeamMembership($data):array - { - $teamUid = $data['teamUid'] ?? ''; - $secret = $data['secret'] ?? ''; - $membershipUid = $data['membershipUid'] ?? ''; - $userUid = $data['userUid'] ?? ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ]), [ - 'secret' => $secret, - 'userId' => $userUid, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertNotEmpty($response['body']['$id']); - $this->assertNotEmpty($response['body']['userId']); - $this->assertNotEmpty($response['body']['teamId']); - $this->assertCount(2, $response['body']['roles']); - $this->assertIsInt($response['body']['joined']); - $this->assertEquals(true, $response['body']['confirm']); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ]), [ - 'secret' => 'sdasdasd', - 'userId' => $userUid, - ]); - - $this->assertEquals(401, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ]), [ - 'secret' => '', - 'userId' => $userUid, - ]); - - $this->assertEquals(400, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ]), [ - 'secret' => $secret, - 'userId' => 'sdasd', - ]); - - $this->assertEquals(401, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ]), [ - 'secret' => $secret, - 'userId' => '', - ]); - - $this->assertEquals(400, $response['headers']['status-code']); - - return $data; - } - - /** - * @depends testUpdateTeamMembership - */ - public function testDeleteTeamMembership($data):array - { - $teamUid = $data['teamUid'] ?? ''; - $membershipUid = $data['membershipUid'] ?? ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ - 'origin' => 'http://localhost', + $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -222,18 +295,8 @@ trait TeamsBaseClient $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(1, $response['body']['memberships']); return []; } + } \ No newline at end of file From 5e6cc855c90471245b71ff1583e5a772076eeda0 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 11 May 2021 23:29:20 +0530 Subject: [PATCH 2/7] feat: remove logs --- app/controllers/api/teams.php | 2 -- app/workers/deletes.php | 3 --- 2 files changed, 5 deletions(-) diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 96d4d89822..5476b65186 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -228,8 +228,6 @@ App::delete('/v1/teams/:teamId') throw new Exception('Failed to remove team from DB', 500); } - var_dump("Deleting team". $teamId); - $deletes ->setParam('type', DELETE_TYPE_DOCUMENT) ->setParam('document', $team) diff --git a/app/workers/deletes.php b/app/workers/deletes.php index b384da5f75..62018e7d1f 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -35,8 +35,6 @@ class DeletesV1 { $projectId = $this->args['projectId']; $type = $this->args['type']; - - var_dump("In deletes worker with type ". $type); switch (strval($type)) { case DELETE_TYPE_DOCUMENT: @@ -104,7 +102,6 @@ class DeletesV1 } protected function deleteMemberships(Document $document, $projectId) { - var_dump("Deleting memberships"); // Delete Memberships $this->deleteByGroup([ '$collection='.Database::SYSTEM_COLLECTION_MEMBERSHIPS, From 0bd542077f37e4d0c30fcd758a70642b1afc9ca0 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 11 May 2021 23:30:00 +0530 Subject: [PATCH 3/7] feat: uncomment --- tests/e2e/Services/Teams/TeamsBaseClient.php | 390 +++++++++---------- 1 file changed, 195 insertions(+), 195 deletions(-) diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index a5d96569aa..9d49069f62 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -6,236 +6,236 @@ use Tests\E2E\Client; trait TeamsBaseClient { - // /** - // * @depends testCreateTeam - // */ - // public function testGetTeamMemberships($data):array - // { - // $teamUid = $data['teamUid'] ?? ''; + /** + * @depends testCreateTeam + */ + public function testGetTeamMemberships($data):array + { + $teamUid = $data['teamUid'] ?? ''; - // /** - // * Test for SUCCESS - // */ - // $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders())); + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); - // $this->assertEquals(200, $response['headers']['status-code']); - // $this->assertIsInt($response['body']['sum']); - // $this->assertNotEmpty($response['body']['memberships'][0]['$id']); - // $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['name']); - // $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']); - // $this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['sum']); + $this->assertNotEmpty($response['body']['memberships'][0]['$id']); + $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['name']); + $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']); + $this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]); - // /** - // * Test for FAILURE - // */ + /** + * Test for FAILURE + */ - // return $data; - // } + return $data; + } - // /** - // * @depends testCreateTeam - // */ - // public function testCreateTeamMembership($data):array - // { - // $teamUid = $data['teamUid'] ?? ''; - // $teamName = $data['teamName'] ?? ''; - // $email = uniqid().'friend@localhost.test'; + /** + * @depends testCreateTeam + */ + public function testCreateTeamMembership($data):array + { + $teamUid = $data['teamUid'] ?? ''; + $teamName = $data['teamName'] ?? ''; + $email = uniqid().'friend@localhost.test'; - // /** - // * Test for SUCCESS - // */ - // $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), [ - // 'email' => $email, - // 'name' => 'Friend User', - // 'roles' => ['admin', 'editor'], - // 'url' => 'http://localhost:5000/join-us#title' - // ]); + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'email' => $email, + 'name' => 'Friend User', + 'roles' => ['admin', 'editor'], + 'url' => 'http://localhost:5000/join-us#title' + ]); - // $this->assertEquals(201, $response['headers']['status-code']); - // $this->assertNotEmpty($response['body']['$id']); - // $this->assertNotEmpty($response['body']['userId']); - // $this->assertNotEmpty($response['body']['teamId']); - // $this->assertCount(2, $response['body']['roles']); - // $this->assertIsInt($response['body']['joined']); - // $this->assertEquals(false, $response['body']['confirm']); + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertNotEmpty($response['body']['userId']); + $this->assertNotEmpty($response['body']['teamId']); + $this->assertCount(2, $response['body']['roles']); + $this->assertIsInt($response['body']['joined']); + $this->assertEquals(false, $response['body']['confirm']); - // $lastEmail = $this->getLastEmail(); + $lastEmail = $this->getLastEmail(); - // $this->assertEquals($email, $lastEmail['to'][0]['address']); - // $this->assertEquals('Friend User', $lastEmail['to'][0]['name']); - // $this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']); + $this->assertEquals($email, $lastEmail['to'][0]['address']); + $this->assertEquals('Friend User', $lastEmail['to'][0]['name']); + $this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']); - // $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); - // $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 13); - // $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); + $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); + $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 13); + $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); - // /** - // * Test for FAILURE - // */ - // $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), [ - // 'email' => 'dasdkaskdjaskdjasjkd', - // 'name' => 'Friend User', - // 'roles' => ['admin', 'editor'], - // 'url' => 'http://localhost:5000/join-us#title' - // ]); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'email' => 'dasdkaskdjaskdjasjkd', + 'name' => 'Friend User', + 'roles' => ['admin', 'editor'], + 'url' => 'http://localhost:5000/join-us#title' + ]); - // $this->assertEquals(400, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); - // $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), [ - // 'email' => $email, - // 'name' => 'Friend User', - // 'roles' => 'bad string', - // 'url' => 'http://localhost:5000/join-us#title' - // ]); + $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'email' => $email, + 'name' => 'Friend User', + 'roles' => 'bad string', + 'url' => 'http://localhost:5000/join-us#title' + ]); - // $this->assertEquals(400, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); - // $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), [ - // 'email' => $email, - // 'name' => 'Friend User', - // 'roles' => ['admin', 'editor'], - // 'url' => 'http://example.com/join-us#title' // bad url - // ]); + $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'email' => $email, + 'name' => 'Friend User', + 'roles' => ['admin', 'editor'], + 'url' => 'http://example.com/join-us#title' // bad url + ]); - // $this->assertEquals(400, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); - // return [ - // 'teamUid' => $teamUid, - // 'secret' => $secret, - // 'membershipUid' => $membershipUid, - // 'userUid' => $userUid, - // ]; - // } + return [ + 'teamUid' => $teamUid, + 'secret' => $secret, + 'membershipUid' => $membershipUid, + 'userUid' => $userUid, + ]; + } - // /** - // * @depends testCreateTeamMembership - // */ - // public function testUpdateTeamMembership($data):array - // { - // $teamUid = $data['teamUid'] ?? ''; - // $secret = $data['secret'] ?? ''; - // $membershipUid = $data['membershipUid'] ?? ''; - // $userUid = $data['userUid'] ?? ''; + /** + * @depends testCreateTeamMembership + */ + public function testUpdateTeamMembership($data):array + { + $teamUid = $data['teamUid'] ?? ''; + $secret = $data['secret'] ?? ''; + $membershipUid = $data['membershipUid'] ?? ''; + $userUid = $data['userUid'] ?? ''; - // /** - // * Test for SUCCESS - // */ - // $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - // 'origin' => 'http://localhost', - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ]), [ - // 'secret' => $secret, - // 'userId' => $userUid, - // ]); + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'secret' => $secret, + 'userId' => $userUid, + ]); - // $this->assertEquals(200, $response['headers']['status-code']); - // $this->assertNotEmpty($response['body']['$id']); - // $this->assertNotEmpty($response['body']['userId']); - // $this->assertNotEmpty($response['body']['teamId']); - // $this->assertCount(2, $response['body']['roles']); - // $this->assertIsInt($response['body']['joined']); - // $this->assertEquals(true, $response['body']['confirm']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertNotEmpty($response['body']['userId']); + $this->assertNotEmpty($response['body']['teamId']); + $this->assertCount(2, $response['body']['roles']); + $this->assertIsInt($response['body']['joined']); + $this->assertEquals(true, $response['body']['confirm']); - // /** - // * Test for FAILURE - // */ - // $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - // 'origin' => 'http://localhost', - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ]), [ - // 'secret' => 'sdasdasd', - // 'userId' => $userUid, - // ]); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'secret' => 'sdasdasd', + 'userId' => $userUid, + ]); - // $this->assertEquals(401, $response['headers']['status-code']); + $this->assertEquals(401, $response['headers']['status-code']); - // $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - // 'origin' => 'http://localhost', - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ]), [ - // 'secret' => '', - // 'userId' => $userUid, - // ]); + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'secret' => '', + 'userId' => $userUid, + ]); - // $this->assertEquals(400, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); - // $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - // 'origin' => 'http://localhost', - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ]), [ - // 'secret' => $secret, - // 'userId' => 'sdasd', - // ]); + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'secret' => $secret, + 'userId' => 'sdasd', + ]); - // $this->assertEquals(401, $response['headers']['status-code']); + $this->assertEquals(401, $response['headers']['status-code']); - // $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - // 'origin' => 'http://localhost', - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ]), [ - // 'secret' => $secret, - // 'userId' => '', - // ]); + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'secret' => $secret, + 'userId' => '', + ]); - // $this->assertEquals(400, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); - // return $data; - // } + return $data; + } - // /** - // * @depends testUpdateTeamMembership - // */ - // public function testDeleteTeamMembership($data):array - // { - // $teamUid = $data['teamUid'] ?? ''; - // $membershipUid = $data['membershipUid'] ?? ''; + /** + * @depends testUpdateTeamMembership + */ + public function testDeleteTeamMembership($data):array + { + $teamUid = $data['teamUid'] ?? ''; + $membershipUid = $data['membershipUid'] ?? ''; - // /** - // * Test for SUCCESS - // */ - // $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ - // 'origin' => 'http://localhost', - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders())); + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); - // $this->assertEquals(204, $response['headers']['status-code']); - // $this->assertEmpty($response['body']); + $this->assertEquals(204, $response['headers']['status-code']); + $this->assertEmpty($response['body']); - // /** - // * Test for FAILURE - // */ - // $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ - // 'origin' => 'http://localhost', - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders())); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); - // $this->assertEquals(200, $response['headers']['status-code']); - // $this->assertCount(1, $response['body']['memberships']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(1, $response['body']['memberships']); - // return []; - // } + return []; + } /** From 08f606d29b3da9b92fa27ab17f2b5b1fa104c4d1 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 11 May 2021 23:31:00 +0530 Subject: [PATCH 4/7] feat: remove unused import --- app/workers/deletes.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/workers/deletes.php b/app/workers/deletes.php index 62018e7d1f..944ad114d2 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -5,7 +5,6 @@ use Appwrite\Database\Adapter\MySQL as MySQLAdapter; use Appwrite\Database\Adapter\Redis as RedisAdapter; use Appwrite\Database\Document; use Appwrite\Database\Validator\Authorization; -use Swoole\FastCGI\Record\Data; use Utopia\Storage\Device\Local; use Utopia\Abuse\Abuse; use Utopia\Abuse\Adapters\TimeLimit; From c9075278e10425864c7ec82e90573fcffce3d1da Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 13 May 2021 19:12:52 +0530 Subject: [PATCH 5/7] feat: some test code --- app/workers/deletes.php | 12 +- tests/e2e/Services/Teams/TeamsBaseClient.php | 392 +++++++++---------- 2 files changed, 207 insertions(+), 197 deletions(-) diff --git a/app/workers/deletes.php b/app/workers/deletes.php index 944ad114d2..f54acd222f 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -101,6 +101,8 @@ class DeletesV1 } protected function deleteMemberships(Document $document, $projectId) { + var_dump("In deleteMembership"); + var_dump($document); // Delete Memberships $this->deleteByGroup([ '$collection='.Database::SYSTEM_COLLECTION_MEMBERSHIPS, @@ -214,7 +216,7 @@ class DeletesV1 Console::success('Delete code tag: '.$document->getAttribute('path', '')); } else { - Console::error('Dailed to delete code tag: '.$document->getAttribute('path', '')); + Console::error('Failed to delete code tag: '.$document->getAttribute('path', '')); } }); @@ -229,6 +231,8 @@ class DeletesV1 { Authorization::disable(); + Console::success($document->getAttribute('name', 'noname')); + var_dump($document); if($database->deleteDocument($document->getId())) { Console::success('Deleted document "'.$document->getId().'" successfully'); @@ -314,6 +318,12 @@ class DeletesV1 Authorization::reset(); + var_dump("chunk=".$chunk); + var_dump("sum=".$sum); + var_dump("limit=".$limit); + var_dump("offset=".$count); + var_dump("count(results)=".count($results)); + $sum = count($results); Console::info('Deleting chunk #'.$chunk.'. Found '.$sum.' documents'); diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index 9d49069f62..6787f110eb 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -6,236 +6,236 @@ use Tests\E2E\Client; trait TeamsBaseClient { - /** - * @depends testCreateTeam - */ - public function testGetTeamMemberships($data):array - { - $teamUid = $data['teamUid'] ?? ''; +// /** +// * @depends testCreateTeam +// */ +// public function testGetTeamMemberships($data):array +// { +// $teamUid = $data['teamUid'] ?? ''; - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); +// /** +// * Test for SUCCESS +// */ +// $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([ +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $this->getProject()['$id'], +// ], $this->getHeaders())); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsInt($response['body']['sum']); - $this->assertNotEmpty($response['body']['memberships'][0]['$id']); - $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['name']); - $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']); - $this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]); +// $this->assertEquals(200, $response['headers']['status-code']); +// $this->assertIsInt($response['body']['sum']); +// $this->assertNotEmpty($response['body']['memberships'][0]['$id']); +// $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['name']); +// $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']); +// $this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]); - /** - * Test for FAILURE - */ +// /** +// * Test for FAILURE +// */ - return $data; - } +// return $data; +// } - /** - * @depends testCreateTeam - */ - public function testCreateTeamMembership($data):array - { - $teamUid = $data['teamUid'] ?? ''; - $teamName = $data['teamName'] ?? ''; - $email = uniqid().'friend@localhost.test'; +// /** +// * @depends testCreateTeam +// */ +// public function testCreateTeamMembership($data):array +// { +// $teamUid = $data['teamUid'] ?? ''; +// $teamName = $data['teamName'] ?? ''; +// $email = uniqid().'friend@localhost.test'; - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'email' => $email, - 'name' => 'Friend User', - 'roles' => ['admin', 'editor'], - 'url' => 'http://localhost:5000/join-us#title' - ]); +// /** +// * Test for SUCCESS +// */ +// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $this->getProject()['$id'], +// ], $this->getHeaders()), [ +// 'email' => $email, +// 'name' => 'Friend User', +// 'roles' => ['admin', 'editor'], +// 'url' => 'http://localhost:5000/join-us#title' +// ]); - $this->assertEquals(201, $response['headers']['status-code']); - $this->assertNotEmpty($response['body']['$id']); - $this->assertNotEmpty($response['body']['userId']); - $this->assertNotEmpty($response['body']['teamId']); - $this->assertCount(2, $response['body']['roles']); - $this->assertIsInt($response['body']['joined']); - $this->assertEquals(false, $response['body']['confirm']); +// $this->assertEquals(201, $response['headers']['status-code']); +// $this->assertNotEmpty($response['body']['$id']); +// $this->assertNotEmpty($response['body']['userId']); +// $this->assertNotEmpty($response['body']['teamId']); +// $this->assertCount(2, $response['body']['roles']); +// $this->assertIsInt($response['body']['joined']); +// $this->assertEquals(false, $response['body']['confirm']); - $lastEmail = $this->getLastEmail(); +// $lastEmail = $this->getLastEmail(); - $this->assertEquals($email, $lastEmail['to'][0]['address']); - $this->assertEquals('Friend User', $lastEmail['to'][0]['name']); - $this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']); +// $this->assertEquals($email, $lastEmail['to'][0]['address']); +// $this->assertEquals('Friend User', $lastEmail['to'][0]['name']); +// $this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']); - $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); - $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 13); - $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); +// $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); +// $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 13); +// $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'email' => 'dasdkaskdjaskdjasjkd', - 'name' => 'Friend User', - 'roles' => ['admin', 'editor'], - 'url' => 'http://localhost:5000/join-us#title' - ]); +// /** +// * Test for FAILURE +// */ +// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $this->getProject()['$id'], +// ], $this->getHeaders()), [ +// 'email' => 'dasdkaskdjaskdjasjkd', +// 'name' => 'Friend User', +// 'roles' => ['admin', 'editor'], +// 'url' => 'http://localhost:5000/join-us#title' +// ]); - $this->assertEquals(400, $response['headers']['status-code']); +// $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'email' => $email, - 'name' => 'Friend User', - 'roles' => 'bad string', - 'url' => 'http://localhost:5000/join-us#title' - ]); +// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $this->getProject()['$id'], +// ], $this->getHeaders()), [ +// 'email' => $email, +// 'name' => 'Friend User', +// 'roles' => 'bad string', +// 'url' => 'http://localhost:5000/join-us#title' +// ]); - $this->assertEquals(400, $response['headers']['status-code']); +// $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'email' => $email, - 'name' => 'Friend User', - 'roles' => ['admin', 'editor'], - 'url' => 'http://example.com/join-us#title' // bad url - ]); +// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $this->getProject()['$id'], +// ], $this->getHeaders()), [ +// 'email' => $email, +// 'name' => 'Friend User', +// 'roles' => ['admin', 'editor'], +// 'url' => 'http://example.com/join-us#title' // bad url +// ]); - $this->assertEquals(400, $response['headers']['status-code']); +// $this->assertEquals(400, $response['headers']['status-code']); - return [ - 'teamUid' => $teamUid, - 'secret' => $secret, - 'membershipUid' => $membershipUid, - 'userUid' => $userUid, - ]; - } +// return [ +// 'teamUid' => $teamUid, +// 'secret' => $secret, +// 'membershipUid' => $membershipUid, +// 'userUid' => $userUid, +// ]; +// } - /** - * @depends testCreateTeamMembership - */ - public function testUpdateTeamMembership($data):array - { - $teamUid = $data['teamUid'] ?? ''; - $secret = $data['secret'] ?? ''; - $membershipUid = $data['membershipUid'] ?? ''; - $userUid = $data['userUid'] ?? ''; +// /** +// * @depends testCreateTeamMembership +// */ +// public function testUpdateTeamMembership($data):array +// { +// $teamUid = $data['teamUid'] ?? ''; +// $secret = $data['secret'] ?? ''; +// $membershipUid = $data['membershipUid'] ?? ''; +// $userUid = $data['userUid'] ?? ''; - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ]), [ - 'secret' => $secret, - 'userId' => $userUid, - ]); +// /** +// * Test for SUCCESS +// */ +// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ +// 'origin' => 'http://localhost', +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $this->getProject()['$id'], +// ]), [ +// 'secret' => $secret, +// 'userId' => $userUid, +// ]); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertNotEmpty($response['body']['$id']); - $this->assertNotEmpty($response['body']['userId']); - $this->assertNotEmpty($response['body']['teamId']); - $this->assertCount(2, $response['body']['roles']); - $this->assertIsInt($response['body']['joined']); - $this->assertEquals(true, $response['body']['confirm']); +// $this->assertEquals(200, $response['headers']['status-code']); +// $this->assertNotEmpty($response['body']['$id']); +// $this->assertNotEmpty($response['body']['userId']); +// $this->assertNotEmpty($response['body']['teamId']); +// $this->assertCount(2, $response['body']['roles']); +// $this->assertIsInt($response['body']['joined']); +// $this->assertEquals(true, $response['body']['confirm']); - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ]), [ - 'secret' => 'sdasdasd', - 'userId' => $userUid, - ]); +// /** +// * Test for FAILURE +// */ +// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ +// 'origin' => 'http://localhost', +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $this->getProject()['$id'], +// ]), [ +// 'secret' => 'sdasdasd', +// 'userId' => $userUid, +// ]); - $this->assertEquals(401, $response['headers']['status-code']); +// $this->assertEquals(401, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ]), [ - 'secret' => '', - 'userId' => $userUid, - ]); +// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ +// 'origin' => 'http://localhost', +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $this->getProject()['$id'], +// ]), [ +// 'secret' => '', +// 'userId' => $userUid, +// ]); - $this->assertEquals(400, $response['headers']['status-code']); +// $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ]), [ - 'secret' => $secret, - 'userId' => 'sdasd', - ]); +// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ +// 'origin' => 'http://localhost', +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $this->getProject()['$id'], +// ]), [ +// 'secret' => $secret, +// 'userId' => 'sdasd', +// ]); - $this->assertEquals(401, $response['headers']['status-code']); +// $this->assertEquals(401, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ]), [ - 'secret' => $secret, - 'userId' => '', - ]); +// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ +// 'origin' => 'http://localhost', +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $this->getProject()['$id'], +// ]), [ +// 'secret' => $secret, +// 'userId' => '', +// ]); - $this->assertEquals(400, $response['headers']['status-code']); +// $this->assertEquals(400, $response['headers']['status-code']); - return $data; - } +// return $data; +// } - /** - * @depends testUpdateTeamMembership - */ - public function testDeleteTeamMembership($data):array - { - $teamUid = $data['teamUid'] ?? ''; - $membershipUid = $data['membershipUid'] ?? ''; +// /** +// * @depends testUpdateTeamMembership +// */ +// public function testDeleteTeamMembership($data):array +// { +// $teamUid = $data['teamUid'] ?? ''; +// $membershipUid = $data['membershipUid'] ?? ''; - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); +// /** +// * Test for SUCCESS +// */ +// $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ +// 'origin' => 'http://localhost', +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $this->getProject()['$id'], +// ], $this->getHeaders())); - $this->assertEquals(204, $response['headers']['status-code']); - $this->assertEmpty($response['body']); +// $this->assertEquals(204, $response['headers']['status-code']); +// $this->assertEmpty($response['body']); - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); +// /** +// * Test for FAILURE +// */ +// $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ +// 'origin' => 'http://localhost', +// 'content-type' => 'application/json', +// 'x-appwrite-project' => $this->getProject()['$id'], +// ], $this->getHeaders())); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertCount(1, $response['body']['memberships']); +// $this->assertEquals(200, $response['headers']['status-code']); +// $this->assertCount(1, $response['body']['memberships']); - return []; - } +// return []; +// } /** @@ -244,7 +244,7 @@ trait TeamsBaseClient public function testDeleteTeamMembershipsWorker($data):array { $teamUid = $data['teamUid'] ?? ''; - $count = 50; + $count = 3; /* * Create $count Team Memberships From 09a90a563198bf3a72bae10441e60b1d70860163 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 14 Jun 2021 10:41:48 +0530 Subject: [PATCH 6/7] feat: fix deletes workker bug --- app/workers/deletes.php | 13 +- tests/e2e/Services/Teams/TeamsBaseClient.php | 530 +++++++++---------- 2 files changed, 266 insertions(+), 277 deletions(-) diff --git a/app/workers/deletes.php b/app/workers/deletes.php index f54acd222f..1636ff4af5 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -32,7 +32,7 @@ class DeletesV1 public function perform() { - $projectId = $this->args['projectId']; + $projectId = isset($this->args['projectId']) ? $this->args['projectId'] : ''; $type = $this->args['type']; switch (strval($type)) { @@ -101,8 +101,6 @@ class DeletesV1 } protected function deleteMemberships(Document $document, $projectId) { - var_dump("In deleteMembership"); - var_dump($document); // Delete Memberships $this->deleteByGroup([ '$collection='.Database::SYSTEM_COLLECTION_MEMBERSHIPS, @@ -232,7 +230,6 @@ class DeletesV1 Authorization::disable(); Console::success($document->getAttribute('name', 'noname')); - var_dump($document); if($database->deleteDocument($document->getId())) { Console::success('Deleted document "'.$document->getId().'" successfully'); @@ -266,7 +263,6 @@ class DeletesV1 Authorization::disable(); $projects = $this->getConsoleDB()->getCollection([ 'limit' => $limit, - 'offset' => $count, 'orderType' => 'ASC', 'orderCast' => 'string', 'filters' => [ @@ -309,7 +305,6 @@ class DeletesV1 $results = $database->getCollection([ 'limit' => $limit, - 'offset' => $count, 'orderField' => '$id', 'orderType' => 'ASC', 'orderCast' => 'string', @@ -318,12 +313,6 @@ class DeletesV1 Authorization::reset(); - var_dump("chunk=".$chunk); - var_dump("sum=".$sum); - var_dump("limit=".$limit); - var_dump("offset=".$count); - var_dump("count(results)=".count($results)); - $sum = count($results); Console::info('Deleting chunk #'.$chunk.'. Found '.$sum.' documents'); diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index 6787f110eb..ee9d1541bc 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -6,275 +6,15 @@ use Tests\E2E\Client; trait TeamsBaseClient { -// /** -// * @depends testCreateTeam -// */ -// public function testGetTeamMemberships($data):array -// { -// $teamUid = $data['teamUid'] ?? ''; - -// /** -// * Test for SUCCESS -// */ -// $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([ -// 'content-type' => 'application/json', -// 'x-appwrite-project' => $this->getProject()['$id'], -// ], $this->getHeaders())); - -// $this->assertEquals(200, $response['headers']['status-code']); -// $this->assertIsInt($response['body']['sum']); -// $this->assertNotEmpty($response['body']['memberships'][0]['$id']); -// $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['name']); -// $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']); -// $this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]); - -// /** -// * Test for FAILURE -// */ - -// return $data; -// } - -// /** -// * @depends testCreateTeam -// */ -// public function testCreateTeamMembership($data):array -// { -// $teamUid = $data['teamUid'] ?? ''; -// $teamName = $data['teamName'] ?? ''; -// $email = uniqid().'friend@localhost.test'; - -// /** -// * Test for SUCCESS -// */ -// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ -// 'content-type' => 'application/json', -// 'x-appwrite-project' => $this->getProject()['$id'], -// ], $this->getHeaders()), [ -// 'email' => $email, -// 'name' => 'Friend User', -// 'roles' => ['admin', 'editor'], -// 'url' => 'http://localhost:5000/join-us#title' -// ]); - -// $this->assertEquals(201, $response['headers']['status-code']); -// $this->assertNotEmpty($response['body']['$id']); -// $this->assertNotEmpty($response['body']['userId']); -// $this->assertNotEmpty($response['body']['teamId']); -// $this->assertCount(2, $response['body']['roles']); -// $this->assertIsInt($response['body']['joined']); -// $this->assertEquals(false, $response['body']['confirm']); - -// $lastEmail = $this->getLastEmail(); - -// $this->assertEquals($email, $lastEmail['to'][0]['address']); -// $this->assertEquals('Friend User', $lastEmail['to'][0]['name']); -// $this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']); - -// $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); -// $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 13); -// $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); - -// /** -// * Test for FAILURE -// */ -// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ -// 'content-type' => 'application/json', -// 'x-appwrite-project' => $this->getProject()['$id'], -// ], $this->getHeaders()), [ -// 'email' => 'dasdkaskdjaskdjasjkd', -// 'name' => 'Friend User', -// 'roles' => ['admin', 'editor'], -// 'url' => 'http://localhost:5000/join-us#title' -// ]); - -// $this->assertEquals(400, $response['headers']['status-code']); - -// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ -// 'content-type' => 'application/json', -// 'x-appwrite-project' => $this->getProject()['$id'], -// ], $this->getHeaders()), [ -// 'email' => $email, -// 'name' => 'Friend User', -// 'roles' => 'bad string', -// 'url' => 'http://localhost:5000/join-us#title' -// ]); - -// $this->assertEquals(400, $response['headers']['status-code']); - -// $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ -// 'content-type' => 'application/json', -// 'x-appwrite-project' => $this->getProject()['$id'], -// ], $this->getHeaders()), [ -// 'email' => $email, -// 'name' => 'Friend User', -// 'roles' => ['admin', 'editor'], -// 'url' => 'http://example.com/join-us#title' // bad url -// ]); - -// $this->assertEquals(400, $response['headers']['status-code']); - -// return [ -// 'teamUid' => $teamUid, -// 'secret' => $secret, -// 'membershipUid' => $membershipUid, -// 'userUid' => $userUid, -// ]; -// } - -// /** -// * @depends testCreateTeamMembership -// */ -// public function testUpdateTeamMembership($data):array -// { -// $teamUid = $data['teamUid'] ?? ''; -// $secret = $data['secret'] ?? ''; -// $membershipUid = $data['membershipUid'] ?? ''; -// $userUid = $data['userUid'] ?? ''; - -// /** -// * Test for SUCCESS -// */ -// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ -// 'origin' => 'http://localhost', -// 'content-type' => 'application/json', -// 'x-appwrite-project' => $this->getProject()['$id'], -// ]), [ -// 'secret' => $secret, -// 'userId' => $userUid, -// ]); - -// $this->assertEquals(200, $response['headers']['status-code']); -// $this->assertNotEmpty($response['body']['$id']); -// $this->assertNotEmpty($response['body']['userId']); -// $this->assertNotEmpty($response['body']['teamId']); -// $this->assertCount(2, $response['body']['roles']); -// $this->assertIsInt($response['body']['joined']); -// $this->assertEquals(true, $response['body']['confirm']); - -// /** -// * Test for FAILURE -// */ -// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ -// 'origin' => 'http://localhost', -// 'content-type' => 'application/json', -// 'x-appwrite-project' => $this->getProject()['$id'], -// ]), [ -// 'secret' => 'sdasdasd', -// 'userId' => $userUid, -// ]); - -// $this->assertEquals(401, $response['headers']['status-code']); - -// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ -// 'origin' => 'http://localhost', -// 'content-type' => 'application/json', -// 'x-appwrite-project' => $this->getProject()['$id'], -// ]), [ -// 'secret' => '', -// 'userId' => $userUid, -// ]); - -// $this->assertEquals(400, $response['headers']['status-code']); - -// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ -// 'origin' => 'http://localhost', -// 'content-type' => 'application/json', -// 'x-appwrite-project' => $this->getProject()['$id'], -// ]), [ -// 'secret' => $secret, -// 'userId' => 'sdasd', -// ]); - -// $this->assertEquals(401, $response['headers']['status-code']); - -// $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ -// 'origin' => 'http://localhost', -// 'content-type' => 'application/json', -// 'x-appwrite-project' => $this->getProject()['$id'], -// ]), [ -// 'secret' => $secret, -// 'userId' => '', -// ]); - -// $this->assertEquals(400, $response['headers']['status-code']); - -// return $data; -// } - -// /** -// * @depends testUpdateTeamMembership -// */ -// public function testDeleteTeamMembership($data):array -// { -// $teamUid = $data['teamUid'] ?? ''; -// $membershipUid = $data['membershipUid'] ?? ''; - -// /** -// * Test for SUCCESS -// */ -// $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ -// 'origin' => 'http://localhost', -// 'content-type' => 'application/json', -// 'x-appwrite-project' => $this->getProject()['$id'], -// ], $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.'/memberships/'.$membershipUid, array_merge([ -// 'origin' => 'http://localhost', -// 'content-type' => 'application/json', -// 'x-appwrite-project' => $this->getProject()['$id'], -// ], $this->getHeaders())); - -// $this->assertEquals(200, $response['headers']['status-code']); -// $this->assertCount(1, $response['body']['memberships']); - -// return []; -// } - - /** * @depends testCreateTeam */ - public function testDeleteTeamMembershipsWorker($data):array + public function testGetTeamMemberships($data):array { $teamUid = $data['teamUid'] ?? ''; - $count = 3; - - /* - * Create $count Team Memberships - */ - for ($i = 0; $i < $count; ++$i) { - $email = uniqid().'friend@localhost.test'; - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'email' => $email, - 'name' => 'Friend User ' . $i, - 'roles' => ['admin', 'editor'], - 'url' => 'http://localhost:5000/join-us#title' - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - $this->assertNotEmpty($response['body']['$id']); - $this->assertNotEmpty($response['body']['userId']); - $this->assertNotEmpty($response['body']['teamId']); - $this->assertCount(2, $response['body']['roles']); - $this->assertIsInt($response['body']['joined']); - $this->assertEquals(false, $response['body']['confirm']); - } /** - * Get team memberships + * Test for SUCCESS */ $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([ 'content-type' => 'application/json', @@ -282,12 +22,199 @@ trait TeamsBaseClient ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals($count + 1 /* +1 for Team owner */, $response['body']['sum']); + $this->assertIsInt($response['body']['sum']); + $this->assertNotEmpty($response['body']['memberships'][0]['$id']); + $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['name']); + $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']); + $this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]); /** - * Delete the team + * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid, array_merge([ + + return $data; + } + + /** + * @depends testCreateTeam + */ + public function testCreateTeamMembership($data):array + { + $teamUid = $data['teamUid'] ?? ''; + $teamName = $data['teamName'] ?? ''; + $email = uniqid().'friend@localhost.test'; + + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'email' => $email, + 'name' => 'Friend User', + 'roles' => ['admin', 'editor'], + 'url' => 'http://localhost:5000/join-us#title' + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertNotEmpty($response['body']['userId']); + $this->assertNotEmpty($response['body']['teamId']); + $this->assertCount(2, $response['body']['roles']); + $this->assertIsInt($response['body']['joined']); + $this->assertEquals(false, $response['body']['confirm']); + + $lastEmail = $this->getLastEmail(); + + $this->assertEquals($email, $lastEmail['to'][0]['address']); + $this->assertEquals('Friend User', $lastEmail['to'][0]['name']); + $this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']); + + $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); + $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 13); + $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); + + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'email' => 'dasdkaskdjaskdjasjkd', + 'name' => 'Friend User', + 'roles' => ['admin', 'editor'], + 'url' => 'http://localhost:5000/join-us#title' + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'email' => $email, + 'name' => 'Friend User', + 'roles' => 'bad string', + 'url' => 'http://localhost:5000/join-us#title' + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'email' => $email, + 'name' => 'Friend User', + 'roles' => ['admin', 'editor'], + 'url' => 'http://example.com/join-us#title' // bad url + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + return [ + 'teamUid' => $teamUid, + 'secret' => $secret, + 'membershipUid' => $membershipUid, + 'userUid' => $userUid, + ]; + } + + /** + * @depends testCreateTeamMembership + */ + public function testUpdateTeamMembership($data):array + { + $teamUid = $data['teamUid'] ?? ''; + $secret = $data['secret'] ?? ''; + $membershipUid = $data['membershipUid'] ?? ''; + $userUid = $data['userUid'] ?? ''; + + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'secret' => $secret, + 'userId' => $userUid, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertNotEmpty($response['body']['userId']); + $this->assertNotEmpty($response['body']['teamId']); + $this->assertCount(2, $response['body']['roles']); + $this->assertIsInt($response['body']['joined']); + $this->assertEquals(true, $response['body']['confirm']); + + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'secret' => 'sdasdasd', + 'userId' => $userUid, + ]); + + $this->assertEquals(401, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'secret' => '', + 'userId' => $userUid, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'secret' => $secret, + 'userId' => 'sdasd', + ]); + + $this->assertEquals(401, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'secret' => $secret, + 'userId' => '', + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + return $data; + } + + /** + * @depends testUpdateTeamMembership + */ + public function testDeleteTeamMembership($data):array + { + $teamUid = $data['teamUid'] ?? ''; + $membershipUid = $data['membershipUid'] ?? ''; + + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ + 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -295,8 +222,81 @@ trait TeamsBaseClient $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(1, $response['body']['memberships']); return []; } + + // /** + // * @depends testCreateTeam + // */ + // public function testDeleteTeamMembershipsWorker($data):array + // { + // $teamUid = $data['teamUid'] ?? ''; + // $count = 100; + + // /* + // * Create $count Team Memberships + // */ + // for ($i = 0; $i < $count; ++$i) { + // $email = uniqid().'friend@localhost.test'; + // /** + // * Test for SUCCESS + // */ + // $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ], $this->getHeaders()), [ + // 'email' => $email, + // 'name' => 'Friend User ' . $i, + // 'roles' => ['admin', 'editor'], + // 'url' => 'http://localhost:5000/join-us#title' + // ]); + + // $this->assertEquals(201, $response['headers']['status-code']); + // $this->assertNotEmpty($response['body']['$id']); + // $this->assertNotEmpty($response['body']['userId']); + // $this->assertNotEmpty($response['body']['teamId']); + // $this->assertCount(2, $response['body']['roles']); + // $this->assertIsInt($response['body']['joined']); + // $this->assertEquals(false, $response['body']['confirm']); + // } + + // /** + // * Get team memberships + // */ + // $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([ + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ], $this->getHeaders())); + + // $this->assertEquals(200, $response['headers']['status-code']); + // $this->assertEquals($count + 1 /* +1 for Team owner */, $response['body']['sum']); + + // /** + // * Delete the team + // */ + // $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid, array_merge([ + // 'content-type' => 'application/json', + // 'x-appwrite-project' => $this->getProject()['$id'], + // ], $this->getHeaders())); + + // $this->assertEquals(204, $response['headers']['status-code']); + // $this->assertEmpty($response['body']); + + + // return []; + // } + } \ No newline at end of file From 412d7c87350e1134b2c8a05a6d5a786f070b5b14 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 14 Jun 2021 10:45:41 +0530 Subject: [PATCH 7/7] feat: removed log --- app/workers/deletes.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/workers/deletes.php b/app/workers/deletes.php index 1636ff4af5..9f12eaed7d 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -229,7 +229,6 @@ class DeletesV1 { Authorization::disable(); - Console::success($document->getAttribute('name', 'noname')); if($database->deleteDocument($document->getId())) { Console::success('Deleted document "'.$document->getId().'" successfully');