mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Merge pull request #10655 from appwrite/fix-test-dependencies-projects
Refactor ProjectsConsoleClientTest to remove test dependencies
This commit is contained in:
commit
2cbfa6930f
1 changed files with 199 additions and 69 deletions
|
|
@ -112,13 +112,33 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testCreateDuplicateProject(): void
|
||||||
* @depends testCreateProject
|
|
||||||
*/
|
|
||||||
public function testCreateDuplicateProject($data)
|
|
||||||
{
|
{
|
||||||
$teamId = $data['teamId'] ?? '';
|
// Create a team
|
||||||
$projectId = $data['projectId'] ?? '';
|
$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' => 'Duplicate Test Team',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $team['headers']['status-code']);
|
||||||
|
$teamId = $team['body']['$id'];
|
||||||
|
|
||||||
|
// Create a project
|
||||||
|
$projectId = ID::unique();
|
||||||
|
$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' => 'Original Project',
|
||||||
|
'teamId' => $teamId,
|
||||||
|
'region' => System::getEnv('_APP_REGION', 'default')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for FAILURE
|
* Test for FAILURE
|
||||||
|
|
@ -416,12 +436,32 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testGetProject(): void
|
||||||
* @depends testCreateProject
|
|
||||||
*/
|
|
||||||
public function testGetProject($data): array
|
|
||||||
{
|
{
|
||||||
$id = $data['projectId'] ?? '';
|
// Create a team
|
||||||
|
$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' => 'Get Project Test Team',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $team['headers']['status-code']);
|
||||||
|
|
||||||
|
// Create a project
|
||||||
|
$response = $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' => 'Project Test',
|
||||||
|
'teamId' => $team['body']['$id'],
|
||||||
|
'region' => System::getEnv('_APP_REGION', 'default')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
$id = $response['body']['$id'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for SUCCESS
|
* Test for SUCCESS
|
||||||
|
|
@ -439,7 +479,6 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
/**
|
/**
|
||||||
* Test for FAILURE
|
* Test for FAILURE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/projects/empty', array_merge([
|
$response = $this->client->call(Client::METHOD_GET, '/projects/empty', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
|
@ -453,8 +492,6 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
], $this->getHeaders()));
|
], $this->getHeaders()));
|
||||||
|
|
||||||
$this->assertEquals(400, $response['headers']['status-code']);
|
$this->assertEquals(400, $response['headers']['status-code']);
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -512,12 +549,33 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testUpdateProject(): void
|
||||||
* @depends testCreateProject
|
|
||||||
*/
|
|
||||||
public function testUpdateProject($data): array
|
|
||||||
{
|
{
|
||||||
$id = $data['projectId'] ?? '';
|
// Create a team
|
||||||
|
$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' => 'Update Project Test Team',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $team['headers']['status-code']);
|
||||||
|
$teamId = $team['body']['$id'];
|
||||||
|
|
||||||
|
// Create a project
|
||||||
|
$response = $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' => 'Project Test',
|
||||||
|
'teamId' => $teamId,
|
||||||
|
'region' => System::getEnv('_APP_REGION', 'default')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
$id = $response['body']['$id'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for SUCCESS
|
* Test for SUCCESS
|
||||||
|
|
@ -542,7 +600,6 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
/**
|
/**
|
||||||
* Test for FAILURE
|
* Test for FAILURE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
|
@ -552,8 +609,6 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(401, $response['headers']['status-code']);
|
$this->assertEquals(401, $response['headers']['status-code']);
|
||||||
|
|
||||||
return ['projectId' => $projectId];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -607,11 +662,35 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group smtpAndTemplates
|
* @group smtpAndTemplates
|
||||||
* @depends testCreateProject
|
|
||||||
*/
|
*/
|
||||||
public function testCreateProjectSMTPTests($data): array
|
public function testCreateProjectSMTPTests(): void
|
||||||
{
|
{
|
||||||
$id = $data['projectId'];
|
// Create a team
|
||||||
|
$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' => 'Create Project SMTP Tests Test Team',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $team['headers']['status-code']);
|
||||||
|
$teamId = $team['body']['$id'];
|
||||||
|
|
||||||
|
// Create a project
|
||||||
|
$response = $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' => 'Project Test',
|
||||||
|
'teamId' => $teamId,
|
||||||
|
'region' => System::getEnv('_APP_REGION', 'default')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
$id = $response['body']['$id'];
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
|
@ -680,8 +759,6 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(400, $response['headers']['status-code']);
|
$this->assertEquals(400, $response['headers']['status-code']);
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -793,7 +870,6 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
/**
|
/**
|
||||||
* Test for SUCCESS
|
* Test for SUCCESS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/duration', array_merge([
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/duration', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
|
@ -950,10 +1026,32 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
return ['projectId' => $projectId];
|
return ['projectId' => $projectId];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @depends testCreateProject */
|
public function testUpdateProjectInvalidateSessions(): void
|
||||||
public function testUpdateProjectInvalidateSessions($data): array
|
|
||||||
{
|
{
|
||||||
$id = $data['projectId'];
|
// Create a team for the test 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' => 'Session Invalidation Test Team',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $team['headers']['status-code']);
|
||||||
|
|
||||||
|
// Create a test project
|
||||||
|
$response = $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' => 'Session Invalidation Test Project',
|
||||||
|
'teamId' => $team['body']['$id'],
|
||||||
|
'region' => System::getEnv('_APP_REGION', 'default')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
$id = $response['body']['$id'];
|
||||||
|
|
||||||
// Check defaults
|
// Check defaults
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
||||||
|
|
@ -995,22 +1093,41 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
|
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertTrue($response['body']['authInvalidateSessions']);
|
$this->assertTrue($response['body']['authInvalidateSessions']);
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testUpdateProjectOAuth(): void
|
||||||
* @depends testCreateProject
|
|
||||||
*/
|
|
||||||
public function testUpdateProjectOAuth($data): array
|
|
||||||
{
|
{
|
||||||
$id = $data['projectId'] ?? '';
|
// Create a team
|
||||||
|
$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' => 'Update Project OAuth Test Team',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $team['headers']['status-code']);
|
||||||
|
$teamId = $team['body']['$id'];
|
||||||
|
|
||||||
|
// Create a project
|
||||||
|
$response = $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' => 'Project Test',
|
||||||
|
'teamId' => $teamId,
|
||||||
|
'region' => System::getEnv('_APP_REGION', 'default')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
$id = $response['body']['$id'];
|
||||||
|
|
||||||
$providers = require(__DIR__ . '/../../../../app/config/oAuthProviders.php');
|
$providers = require(__DIR__ . '/../../../../app/config/oAuthProviders.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for SUCCESS
|
* Test for SUCCESS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
foreach ($providers as $key => $provider) {
|
foreach ($providers as $key => $provider) {
|
||||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
|
|
@ -1095,7 +1212,6 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
/**
|
/**
|
||||||
* Test for FAILURE
|
* Test for FAILURE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
|
@ -1106,18 +1222,37 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(400, $response['headers']['status-code']);
|
$this->assertEquals(400, $response['headers']['status-code']);
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testUpdateProjectAuthStatus(): void
|
||||||
* @depends testCreateProject
|
|
||||||
*/
|
|
||||||
public function testUpdateProjectAuthStatus($data): array
|
|
||||||
{
|
{
|
||||||
$id = $data['projectId'] ?? '';
|
// Create a team
|
||||||
$auth = require(__DIR__ . '/../../../../app/config/auth.php');
|
$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' => 'Update Project Auth Status Test Team',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $team['headers']['status-code']);
|
||||||
|
$teamId = $team['body']['$id'];
|
||||||
|
|
||||||
|
// Create a project
|
||||||
|
$response = $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' => 'Project Test',
|
||||||
|
'teamId' => $teamId,
|
||||||
|
'region' => System::getEnv('_APP_REGION', 'default')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
$id = $response['body']['$id'];
|
||||||
|
|
||||||
|
$auth = require(__DIR__ . '/../../../../app/config/auth.php');
|
||||||
$originalEmail = uniqid() . 'user@localhost.test';
|
$originalEmail = uniqid() . 'user@localhost.test';
|
||||||
$originalPassword = 'password';
|
$originalPassword = 'password';
|
||||||
$originalName = 'User Name';
|
$originalName = 'User Name';
|
||||||
|
|
@ -1251,8 +1386,6 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
'status' => true,
|
'status' => true,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1457,9 +1590,6 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
$sessionCookie = $response['headers']['set-cookie'];
|
$sessionCookie = $response['headers']['set-cookie'];
|
||||||
$sessionId2 = $response['body']['$id'];
|
$sessionId2 = $response['body']['$id'];
|
||||||
|
|
||||||
// request was called in parallel and test failed
|
|
||||||
sleep(5);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List sessions
|
* List sessions
|
||||||
*/
|
*/
|
||||||
|
|
@ -3357,15 +3487,15 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
{
|
{
|
||||||
$id = $data['projectId'] ?? '';
|
$id = $data['projectId'] ?? '';
|
||||||
|
|
||||||
sleep(1);
|
$this->assertEventually(function () use ($id) {
|
||||||
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), []);
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms', array_merge([
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
'content-type' => 'application/json',
|
$this->assertEquals(8, $response['body']['total']);
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
});
|
||||||
], $this->getHeaders()), []);
|
|
||||||
|
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
|
||||||
$this->assertEquals(8, $response['body']['total']);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for FAILURE
|
* Test for FAILURE
|
||||||
|
|
@ -4015,16 +4145,16 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
|
|
||||||
$this->assertEquals(204, $project1['headers']['status-code']);
|
$this->assertEquals(204, $project1['headers']['status-code']);
|
||||||
|
|
||||||
\sleep(3);
|
|
||||||
|
|
||||||
// Ensure project 2 user is still there
|
// Ensure project 2 user is still there
|
||||||
$user2 = $this->client->call(Client::METHOD_GET, '/users/' . $user2['body']['$id'], [
|
$this->assertEventually(function () use ($user2, $project2Id, $key2) {
|
||||||
'content-type' => 'application/json',
|
$response = $this->client->call(Client::METHOD_GET, '/users/' . $user2['body']['$id'], [
|
||||||
'x-appwrite-project' => $project2Id,
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-key' => $key2['body']['secret'],
|
'x-appwrite-project' => $project2Id,
|
||||||
]);
|
'x-appwrite-key' => $key2['body']['secret'],
|
||||||
|
]);
|
||||||
|
|
||||||
$this->assertEquals(200, $user2['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
|
});
|
||||||
|
|
||||||
// Create another user in project 2 in case read hits stale cache
|
// Create another user in project 2 in case read hits stale cache
|
||||||
$user3 = $this->client->call(Client::METHOD_POST, '/users', [
|
$user3 = $this->client->call(Client::METHOD_POST, '/users', [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue