diff --git a/tests/e2e/Scopes/SideServerOrganization.php b/tests/e2e/Scopes/SideServerOrganization.php new file mode 100644 index 0000000000..45fa48451f --- /dev/null +++ b/tests/e2e/Scopes/SideServerOrganization.php @@ -0,0 +1,81 @@ +client->call(Client::METHOD_POST, '/teams', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => 'console', + ], [ + 'teamId' => $teamId, + 'name' => 'Organization Test', + ]); + if (\in_array($team['headers']['status-code'], [201, 409])) { + break; + } + \usleep(500000); + } + $this->assertContains($team['headers']['status-code'], [201, 409]); + $teamId = $team['body']['$id'] ?? $teamId; + + $key = $this->client->call(Client::METHOD_POST, '/v1/organization/keys', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => 'console', + 'x-appwrite-organization' => $teamId, + ], [ + 'keyId' => ID::unique(), + 'name' => 'Organization Key', + 'scopes' => ['projects.read', 'projects.write'], + ]); + + $this->assertEquals(201, $key['headers']['status-code']); + $this->assertNotEmpty($key['body']['secret']); + + self::$organization = [ + '$id' => $teamId, + 'apiKey' => $key['body']['secret'], + ]; + + return self::$organization; + } + + public function getHeaders(bool $devKey = false): array + { + $organization = $this->getOrganization(); + + return [ + 'x-appwrite-key' => $organization['apiKey'], + 'x-appwrite-organization' => $organization['$id'], + ]; + } + + /** + * @return string + */ + public function getSide() + { + return 'server'; + } +} diff --git a/tests/e2e/Services/Organization/ProjectsBase.php b/tests/e2e/Services/Organization/ProjectsBase.php new file mode 100644 index 0000000000..eff7c827a3 --- /dev/null +++ b/tests/e2e/Services/Organization/ProjectsBase.php @@ -0,0 +1,26 @@ +client->call(Client::METHOD_POST, '/v1/organization/projects', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'projectId' => ID::unique(), + 'name' => 'Organization Project Test', + 'region' => System::getEnv('_APP_REGION', 'default'), + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertEquals('Organization Project Test', $response['body']['name']); + } +} diff --git a/tests/e2e/Services/Organization/ProjectsConsoleClientTest.php b/tests/e2e/Services/Organization/ProjectsConsoleClientTest.php new file mode 100644 index 0000000000..5d016eff01 --- /dev/null +++ b/tests/e2e/Services/Organization/ProjectsConsoleClientTest.php @@ -0,0 +1,14 @@ +