Skip to content

Commit

Permalink
More test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
olotintemitope committed Apr 1, 2016
1 parent 9953f30 commit c6656ad
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Auth/Oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public function runRegisterUser($user, $userParams, $response)
* This method authenticate the user and log them in if the supplied
* credentials are valid.
*
* @param array $loginParams
*
* @return json jwt
*/
public function loginUser(Request $request, Response $response)
Expand Down Expand Up @@ -116,7 +114,12 @@ public function loginUser(Request $request, Response $response)
*/
public function logoutUser(Request $request, Response $response, $args)
{
return $response->withJson(['message' => 'Logout successful'], 200);
if ($args['logout']) {
return $response->withJson(['message' => 'Logout successful'], 200);

}

return $response->withJson(['message' => 'Logout not successful'], 400);
}

/**
Expand Down
36 changes: 36 additions & 0 deletions test/EmojiEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,42 @@ public function testDeleteEmoji()
$this->assertSame($response->getStatusCode(), 200);
}

public function testuserLogoutWithToken()
{
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/auth/logout',
'CONTENT_TYPE' => 'application/json',
'PATH_INFO' => '/auth',
'HTTP_AUTHORIZATION' => json_encode(['jwt' => $this->getCurrentToken()]),
]);

$req = Request::createFromEnvironment($env);
$this->app->getContainer()['request'] = $req;
$response = $this->app->run(true);

$data = json_decode($response->getBody(), true);
$this->assertSame($response->getStatusCode(), 200);
}

public function testuserWantToLogoutWithTokenButWithoutCorrectQueryParams()
{
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/auth/signout',
'CONTENT_TYPE' => 'application/json',
'PATH_INFO' => '/auth',
'HTTP_AUTHORIZATION' => json_encode(['jwt' => $this->getCurrentToken()]),
]);

$req = Request::createFromEnvironment($env);
$this->app->getContainer()['request'] = $req;
$response = $this->app->run(true);

$data = json_decode($response->getBody(), true);
$this->assertSame($response->getStatusCode(), 400);
}

public function testuserLogoutWithoutToken()
{
$env = Environment::mock([
Expand Down

0 comments on commit c6656ad

Please sign in to comment.