54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?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());
|
|
}
|
|
}
|