diff --git a/src/AuthBucket/Push/Controller/PushController.php b/src/AuthBucket/Push/Controller/PushController.php index e88ad4d..21bf168 100644 --- a/src/AuthBucket/Push/Controller/PushController.php +++ b/src/AuthBucket/Push/Controller/PushController.php @@ -102,9 +102,11 @@ public function unregisterAction(Request $request) { $clientId = $this->checkClientId(); + $serviceId = $this->checkServiceId($request, $clientId); + $deviceToken = $this->checkDeviceToken($request); - // Remove all legacy record for this deviceToken. + // Remove all legacy record for this device_token. $deviceManager = $this->modelManagerFactory->getModelManager('device'); $devices = $deviceManager->readModelBy(array( 'deviceToken' => $deviceToken, @@ -114,12 +116,15 @@ public function unregisterAction(Request $request) $deviceManager->deleteModel($device); } - $format = $request->getRequestFormat(); - - $deviceSupplied = $this->checkDevice($request); + // Prepare parameters for JSON response. + $parameters = array( + 'device_token' => $deviceToken, + 'service_id' => $serviceId, + ); - return new Response($this->serializer->serialize($deviceSupplied, $format), 200, array( - "Content-Type" => $request->getMimeType($format), + return JsonResponse::create($parameters, 200, array( + 'Cache-Control' => 'no-store', + 'Pragma' => 'no-cache', )); } diff --git a/tests/AuthBucket/Push/Tests/Controller/PushControllerTest.php b/tests/AuthBucket/Push/Tests/Controller/PushControllerTest.php index b167e90..a31c013 100644 --- a/tests/AuthBucket/Push/Tests/Controller/PushControllerTest.php +++ b/tests/AuthBucket/Push/Tests/Controller/PushControllerTest.php @@ -32,19 +32,19 @@ public function testGoodRegister() $this->assertEquals('0027956241e3ca5090de548fe468334d', $response['device_token']); } - public function _testGoodUnrgister() + public function testGoodUnrgister() { + $parameters = array( + 'device_token' => '0027956241e3ca5090de548fe468334d', + 'service_id' => 'f2ee1d163e9c9b633efca95fb9733f35', + ); $server = array( 'HTTP_Authorization' => 'Bearer 18cdaa6481c0d5f323351ea1029fc065', ); - $content = $this->app['serializer']->encode(array( - 'deviceToken' => '0027956241e3ca5090de548fe468334d', - 'serviceId' => 'f2ee1d163e9c9b633efca95fb9733f35', - ), 'json'); $client = $this->createClient(); - $crawler = $client->request('POST', '/api/v1.0/push/unregister.json', array(), array(), $server, $content); + $crawler = $client->request('POST', '/api/v1.0/push/unregister', $parameters, array(), $server); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'json'); - $this->assertEquals('0027956241e3ca5090de548fe468334d', $response['deviceToken']); + $response = json_decode($client->getResponse()->getContent(), true); + $this->assertEquals('0027956241e3ca5090de548fe468334d', $response['device_token']); } }