user disabled_at field addedù
This commit is contained in:
53
backend/tests/Feature/Auth/LoginTest.php
Normal file
53
backend/tests/Feature/Auth/LoginTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Verifica il gate di login custom (`App\Actions\Fortify\AuthenticateUser`),
|
||||
* registrato via `Fortify::authenticateUsing()`.
|
||||
*/
|
||||
class LoginTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_login_succeeds_with_valid_credentials(): void
|
||||
{
|
||||
$user = $this->operationalUser();
|
||||
|
||||
$this->postJson('/api/login', [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
])->assertOk()->assertJsonPath('two_factor', false);
|
||||
|
||||
$this->assertTrue(Auth::check());
|
||||
$this->assertSame($user->id, Auth::id());
|
||||
}
|
||||
|
||||
public function test_login_fails_with_wrong_password(): void
|
||||
{
|
||||
$user = $this->operationalUser();
|
||||
|
||||
$this->postJson('/api/login', [
|
||||
'email' => $user->email,
|
||||
'password' => 'wrong-password',
|
||||
])->assertUnprocessable();
|
||||
|
||||
$this->assertFalse(Auth::check());
|
||||
}
|
||||
|
||||
public function test_login_fails_for_disabled_user(): void
|
||||
{
|
||||
$user = $this->operationalUser(['disabled_at' => now()]);
|
||||
|
||||
$this->postJson('/api/login', [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
])->assertUnprocessable();
|
||||
|
||||
$this->assertFalse(Auth::check());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user