Add failing test
This commit is contained in:
parent
00dd9b0b25
commit
1380f0ba0a
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace BeyondCode\LaravelWebSockets\Tests\Channels;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
|
||||
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
|
||||
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
||||
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\InvalidSignature;
|
||||
|
|
@ -42,16 +43,7 @@ class PresenceChannelTest extends TestCase
|
|||
],
|
||||
];
|
||||
|
||||
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
|
||||
'channel' => 'presence-channel',
|
||||
'channel_data' => json_encode($channelData),
|
||||
],
|
||||
]));
|
||||
$message = $this->getSignedMessage($connection, 'presence-channel', $channelData);
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
|
||||
|
|
@ -71,16 +63,7 @@ class PresenceChannelTest extends TestCase
|
|||
'user_id' => 1,
|
||||
];
|
||||
|
||||
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
|
||||
'channel' => 'presence-channel',
|
||||
'channel_data' => json_encode($channelData),
|
||||
],
|
||||
]));
|
||||
$message = $this->getSignedMessage($connection, 'presence-channel', $channelData);
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
|
||||
|
|
@ -88,4 +71,46 @@ class PresenceChannelTest extends TestCase
|
|||
'channel' => 'presence-channel',
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function multiple_clients_with_same_user_id_are_counted_once()
|
||||
{
|
||||
$this->pusherServer->onOpen($connection = $this->getWebSocketConnection());
|
||||
$this->pusherServer->onOpen($connection2 = $this->getWebSocketConnection());
|
||||
|
||||
$channelName = 'presence-channel';
|
||||
$channelData = [
|
||||
'user_id' => $userId = 1,
|
||||
];
|
||||
|
||||
$this->pusherServer->onMessage($connection, $this->getSignedMessage($connection, $channelName, $channelData));
|
||||
$this->pusherServer->onMessage($connection2, $this->getSignedMessage($connection2, $channelName, $channelData));
|
||||
|
||||
$connection2->assertSentEvent('pusher_internal:subscription_succeeded', [
|
||||
'channel' => $channelName,
|
||||
'data' => json_encode([
|
||||
'presence' => [
|
||||
'ids' => [(string)$userId],
|
||||
'hash' => [
|
||||
(string)$userId => [],
|
||||
],
|
||||
'count' => 1,
|
||||
],
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
private function getSignedMessage(Connection $connection, string $channelName, array $channelData): Message
|
||||
{
|
||||
$signature = "{$connection->socketId}:{$channelName}:" . json_encode($channelData);
|
||||
|
||||
return new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'auth' => $connection->app->key . ':' . hash_hmac('sha256', $signature, $connection->app->secret),
|
||||
'channel' => $channelName,
|
||||
'channel_data' => json_encode($channelData),
|
||||
],
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue