44 lines
1.0 KiB
PHP
44 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Auth;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class LoginControllerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_login_success_returns_user(): void
|
|
{
|
|
$user = $this->createUser([
|
|
'password' => 'demodemo',
|
|
]);
|
|
|
|
$response = $this->withSession([])->postJson('/api/login', [
|
|
'email' => $user->email,
|
|
'password' => 'demodemo',
|
|
]);
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonFragment([
|
|
'id' => $user->id,
|
|
'email' => $user->email,
|
|
]);
|
|
}
|
|
|
|
public function test_login_inactive_user_fails(): void
|
|
{
|
|
$user = $this->createInactiveUser([
|
|
'password' => 'demodemo',
|
|
]);
|
|
|
|
$response = $this->withSession([])->postJson('/api/login', [
|
|
'email' => $user->email,
|
|
'password' => 'demodemo',
|
|
]);
|
|
|
|
$response->assertStatus(422);
|
|
}
|
|
}
|