From 9a712686f2636e4cdc0bd6910724add60c01f0fd Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 29 Apr 2023 13:13:33 +0530 Subject: [PATCH] chore: add tests --- phpunit.xml | 4 +-- .../Projects/ProjectsConsoleClientTest.php | 33 ++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 927e91567a..4074fe0f1c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,8 +6,8 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" - > + stopOnFailure="true" +> diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 789020bf42..6380a81326 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -3,6 +3,7 @@ namespace Tests\E2E\Services\Projects; use Appwrite\Auth\Auth; +use Appwrite\Extend\Exception; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectConsole; use Tests\E2E\Scopes\SideClient; @@ -98,7 +99,37 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - return ['projectId' => $projectId]; + return [ + 'projectId' => $projectId, + 'teamId' => $team['body']['$id'] + ]; + } + + /** + * @depends testCreateProject + */ + public function testCreateDuplicateProject($data) + { + $teamId = $data['teamId'] ?? ''; + $projectId = $data['projectId'] ?? ''; + + /** + * Test for FAILURE + */ + $response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'projectId' => $projectId, + 'name' => 'Project Duplicate', + 'teamId' => $teamId, + 'region' => 'default' + ]); + + $this->assertEquals(403, $response['headers']['status-code']); + $this->assertEquals(403, $response['body']['code']); + $this->assertEquals(Exception::PROJECT_ALREADY_EXISTS, $response['body']['type']); + $this->assertEquals('Project with the requested ID already exists.', $response['body']['message']); } /**