Add test to ensure presence channel HTTP API responses are correct

This commit is contained in:
Alex Bouma 2020-09-15 18:28:39 +02:00
parent 331a127486
commit 0dde250b19
No known key found for this signature in database
GPG Key ID: AC101F160BEBEA17
2 changed files with 35 additions and 2 deletions

View File

@ -66,6 +66,39 @@ class FetchChannelTest extends TestCase
], 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 */
public function it_returns_404_for_invalid_channels()
{

View File

@ -89,14 +89,14 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
return $connection;
}
protected function joinPresenceChannel($channel): Connection
protected function joinPresenceChannel($channel, $userId = null): Connection
{
$connection = $this->getWebSocketConnection();
$this->pusherServer->onOpen($connection);
$channelData = [
'user_id' => 1,
'user_id' => $userId ?? 1,
'user_info' => [
'name' => 'Marcel',
],