forked from eatvio/eatvio-infra
68 lines
1.5 KiB
PHP
68 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Api\Auth;
|
|
|
|
use App\Models\User;
|
|
use App\Models\UserDetailz;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Testing\Fluent\AssertableJson;
|
|
use Tests\TestCase;
|
|
|
|
class LoginTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected User $user;
|
|
|
|
public function setUp(): void
|
|
{
|
|
$this->refreshApplicationWithLocale('en');
|
|
|
|
$this->user = User::factory()->create();
|
|
}
|
|
|
|
public function test_login_success()
|
|
{
|
|
$response = $this
|
|
->actingAs($this->user)
|
|
->postJson('/api/login', [
|
|
'email' => $this->user->email,
|
|
'password' => 'password',
|
|
]);
|
|
|
|
// Assert a token was returned
|
|
$response->assertStatus(200);
|
|
$response->assertJsonStructure(['token']);
|
|
}
|
|
|
|
|
|
public function test_login_failed_no_register_user()
|
|
{
|
|
$user = User::factory()->make();
|
|
|
|
$response = $this
|
|
->postJson('/api/login', [
|
|
'email' => $user->email,
|
|
'password' => 'password',
|
|
]);
|
|
|
|
// Assert a token was returned
|
|
$response->assertStatus(401);
|
|
}
|
|
|
|
|
|
public function test_login_failed_error_password()
|
|
{
|
|
$response = $this
|
|
->actingAs($this->user)
|
|
->postJson('/api/login', [
|
|
'email' => $this->user->email,
|
|
'password' => '1234567890',
|
|
]);
|
|
|
|
// Assert a token was returned
|
|
$response->assertStatus(401);
|
|
}
|
|
}
|