Skip to content

Commit

Permalink
test content-length
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Apr 23, 2024
1 parent 3e0ca9b commit e9382c5
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/Feature/Protocols/Pusher/Reverb/ChannelControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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']);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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']);
});
20 changes: 20 additions & 0 deletions tests/Feature/Protocols/Pusher/Reverb/ChannelsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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']);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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']);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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']);
});
10 changes: 10 additions & 0 deletions tests/Feature/Protocols/Pusher/Reverb/EventsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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']);
});

0 comments on commit e9382c5

Please sign in to comment.