Skip to content

Commit

Permalink
Revamp unregisterAction in plain POST style.
Browse files Browse the repository at this point in the history
  • Loading branch information
hswong3i committed Oct 11, 2014
1 parent 85fbd45 commit 593cac8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
17 changes: 11 additions & 6 deletions src/AuthBucket/Push/Controller/PushController.php
Expand Up @@ -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,
Expand All @@ -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',
));
}

Expand Down
16 changes: 8 additions & 8 deletions tests/AuthBucket/Push/Tests/Controller/PushControllerTest.php
Expand Up @@ -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']);
}
}

0 comments on commit 593cac8

Please sign in to comment.