Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 0dde250

Browse files
committed
Add test to ensure presence channel HTTP API responses are correct
1 parent 331a127 commit 0dde250

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

tests/HttpApi/FetchChannelTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,39 @@ public function it_returns_the_channel_information()
6666
], json_decode($response->getContent(), true));
6767
}
6868

69+
/** @test */
70+
public function it_returns_the_channel_information_for_presence_channel()
71+
{
72+
$this->joinPresenceChannel('presence-global', 'user:1');
73+
$this->joinPresenceChannel('presence-global', 'user:2');
74+
$this->joinPresenceChannel('presence-global', 'user:2');
75+
76+
$connection = new Connection();
77+
78+
$requestPath = "/apps/1234/channel/presence-global";
79+
$routeParams = [
80+
'appId' => '1234',
81+
'channelName' => 'presence-global',
82+
];
83+
84+
$queryString = Pusher::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);
85+
86+
$request = new Request('GET', "{$requestPath}?{$queryString}&".http_build_query($routeParams));
87+
88+
$controller = app(FetchChannelController::class);
89+
90+
$controller->onOpen($connection, $request);
91+
92+
/** @var JsonResponse $response */
93+
$response = array_pop($connection->sentRawData);
94+
95+
$this->assertSame([
96+
'occupied' => true,
97+
'subscription_count' => 3,
98+
'user_count' => 2,
99+
], json_decode($response->getContent(), true));
100+
}
101+
69102
/** @test */
70103
public function it_returns_404_for_invalid_channels()
71104
{

tests/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ protected function getConnectedWebSocketConnection(array $channelsToJoin = [], s
8989
return $connection;
9090
}
9191

92-
protected function joinPresenceChannel($channel): Connection
92+
protected function joinPresenceChannel($channel, $userId = null): Connection
9393
{
9494
$connection = $this->getWebSocketConnection();
9595

9696
$this->pusherServer->onOpen($connection);
9797

9898
$channelData = [
99-
'user_id' => 1,
99+
'user_id' => $userId ?? 1,
100100
'user_info' => [
101101
'name' => 'Marcel',
102102
],

0 commit comments

Comments
 (0)