laravel-api-simple-blog/tests/Feature/UserTest.php

42 lines
973 B
PHP
Raw Normal View History

2024-10-15 19:58:33 +03:00
<?php
namespace Tests\Feature;
use App\Models\User;
2024-10-17 19:15:01 +03:00
use Illuminate\Foundation\Testing\RefreshDatabase;
2024-10-15 19:58:33 +03:00
use Tests\TestCase;
class UserTest extends TestCase
{
// FIXME: tests should be
// grouped and be separated in several files
2024-10-17 19:15:01 +03:00
use RefreshDatabase;
public function test_success_get_users(): void
{
$this->get('/user')
->assertStatus(200);
}
public function test_success_get_one_user(): void
{
2024-10-16 23:17:37 +03:00
$user = User::factory()->create();
$this->get('/user/' . $user->id)
->assertStatus(200);
}
public function test_fail_get_user_not_exists(): void
{
$this->get('/user/99999999')
->assertNotFound();
// FIXME: Not Fount or Bad request? or any else error?
// Maybe parse exception: id is numeric
// but in future updates id
// will be uuid, it is safer
$this->get('/user/sehtrgher')
2024-10-17 19:15:01 +03:00
->assertBadRequest();
}
2024-10-15 19:58:33 +03:00
}