Add test to ensure presence channel HTTP API responses are correct
This commit is contained in:
parent
331a127486
commit
0dde250b19
|
|
@ -66,6 +66,39 @@ class FetchChannelTest extends TestCase
|
||||||
], json_decode($response->getContent(), true));
|
], json_decode($response->getContent(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function it_returns_the_channel_information_for_presence_channel()
|
||||||
|
{
|
||||||
|
$this->joinPresenceChannel('presence-global', 'user:1');
|
||||||
|
$this->joinPresenceChannel('presence-global', 'user:2');
|
||||||
|
$this->joinPresenceChannel('presence-global', 'user:2');
|
||||||
|
|
||||||
|
$connection = new Connection();
|
||||||
|
|
||||||
|
$requestPath = "/apps/1234/channel/presence-global";
|
||||||
|
$routeParams = [
|
||||||
|
'appId' => '1234',
|
||||||
|
'channelName' => 'presence-global',
|
||||||
|
];
|
||||||
|
|
||||||
|
$queryString = Pusher::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);
|
||||||
|
|
||||||
|
$request = new Request('GET', "{$requestPath}?{$queryString}&".http_build_query($routeParams));
|
||||||
|
|
||||||
|
$controller = app(FetchChannelController::class);
|
||||||
|
|
||||||
|
$controller->onOpen($connection, $request);
|
||||||
|
|
||||||
|
/** @var JsonResponse $response */
|
||||||
|
$response = array_pop($connection->sentRawData);
|
||||||
|
|
||||||
|
$this->assertSame([
|
||||||
|
'occupied' => true,
|
||||||
|
'subscription_count' => 3,
|
||||||
|
'user_count' => 2,
|
||||||
|
], json_decode($response->getContent(), true));
|
||||||
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function it_returns_404_for_invalid_channels()
|
public function it_returns_404_for_invalid_channels()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -89,14 +89,14 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
return $connection;
|
return $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function joinPresenceChannel($channel): Connection
|
protected function joinPresenceChannel($channel, $userId = null): Connection
|
||||||
{
|
{
|
||||||
$connection = $this->getWebSocketConnection();
|
$connection = $this->getWebSocketConnection();
|
||||||
|
|
||||||
$this->pusherServer->onOpen($connection);
|
$this->pusherServer->onOpen($connection);
|
||||||
|
|
||||||
$channelData = [
|
$channelData = [
|
||||||
'user_id' => 1,
|
'user_id' => $userId ?? 1,
|
||||||
'user_info' => [
|
'user_info' => [
|
||||||
'name' => 'Marcel',
|
'name' => 'Marcel',
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue