e2e testrun
This commit is contained in:
parent
0f6e33f4ed
commit
fd462d831c
|
@ -63,6 +63,7 @@
|
||||||
"phpunit/phpunit": "9.4.2",
|
"phpunit/phpunit": "9.4.2",
|
||||||
"ratchet/pawl": "0.3.5",
|
"ratchet/pawl": "0.3.5",
|
||||||
"swoole/ide-helper": "4.5.5",
|
"swoole/ide-helper": "4.5.5",
|
||||||
|
"textalk/websocket": "1.5.2",
|
||||||
"vimeo/psalm": "4.1.1"
|
"vimeo/psalm": "4.1.1"
|
||||||
},
|
},
|
||||||
"repositories": [
|
"repositories": [
|
||||||
|
|
1404
composer.lock
generated
1404
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -2,43 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\E2E\Services\Realtime;
|
namespace Tests\E2E\Services\Realtime;
|
||||||
|
|
||||||
use Ratchet;
|
|
||||||
use Ratchet\RFC6455\Messaging\MessageInterface;
|
|
||||||
|
|
||||||
trait RealtimeBase
|
trait RealtimeBase
|
||||||
{
|
{
|
||||||
private function getWebsocket($channels = []) {
|
|
||||||
$query = [
|
|
||||||
'project' => $this->getProject()['$id'],
|
|
||||||
'channels' => $channels
|
|
||||||
];
|
|
||||||
return 'ws://appwrite-traefik/v1/realtime?' . http_build_query($query);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testHandshake()
|
}
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Test for SUCCESS
|
|
||||||
*/
|
|
||||||
Ratchet\Client\connect($this->getWebsocket(['documents']), [], ['origin' => 'appwrite.test'])->then(function($conn) {
|
|
||||||
$conn->on('message', function(MessageInterface $msg) use ($conn) {
|
|
||||||
$this->assertEquals('{"documents":0}', $msg->__toString());
|
|
||||||
$conn->close();
|
|
||||||
});
|
|
||||||
}, function ($e) {
|
|
||||||
echo "Could not connect: {$e->getMessage()}\n";
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for FAILURE
|
|
||||||
*/
|
|
||||||
Ratchet\Client\connect($this->getWebsocket(['account']), [], ['origin' => 'appwrite.test'])->then(function($conn) {
|
|
||||||
$conn->on('message', function(Message $msg) use ($conn) {
|
|
||||||
$this->assertEquals('Missing channels', $msg->__toString());
|
|
||||||
$conn->close();
|
|
||||||
});
|
|
||||||
}, function ($e) {
|
|
||||||
echo "Could not connect: {$e->getMessage()}\n";
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,9 +7,57 @@ use Tests\E2E\Scopes\Scope;
|
||||||
use Tests\E2E\Scopes\ProjectCustom;
|
use Tests\E2E\Scopes\ProjectCustom;
|
||||||
use Tests\E2E\Scopes\SideClient;
|
use Tests\E2E\Scopes\SideClient;
|
||||||
|
|
||||||
|
use WebSocket\Client as WebSocketClient;
|
||||||
|
use WebSocket\ConnectionException;
|
||||||
|
|
||||||
class RealtimeCustomClientTest extends Scope
|
class RealtimeCustomClientTest extends Scope
|
||||||
{
|
{
|
||||||
use RealtimeBase;
|
use RealtimeBase;
|
||||||
use ProjectCustom;
|
use ProjectCustom;
|
||||||
use SideClient;
|
use SideClient;
|
||||||
|
|
||||||
|
private function getWebsocket($channels = [], $headers = [])
|
||||||
|
{
|
||||||
|
$headers = array_merge(
|
||||||
|
['Origin' => 'http://appwrite.test'],
|
||||||
|
$headers
|
||||||
|
);
|
||||||
|
$query = [
|
||||||
|
'project' => $this->getProject()['$id'],
|
||||||
|
'channels' => $channels
|
||||||
|
];
|
||||||
|
return new WebSocketClient('ws://appwrite-traefik/v1/realtime?' . http_build_query($query), [
|
||||||
|
'headers' => $headers,
|
||||||
|
'timeout' => 5,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConnection()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test for SUCCESS
|
||||||
|
*/
|
||||||
|
$client = $this->getWebsocket(['documents']);
|
||||||
|
$this->assertEquals('{"documents":0}', $client->receive());
|
||||||
|
$client->close();
|
||||||
|
|
||||||
|
$client = $this->getWebsocket(['documents'], ['Origin' => 'http://appwrite.unknown']);
|
||||||
|
$this->assertEquals('Invalid Origin. Register your new client (appwrite.unknown) as a new Web platform on your project console dashboard', $client->receive());
|
||||||
|
$this->expectException(ConnectionException::class); // Check if server disconnnected client
|
||||||
|
$client->close();
|
||||||
|
|
||||||
|
$client = $this->getWebsocket();
|
||||||
|
$this->assertEquals('Missing channels', $client->receive());
|
||||||
|
$this->expectException(ConnectionException::class); // Check if server disconnnected client
|
||||||
|
$client->close();
|
||||||
|
|
||||||
|
$client = new WebSocketClient('ws://appwrite-traefik/v1/realtime', [
|
||||||
|
'headers' => [
|
||||||
|
'Origin' => 'appwrite.test'
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
$this->assertEquals('Missing or unknown project ID', $client->receive());
|
||||||
|
$this->expectException(ConnectionException::class); // Check if server disconnnected client
|
||||||
|
$client->close();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue