From a24702b4e18abe6c695b00d9f210e68dea7b5068 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 3 Jan 2022 15:01:35 +0100 Subject: [PATCH] fix: realtime tests --- app/realtime.php | 4 +-- tests/e2e/Services/Realtime/RealtimeBase.php | 29 ++++++-------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/app/realtime.php b/app/realtime.php index c4ac239a9c..2cb285a82b 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -366,10 +366,10 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, try { /** @var \Utopia\Database\Document $user */ - $user = $app->getResource('user', true); + $user = $app->getResource('user'); /** @var \Utopia\Database\Document $project */ - $project = $app->getResource('project', true); + $project = $app->getResource('project'); /** @var \Utopia\Database\Document $console */ $console = $app->getResource('console'); diff --git a/tests/e2e/Services/Realtime/RealtimeBase.php b/tests/e2e/Services/Realtime/RealtimeBase.php index b9d70b9f8c..2ea7233d5a 100644 --- a/tests/e2e/Services/Realtime/RealtimeBase.php +++ b/tests/e2e/Services/Realtime/RealtimeBase.php @@ -7,7 +7,7 @@ use WebSocket\Client as WebSocketClient; trait RealtimeBase { - private function getWebsocket($channels = [], $headers = [], $projectId = null) + private function getWebsocket($channels = [], $headers = [], $projectId = null): WebSocketClient { if (is_null($projectId)) { $projectId = $this->getProject()['$id']; @@ -28,7 +28,7 @@ trait RealtimeBase ]); } - public function testConnection() + public function testConnection(): void { /** * Test for SUCCESS @@ -36,8 +36,10 @@ trait RealtimeBase $client = $this->getWebsocket(['documents']); $this->assertNotEmpty($client->receive()); $client->close(); - sleep(1); + } + public function testConnectionFailureMissingChannels(): void + { /** * Test for FAILURE */ @@ -51,24 +53,10 @@ trait RealtimeBase $this->assertEquals('Missing channels', $payload['data']['message']); $this->expectException(ConnectionException::class); // Check if server disconnnected client $client->close(); - sleep(1); - - $client = new WebSocketClient('ws://appwrite-traefik/v1/realtime?channels[]=files"', [ - 'headers' => [ - 'Origin' => 'appwrite.test' - ] - ]); - $payload = json_decode($client->receive(), true); - - $this->assertArrayHasKey('type', $payload); - $this->assertArrayHasKey('data', $payload); - $this->assertEquals('error', $payload['type']); - $this->assertEquals(1008, $payload['data']['code']); - $this->assertEquals('Missing or unknown project ID', $payload['data']['message']); - $this->expectException(ConnectionException::class); // Check if server disconnnected client - $client->close(); - sleep(1); + } + public function testConnectionFailureUnknownProject(): void + { $client = new WebSocketClient('ws://appwrite-traefik/v1/realtime?project=123', [ 'headers' => [ 'Origin' => 'appwrite.test' @@ -83,6 +71,5 @@ trait RealtimeBase $this->assertEquals('Missing or unknown project ID', $payload['data']['message']); $this->expectException(ConnectionException::class); // Check if server disconnnected client $client->close(); - sleep(1); } }