Project deletion tests

This commit is contained in:
Matej Bačo
2026-04-23 13:41:11 +02:00
parent a0a3849b16
commit c246fb0f83
2 changed files with 79 additions and 0 deletions
@@ -2,6 +2,7 @@
namespace Tests\E2E\Services\Projects;
use PHPUnit\Framework\Attributes\Group;
use Tests\E2E\Client;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Helpers\Role;
@@ -17,6 +18,83 @@ trait ProjectsBase
private static array $cachedProjectWithAuthLimit = [];
private static array $cachedProjectWithServicesDisabled = [];
protected function createProjectForDeleteTest(): array
{
$rootHeaders = [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
'x-appwrite-project' => 'console',
];
$team = $this->client->call(Client::METHOD_POST, '/teams', $rootHeaders, [
'teamId' => ID::unique(),
'name' => 'Delete Project Team',
]);
$this->assertSame(201, $team['headers']['status-code']);
$project = $this->client->call(Client::METHOD_POST, '/projects', $rootHeaders, [
'projectId' => ID::unique(),
'name' => 'Delete Project Test',
'teamId' => $team['body']['$id'],
'region' => System::getEnv('_APP_REGION', 'default'),
]);
$this->assertSame(201, $project['headers']['status-code']);
$key = $this->client->call(Client::METHOD_POST, '/projects/' . $project['body']['$id'] . '/keys', $rootHeaders, [
'keyId' => ID::unique(),
'name' => 'Delete Project Key',
'scopes' => [
'project.read',
'project.write',
],
]);
$this->assertSame(201, $key['headers']['status-code']);
return [
'projectId' => $project['body']['$id'],
'apiKey' => $key['body']['secret'],
];
}
#[Group('projectsCRUD')]
public function testDeleteProject(): void
{
$project = $this->createProjectForDeleteTest();
$headers = match ($this->getSide()) {
'server' => [
'content-type' => 'application/json',
'x-appwrite-project' => $project['projectId'],
'x-appwrite-key' => $project['apiKey'],
'x-appwrite-mode' => 'admin',
],
default => [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
'x-appwrite-project' => $project['projectId'],
'x-appwrite-mode' => 'admin',
],
};
$response = $this->client->call(Client::METHOD_DELETE, '/project', $headers);
$this->assertSame(204, $response['headers']['status-code']);
$get = $this->client->call(Client::METHOD_GET, '/projects/' . $project['projectId'], [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
'x-appwrite-project' => 'console',
]);
$this->assertSame(404, $get['headers']['status-code']);
}
/**
* Setup and cache a basic project with team
*/
@@ -10,6 +10,7 @@ use Utopia\System\System;
class ProjectsCustomServerTest extends Scope
{
use ProjectsBase;
use ProjectCustom;
use SideServer;