mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
chore: use project injectable
This commit is contained in:
@@ -1061,18 +1061,7 @@ App::get('/v1/ping')
|
||||
->inject('dbForConsole')
|
||||
->inject('queueForEvents')
|
||||
->action(function (string $projectId, Response $response, Document $project, Database $dbForConsole, Event $queueForEvents) {
|
||||
if (empty($projectId) || $projectId === 'console') {
|
||||
throw new AppwriteException(AppwriteException::PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
Console::log('Ping' . json_encode(['projectId' => $projectId], JSON_PRETTY_PRINT));
|
||||
|
||||
$project = Authorization::skip(function () use ($dbForConsole, $projectId) {
|
||||
return $dbForConsole->getDocument('projects', $projectId);
|
||||
});
|
||||
|
||||
if ($project->isEmpty()) {
|
||||
Console::log('Ping' . json_encode($project, JSON_PRETTY_PRINT));
|
||||
throw new AppwriteException(AppwriteException::PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -1081,13 +1070,14 @@ App::get('/v1/ping')
|
||||
|
||||
$project
|
||||
->setAttribute('pingCount', $pingCount)
|
||||
->setAttribute('pingedAt', $pingedAt);
|
||||
->setAttribute('pingedAt', $pingedAt);
|
||||
|
||||
Authorization::skip(function () use ($dbForConsole, $project) {
|
||||
$dbForConsole->updateDocument('projects', $project->getId(), $project);
|
||||
});
|
||||
|
||||
$queueForEvents
|
||||
->setProject($project)
|
||||
->setParam('projectId', $projectId)
|
||||
->setPayload($response->output($project, Response::MODEL_PROJECT));
|
||||
|
||||
|
||||
@@ -18,25 +18,24 @@ class PingTest extends Scope
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
// Without user session
|
||||
$response = $this->client->call(Client::METHOD_GET, '/ping', [], [
|
||||
'projectId' => $this->getProject()['$id'],
|
||||
$response = $this->client->call(Client::METHOD_GET, '/ping', [
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('Pong!', $response['body']);
|
||||
|
||||
// With user session
|
||||
$response = $this->client->call(Client::METHOD_GET, '/ping', $this->getHeaders(), [
|
||||
'projectId' => $this->getProject()['$id'],
|
||||
]);
|
||||
$response = $this->client->call(Client::METHOD_GET, '/ping', array_merge([
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('Pong!', $response['body']);
|
||||
|
||||
// With API key
|
||||
$response = $this->client->call(Client::METHOD_GET, '/ping', [
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'projectId' => $this->getProject()['$id'],
|
||||
]);
|
||||
|
||||
/**
|
||||
@@ -44,10 +43,8 @@ class PingTest extends Scope
|
||||
*/
|
||||
// Fake project ID
|
||||
$response = $this->client->call(Client::METHOD_GET, '/ping', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
]), [
|
||||
'projectId' => 'fake-project-id',
|
||||
]);
|
||||
'x-appwrite-project' => 'fake-project-id',
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(404, $response['headers']['status-code']);
|
||||
$this->assertNotContains('Pong!', $response['body']);
|
||||
|
||||
@@ -478,6 +478,46 @@ class RealtimeConsoleClientTest extends Scope
|
||||
$client->close();
|
||||
}
|
||||
|
||||
public function testPing()
|
||||
{
|
||||
$client = $this->getWebsocket(['console'], [
|
||||
'origin' => 'http://localhost',
|
||||
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
||||
], 'console');
|
||||
|
||||
$response = json_decode($client->receive(), true);
|
||||
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertEquals('connected', $response['type']);
|
||||
|
||||
fwrite(STDOUT, 'Project ID: ' . $this->getProject()['$id'] . "\n");
|
||||
|
||||
$pong = $this->client->call(Client::METHOD_GET, '/ping', [
|
||||
'origin' => 'http://localhost',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $pong['headers']['status-code']);
|
||||
$this->assertEquals('Pong!', $pong['body']);
|
||||
|
||||
$response = json_decode($client->receive(), true);
|
||||
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertEquals('event', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertArrayHasKey('timestamp', $response['data']);
|
||||
$this->assertCount(1, $response['data']['channels']);
|
||||
$this->assertContains('console', $response['data']['channels']);
|
||||
$this->assertContains("projects.{$this->getProject()['$id']}", $response['data']['channels']);
|
||||
$this->assertContains("projects.{$this->getProject()['$id']}.ping", $response['data']['events']);
|
||||
$this->assertNotEmpty($response['data']['payload']);
|
||||
$this->assertArrayHasKey('pingCount', $response['data']['payload']);
|
||||
$this->assertArrayHasKey('pingedAt', $response['data']['payload']);
|
||||
$this->assertEquals(1, $response['data']['payload']['pingCount']);
|
||||
|
||||
$client->close();
|
||||
}
|
||||
|
||||
public function testCreateDeployment()
|
||||
{
|
||||
$response1 = $this->client->call(Client::METHOD_POST, '/functions', array_merge([
|
||||
|
||||
Reference in New Issue
Block a user