class AuthTest extends TestCase
{
use DatabaseMigrations;
public function testRegister()
{
$user = factory(User::class)->make(['password' => 'password123']);
$route = route('register');
$payload = [
'name' => $user->name,
'email' => $user->email,
'password' => $user->password,
'password_confirmation' => $user->password,
];
$this->post($route, $payload)->assertStatus(200);
}
public function testLogin()
{
\Artisan::call('passport:install');
$password = '1234567890';
$user = factory(User::class)->create(['password' => bcrypt($password)]);
$route = route('login');
$payload = [
'email' => $user->email,
'password' => $password,
];
$response = $this->post($route, $payload);
$response
->assertStatus(200)
->assertJsonStructure([
'data' => [
'token_type',
'token',
'expires_at',
],
]);
$responseToken = $response->json()['data']['token'];
$authedUser = Auth::user()->withAccessToken($responseToken);
$this->assertEquals($user->id, $authedUser->id);
}
public function testLogout()
{
\Artisan::call('passport:install');
$password = '1234567890';
$user = factory(User::class)->create(['password' => bcrypt($password)]);
$route = route('login');
$payload = [
'email' => $user->email,
'password' => $password,
];
$response = $this->post($route, $payload);
$route = route('logout');
$this->post($route /* LOGOUT */);
}
}