Initial commit
This commit is contained in:
38
tests/Feature/LoginTest.php
Normal file
38
tests/Feature/LoginTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
it('can login to Forms', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->postJson('/api/login', [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
])
|
||||
->assertSuccessful()
|
||||
->assertJsonStructure(['token', 'expires_in'])
|
||||
->assertJson(['token_type' => 'bearer']);
|
||||
});
|
||||
|
||||
it('can fetch current user', function () {
|
||||
$this->actingAs(User::factory()->create())
|
||||
->getJson('/api/user')
|
||||
->assertSuccessful()
|
||||
->assertJsonStructure(['id', 'name', 'email']);
|
||||
});
|
||||
|
||||
it('can log out', function () {
|
||||
$this->postJson('/api/login', [
|
||||
'email' => User::factory()->create()->email,
|
||||
'password' => 'password',
|
||||
])->assertSuccessful();
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$this->postJson("/api/logout")
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertGuest();
|
||||
$this->getJson("/api/user")
|
||||
->assertStatus(401);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user