opnform/tests/Feature/LoginTest.php

39 lines
936 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', [
2022-09-20 19:59:52 +00:00
'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())
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-01-14 19:52:14 +00:00
$this->postJson("/logout")
2022-09-20 19:59:52 +00:00
->assertSuccessful();
$this->assertGuest();
2024-01-14 19:52:14 +00:00
$this->getJson("/user")
2022-09-20 19:59:52 +00:00
->assertStatus(401);
});