opnform/tests/Feature/LoginTest.php

38 lines
923 B
PHP
Raw Normal View History

2022-09-20 19:59:52 +00:00
<?php
use App\Models\User;
it('can login to Forms', function () {
$user = User::factory()->create();
2024-01-14 19:52:14 +00:00
$this->postJson('/login', [
2024-02-23 10:54:12 +00:00
'email' => $user->email,
'password' => 'password',
])
2022-09-20 19:59:52 +00:00
->assertSuccessful()
->assertJsonStructure(['token', 'expires_in'])
->assertJson(['token_type' => 'bearer']);
});
it('can fetch current user', function () {
$this->actingAs(User::factory()->create())
2024-01-14 19:52:14 +00:00
->getJson('/user')
2022-09-20 19:59:52 +00:00
->assertSuccessful()
->assertJsonStructure(['id', 'name', 'email']);
});
it('can log out', function () {
2024-01-14 19:52:14 +00:00
$this->postJson('/login', [
2022-09-20 19:59:52 +00:00
'email' => User::factory()->create()->email,
'password' => 'password',
])->assertSuccessful();
$this->assertAuthenticated();
2024-02-23 10:54:12 +00:00
$this->postJson('/logout')
2022-09-20 19:59:52 +00:00
->assertSuccessful();
$this->assertGuest();
2024-02-23 10:54:12 +00:00
$this->getJson('/user')
2022-09-20 19:59:52 +00:00
->assertStatus(401);
});