diff --git a/tests/Feature/Protocols/Pusher/Reverb/ChannelControllerTest.php b/tests/Feature/Protocols/Pusher/Reverb/ChannelControllerTest.php index ca397ec0..ea810525 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/ChannelControllerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/ChannelControllerTest.php @@ -59,6 +59,15 @@ expect($response->getBody()->getContents())->toBe('{"occupied":true,"subscription_count":1}'); }); +it('can send the content-length header', function () { + subscribe('test-channel-one'); + subscribe('test-channel-one'); + + $response = await($this->signedRequest('channels/test-channel-one?info=user_count,subscription_count,cache')); + + expect($response->getHeader('Content-Length'))->toBe(['40']); +}); + it('can gather data for a single channel', function () { $this->usingRedis(); @@ -121,3 +130,14 @@ expect($response->getStatusCode())->toBe(200); expect($response->getBody()->getContents())->toBe('{"occupied":true,"subscription_count":1}'); }); + +it('can send the content-length header when gathering results', function () { + $this->usingRedis(); + + subscribe('test-channel-one'); + subscribe('test-channel-one'); + + $response = await($this->signedRequest('channels/test-channel-one?info=user_count,subscription_count,cache')); + + expect($response->getHeader('Content-Length'))->toBe(['40']); +}); diff --git a/tests/Feature/Protocols/Pusher/Reverb/ChannelUsersControllerTest.php b/tests/Feature/Protocols/Pusher/Reverb/ChannelUsersControllerTest.php index 7a9d31c9..e8ebcb9a 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/ChannelUsersControllerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/ChannelUsersControllerTest.php @@ -61,6 +61,19 @@ await($this->signedRequest('channels/presence-test-channel/users')); })->throws(ResponseException::class); +it('can send the content-length header', function () { + $channel = app(ChannelManager::class) + ->for(app()->make(ApplicationProvider::class)->findByKey('reverb-key')) + ->findOrCreate('presence-test-channel'); + $channel->subscribe($connection = new FakeConnection('test-connection-one'), validAuth($connection->id(), 'presence-test-channel', $data = json_encode(['user_id' => 1, 'user_info' => ['name' => 'Taylor']])), $data); + $channel->subscribe($connection = new FakeConnection('test-connection-two'), validAuth($connection->id(), 'presence-test-channel', $data = json_encode(['user_id' => 2, 'user_info' => ['name' => 'Joe']])), $data); + $channel->subscribe($connection = new FakeConnection('test-connection-three'), validAuth($connection->id(), 'presence-test-channel', $data = json_encode(['user_id' => 3, 'user_info' => ['name' => 'Jess']])), $data); + + $response = await($this->signedRequest('channels/presence-test-channel/users')); + + expect($response->getHeader('Content-Length'))->toBe(['38']); +}); + it('gathers the user data', function () { $this->usingRedis(); @@ -92,3 +105,18 @@ expect($response->getStatusCode())->toBe(200); expect($response->getBody()->getContents())->toBe('{"users":[{"id":2},{"id":3}]}'); }); + +it('can send the content-length header when gathering results', function () { + $this->usingRedis(); + + $channel = app(ChannelManager::class) + ->for(app()->make(ApplicationProvider::class)->findByKey('reverb-key')) + ->findOrCreate('presence-test-channel'); + $channel->subscribe($connection = new FakeConnection('test-connection-one'), validAuth($connection->id(), 'presence-test-channel', $data = json_encode(['user_id' => 1, 'user_info' => ['name' => 'Taylor']])), $data); + $channel->subscribe($connection = new FakeConnection('test-connection-two'), validAuth($connection->id(), 'presence-test-channel', $data = json_encode(['user_id' => 2, 'user_info' => ['name' => 'Joe']])), $data); + $channel->subscribe($connection = new FakeConnection('test-connection-three'), validAuth($connection->id(), 'presence-test-channel', $data = json_encode(['user_id' => 3, 'user_info' => ['name' => 'Jess']])), $data); + + $response = await($this->signedRequest('channels/presence-test-channel/users')); + + expect($response->getHeader('Content-Length'))->toBe(['38']); +}); diff --git a/tests/Feature/Protocols/Pusher/Reverb/ChannelsControllerTest.php b/tests/Feature/Protocols/Pusher/Reverb/ChannelsControllerTest.php index 7759d5b1..232115ed 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/ChannelsControllerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/ChannelsControllerTest.php @@ -51,6 +51,15 @@ expect($response->getBody()->getContents())->toBe('{"channels":{"test-channel-two":{}}}'); }); +it('can send the content-length header', function () { + subscribe('test-channel-one'); + subscribe('presence-test-channel-two'); + + $response = await($this->signedRequest('channels?info=user_count')); + + expect($response->getHeader('Content-Length'))->toBe(['81']); +}); + it('can gather all channel information', function () { $this->usingRedis(); @@ -102,3 +111,14 @@ expect($response->getStatusCode())->toBe(200); expect($response->getBody()->getContents())->toBe('{"channels":{"test-channel-two":{}}}'); }); + +it('can send the content-length header when gathering results', function () { + $this->usingRedis(); + + subscribe('test-channel-one'); + subscribe('presence-test-channel-two'); + + $response = await($this->signedRequest('channels?info=user_count')); + + expect($response->getHeader('Content-Length'))->toBe(['81']); +}); diff --git a/tests/Feature/Protocols/Pusher/Reverb/ConnectionsControllerTest.php b/tests/Feature/Protocols/Pusher/Reverb/ConnectionsControllerTest.php index 345cfa96..b08afc8a 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/ConnectionsControllerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/ConnectionsControllerTest.php @@ -27,6 +27,15 @@ expect($response->getBody()->getContents())->toBe('{"connections":1}'); }); +it('can send the content-length header', function () { + subscribe('test-channel-one'); + subscribe('presence-test-channel-two'); + + $response = await($this->signedRequest('connections')); + + expect($response->getHeader('Content-Length'))->toBe(['17']); +}); + it('can gather a connection count', function () { $this->usingRedis(); @@ -51,3 +60,14 @@ expect($response->getStatusCode())->toBe(200); expect($response->getBody()->getContents())->toBe('{"connections":1}'); }); + +it('can send the content-length header when gathering results', function () { + $this->usingRedis(); + + subscribe('test-channel-one'); + subscribe('presence-test-channel-two'); + + $response = await($this->signedRequest('connections')); + + expect($response->getHeader('Content-Length'))->toBe(['17']); +}); \ No newline at end of file diff --git a/tests/Feature/Protocols/Pusher/Reverb/EventsBatchControllerTest.php b/tests/Feature/Protocols/Pusher/Reverb/EventsBatchControllerTest.php index 2aadf7dc..efa6c631 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/EventsBatchControllerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/EventsBatchControllerTest.php @@ -87,6 +87,18 @@ expect($response->getBody()->getContents())->toBe('{"batch":[{"user_count":1},{}]}'); }); +it('can send the content-length header', function () { + $response = await($this->signedPostRequest('batch_events', ['batch' => [ + [ + 'name' => 'NewEvent', + 'channel' => 'test-channel', + 'data' => json_encode(['some' => 'data']), + ], + ]])); + + expect($response->getHeader('Content-Length'))->toBe(['12']); +}); + it('can receive an event batch trigger with multiple events and gather info for each', function () { $this->usingRedis(); @@ -145,3 +157,17 @@ expect($response->getStatusCode())->toBe(500); })->throws(ResponseException::class, exceptionCode: 500); + +it('can send the content-length header when gathering results', function () { + $this->usingRedis(); + + $response = await($this->signedPostRequest('batch_events', ['batch' => [ + [ + 'name' => 'NewEvent', + 'channel' => 'test-channel', + 'data' => json_encode(['some' => 'data']), + ], + ]])); + + expect($response->getHeader('Content-Length'))->toBe(['12']); +}); diff --git a/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php b/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php index f6df3122..a34487c0 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php @@ -197,3 +197,13 @@ it('fails when app cannot be found', function () { await($this->signedPostRequest('events', appId: 'invalid-app-id')); })->throws(ResponseException::class, exceptionCode: 404); + +it('can send the content-length header', function () { + $response = await($this->signedPostRequest('events', [ + 'name' => 'NewEvent', + 'channel' => 'test-channel', + 'data' => json_encode(['some' => 'data']), + ])); + + expect($response->getHeader('Content-Length'))->toBe(['2']); +}); diff --git a/tests/Feature/Protocols/Pusher/Reverb/UsersTerminateControllerTest.php b/tests/Feature/Protocols/Pusher/Reverb/UsersTerminateControllerTest.php index 9dd3ec18..99851799 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/UsersTerminateControllerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/UsersTerminateControllerTest.php @@ -29,6 +29,7 @@ expect($response->getBody()->getContents())->toBe('{}'); expect(collect(channels()->all())->get('presence-test-channel-one')->connections())->toHaveCount(1); expect(collect(channels()->all())->get('test-channel-two')->connections())->toHaveCount(1); + expect($response->getHeader('Content-Length'))->toBe(['2']); }); it('unsubscribes from all channels across all servers and terminates a user', function () { @@ -51,4 +52,5 @@ expect($response->getBody()->getContents())->toBe('{}'); expect(collect(channels()->all())->get('presence-test-channel-one')->connections())->toHaveCount(1); expect(collect(channels()->all())->get('test-channel-two')->connections())->toHaveCount(1); + expect($response->getHeader('Content-Length'))->toBe(['2']); });