user disabled_at field addedù

This commit is contained in:
Giuseppe Naponiello
2026-06-24 17:02:11 +02:00
parent 96b0dc76aa
commit f8206b5840
5 changed files with 120 additions and 0 deletions

View 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());
}
}