From a0ea0617f57a02f80d2a8a408508841c4e311e28 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Fri, 7 Dec 2018 20:38:17 +0100 Subject: [PATCH 1/2] Fix Pusher lib expecting empty object not array --- src/HttpApi/Controllers/FetchChannelsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HttpApi/Controllers/FetchChannelsController.php b/src/HttpApi/Controllers/FetchChannelsController.php index 937000e..22d8c1f 100644 --- a/src/HttpApi/Controllers/FetchChannelsController.php +++ b/src/HttpApi/Controllers/FetchChannelsController.php @@ -25,7 +25,7 @@ class FetchChannelsController extends Controller return [ 'user_count' => count($channel->getUsers()), ]; - })->toArray(), + })->toArray() ?: new \stdClass, ]; } } From 0a0c1249ebb72be5eaa15ef56c94783de56bcae1 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Fri, 7 Dec 2018 20:42:20 +0100 Subject: [PATCH 2/2] Add test --- tests/HttpApi/FetchChannelsTest.php | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/HttpApi/FetchChannelsTest.php b/tests/HttpApi/FetchChannelsTest.php index 088dabf..94a6eb8 100644 --- a/tests/HttpApi/FetchChannelsTest.php +++ b/tests/HttpApi/FetchChannelsTest.php @@ -80,4 +80,35 @@ class FetchChannelsTest extends TestCase ], ], json_decode($response->getContent(), true)); } + + /** @test */ + public function it_returns_empty_object_for_no_channels_found() + { + $connection = new Connection(); + + $auth_key = 'TestKey'; + $auth_timestamp = time(); + $auth_version = '1.0'; + + $queryParameters = http_build_query(compact('auth_key', 'auth_timestamp', 'auth_version')); + + $signature = + "GET\n/apps/1234/channels\n". + "auth_key={$auth_key}". + "&auth_timestamp={$auth_timestamp}". + "&auth_version={$auth_version}"; + + $auth_signature = hash_hmac('sha256', $signature, 'TestSecret'); + + $request = new Request('GET', "/apps/1234/channels?appId=1234&auth_signature={$auth_signature}&{$queryParameters}"); + + $controller = app(FetchChannelsController::class); + + $controller->onOpen($connection, $request); + + /** @var JsonResponse $response */ + $response = array_pop($connection->sentRawData); + + $this->assertSame('{"channels":{}}', $response->getContent()); + } }