Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Nov 27, 2024
1 parent ae2e9fe commit b521e00
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/Protocols/Pusher/PusherPubSubIncomingMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public function handle(string $payload): void
$event = json_decode($payload, associative: true, flags: JSON_THROW_ON_ERROR);

$application = unserialize($event['application']);

$except = isset($event['socket_id']) ?
app(ChannelManager::class)->for($application)->connections()[$event['socket_id']] ?? null
: null;
$except = app(ChannelManager::class)->for($application)->connections()[$event['socket_id']] ?? null;

match ($event['type'] ?? null) {
'message' => EventDispatcher::dispatchSynchronously(
Expand Down
23 changes: 23 additions & 0 deletions tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@
expect($response->getBody()->getContents())->toBe('{}');
});

it('can ignore a subscriber when publishing events over redis', function () {
$this->usingRedis();

$connection = connect();
subscribe('test-channel-two', connection: $connection);
$response = await($this->signedPostRequest('events', [
'name' => 'NewEvent',
'channels' => ['test-channel-one', 'test-channel-two'],
'data' => json_encode(['some' => 'data']),
]));

$response = await($this->signedPostRequest('events', [
'name' => 'NewEvent',
'channels' => ['test-channel-one', 'test-channel-two'],
'data' => json_encode(['some' => 'data']),
'socket_id' => $connection->socketId(),
]));

$connection->assertReceived('{"event":"NewEvent","data":"{\"some\":\"data\"}","channel":"test-channel-two"}', 1);
expect($response->getStatusCode())->toBe(200);
expect($response->getBody()->getContents())->toBe('{}');
});

it('does not fail when ignoring an invalid subscriber', function () {
$connection = connect();
subscribe('test-channel-two', connection: $connection);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
app(ServerProviderManager::class)->withPublishing();
$pubSub = Mockery::mock(PubSubProvider::class);
$pubSub->shouldReceive('publish')->once()
->with(['type' => 'message', 'application' => serialize($app), 'payload' => ['channel' => 'test-channel']]);
->with(['type' => 'message', 'application' => serialize($app), 'payload' => ['channel' => 'test-channel'], 'socket_id' => null]);

$this->app->instance(PubSubProvider::class, $pubSub);

Expand Down

0 comments on commit b521e00

Please sign in to comment.