Skip to content

Instantly share code, notes, and snippets.

@fityanos
Last active November 17, 2018 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fityanos/5667116d8130fe8d0fc3ede87786217a to your computer and use it in GitHub Desktop.
Save fityanos/5667116d8130fe8d0fc3ede87786217a to your computer and use it in GitHub Desktop.
example test file
<?php
use \Codeception\Util\HttpCode as status;
/**
* Class invalidXauthAndAuthCest
*
* how to run =>
* codecept run api --env envName -g invalidXauthAndAuth --steps [execution with detailed steps]
* ********
* codecept run api --env envName -g invalidXauthAndAuth -d [execution with debugging]
* ********
* codecept run api --env envName -g invalidXauthAndAuth --json [execution and save JSON result in _output__DIR__]
* ********
* codecept run api --env envName -g invalidXauthAndAuth --report [execution and save report in _output __DIR__]
*
* @group appsApi
* @group appsApiAuth
* @group appsApiAuthToken
* @group appsApiAuthTokenBooking
* @group invalidXauthAndAuth
*/
class invalidXauthAndAuthCest
{
/**
* @param ApiGuy $I
* @throws Exception
*
* @tr-suite 294
* @tr-case 259586
*/
public function searchUsingExpiredToken(ApiGuy $I)
{
/** @var => Get auth-token and store it in $token */
$firstHashToken = $I->getAuthTokenNativeApps();
$usrToken = $I->getLocalToken();
$I->haveHttpHeader('x-authorization', 'spiderMan' . $firstHashToken);
$I->haveHttpHeader('authorization', 'invalid' . $usrToken);
// >>>>>>>>>> API CALL <<<<<<<<<<
$I->sendGET('/hotel/order/user');
// Assertions for status code && JSON body
$I->seeResponseIsJson();
$I->canSeeResponseCodeIsClientError();
$I->seeResponseCodeIs(status::UNAUTHORIZED); // 401
}
/**
* @param ApiGuy $I
* @throws Exception
*/
public function regenerateToken(ApiGuy $I)
{
// Regenerate another token and test
$secondHashToken = $I->getAuthTokenNativeApps();
$I->haveHttpHeader('x-authorization', $secondHashToken);
// >>>>>>>>>> API CALL <<<<<<<<<<
$I->sendGET('/hotel/order/user');
// Assertions for status code && JSON body
$I->seeResponseIsJson();
$I->seeResponseCodeIs(status::OK); // 200
// I should get empty Array
$I->seeResponseContainsJson([]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment