Skip to content

Instantly share code, notes, and snippets.

Created April 4, 2015 04:04
Show Gist options
  • Save anonymous/fe05253bf0364cde349b to your computer and use it in GitHub Desktop.
Save anonymous/fe05253bf0364cde349b to your computer and use it in GitHub Desktop.
<?php
$firstName = 'ApiGuy';
$email = 'user1@test.com';
$password = 'password';
$mobileNumber = '+61418888888';
$deviceType = 'ios';
$deviceId = '323dewd';
$I = new NoGuy($scenario);
$I->wantTo('Register a new user with insufficient credentials');
$data = json_encode(['User' => ['first_name' => $firstName, 'last_name' => 'dddd', 'password' => $password]]);
$I->sendPost('user/register', $data);
$I->seeResponseCodeIs(422);
$I = new NoGuy($scenario);
$I->wantTo('Register a new user');
$data = json_encode(['User' => ['first_name' => $firstName, 'last_name' => 'dddd', 'email' => $email, 'password' => $password, 'mobile_number' => $mobileNumber]]);
$I->sendPost('user/register', $data);
$I->seeResponseCodeIs(201);
$I->seeResponseContainsJson(['email' => $email]);
$I = new NoGuy($scenario);
$I->wantTo('Login with username and password');
$I->sendPost('user/login', json_encode(['email' =>$email, 'password' => $password, 'device_type' => $deviceType, 'device_id' => $deviceId]));
$I->seeResponseCodeIs(200);
$response = $I->grabDataFromJsonResponse();
$I = new NoGuy($scenario);
$I->wantTo('Fail to authenticate with false Bearer-Token');
$I->haveHttpHeader('Bearer-Token', 'ABCD1234');
$I->sendGet('user/test');
$I->seeResponseCodeIs(401);
$I = new NoGuy($scenario);
$I->wantTo('Authenticate with Bearer-Token');
$I->haveHttpHeader('Bearer-Token', $response['bearer_token']);
$I->sendGet('user/test');
$I->seeResponseCodeIs(200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment