fix: realtime event

This commit is contained in:
loks0n
2024-10-07 15:58:34 +01:00
parent de509c6928
commit e0bd500aa2
4 changed files with 14 additions and 10 deletions
+4 -7
View File
@@ -30,7 +30,6 @@ use Utopia\Database\Document;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization;
use Utopia\Database\Validator\UID;
use Utopia\Domains\Domain;
use Utopia\DSN\DSN;
use Utopia\Locale\Locale;
@@ -1053,14 +1052,13 @@ include_once __DIR__ . '/shared/api/auth.php';
App::get('/v1/ping')
->groups(['api', 'general'])
->desc('Test the connection between the Appwrite and the SDK.')
->label('scope', 'public')
->label('scope', 'global')
->label('event', 'projects.[projectId].ping')
->param('projectId', '', new UID(), 'Project unique ID.')
->inject('response')
->inject('console')
->inject('project')
->inject('dbForConsole')
->inject('queueForEvents')
->action(function (string $projectId, Response $response, Document $project, Database $dbForConsole, Event $queueForEvents) {
->action(function (Response $response, Document $project, Database $dbForConsole, Event $queueForEvents) {
if ($project->isEmpty()) {
throw new AppwriteException(AppwriteException::PROJECT_NOT_FOUND);
}
@@ -1077,8 +1075,7 @@ App::get('/v1/ping')
});
$queueForEvents
->setProject($project)
->setParam('projectId', $projectId)
->setParam('projectId', $project->getId())
->setPayload($response->output($project, Response::MODEL_PROJECT));
$response->text('Pong!');
@@ -270,6 +270,12 @@ class Realtime extends Adapter
$projectId = 'console';
$roles = [Role::team($project->getAttribute('teamId'))->toString()];
break;
case 'projects':
$channels[] = 'console';
$channels[] = 'projects.' . $parts[1];
$projectId = 'console';
$roles = [Role::team($project->getAttribute('teamId'))->toString()];
break;
case 'teams':
if ($parts[2] === 'memberships') {
$permissionsChanged = $parts[4] ?? false;
+3
View File
@@ -38,6 +38,9 @@ class PingTest extends Scope
'x-appwrite-key' => $this->getProject()['apiKey'],
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('Pong!', $response['body']);
/**
* Test for FAILURE
*/
@@ -490,8 +490,6 @@ class RealtimeConsoleClientTest extends Scope
$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'],
@@ -506,7 +504,7 @@ class RealtimeConsoleClientTest extends Scope
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertCount(1, $response['data']['channels']);
$this->assertCount(2, $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']);