From 3da4b01f4ebe0981f32e9ef7f0afe19441186ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 3 Oct 2022 08:06:48 +0000 Subject: [PATCH] Deprecate team deletion with project --- app/controllers/api/projects.php | 4 - .../Projects/ProjectsConsoleClientTest.php | 79 +++++++++++++++++++ 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 41ba77da4..9413e8c68 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -563,10 +563,6 @@ App::delete('/v1/projects/:projectId') ->setDocument($project) ; - if (!$dbForConsole->deleteDocument('teams', $project->getAttribute('teamId', null))) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove project team from DB'); - } - if (!$dbForConsole->deleteDocument('projects', $projectId)) { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove project from DB'); } diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 4c4d2e521..df2a5beef 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -2321,4 +2321,83 @@ class ProjectsConsoleClientTest extends Scope return $data; } + + public function testDeleteProject(): array + { + $data = []; + + // Create a team and a project + $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'teamId' => ID::unique(), + 'name' => 'Amating Team', + ]); + + $this->assertEquals(201, $team['headers']['status-code']); + $this->assertEquals('Amating Team', $team['body']['name']); + $this->assertNotEmpty($team['body']['$id']); + + $teamId = $team['body']['$id']; + + $project = $this->client->call(Client::METHOD_POST, '/projects', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'projectId' => ID::unique(), + 'name' => 'Amazing Project', + 'teamId' => $teamId, + 'region' => 'default' + ]); + + $this->assertEquals(201, $project['headers']['status-code']); + $this->assertEquals('Amazing Project', $project['body']['name']); + $this->assertEquals($teamId, $project['body']['teamId']); + $this->assertNotEmpty($project['body']['$id']); + + $projectId = $project['body']['$id']; + + // Ensure I can get both team and project + $team = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $team['headers']['status-code']); + + $project = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $project['headers']['status-code']); + + // Delete team + $team = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'password' => 'password' + ]); + + $this->assertEquals(204, $team['headers']['status-code']); + + // Ensure I can get team but not a project + $team = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $team['headers']['status-code']); + + $project = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(404, $project['headers']['status-code']); + + return $data; + } }