Skip to content

Instantly share code, notes, and snippets.

@PhillJaySaw
Created March 24, 2020 12:38
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 PhillJaySaw/3b4b126f450b8423bf049a4f54a22fca to your computer and use it in GitHub Desktop.
Save PhillJaySaw/3b4b126f450b8423bf049a4f54a22fca to your computer and use it in GitHub Desktop.
class AuthCest
{
// tests
public function validCredentials(ApiTester $I)
{
$I->wantTo('Generate access token');
$email = uniqid('email-') . '@gmail.com';
$password = uniqid('password-');
// create user in database
$userId = $I->createUser([
'email' => $email,
'password' => $password
]);
// generate access token via API
$I->haveHttpHeader('Content-Type', 'application/json');
$I->sendPOST('/api/v1/auth/authenticate', ['email' => $email, 'password' => $password]);
// validate response
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
$I->seeResponseIsJson();
$I->seeResponseJsonMatchesJsonPath('$.token');
$I->seeResponseJsonMatchesJsonPath('$.userId');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment