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

42 lines
973 B
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class UserTest extends TestCase
{
// FIXME: tests should be
// grouped and be separated in several files
use RefreshDatabase;
public function test_success_get_users(): void
{
$this->get('/user')
->assertStatus(200);
}
public function test_success_get_one_user(): void
{
$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')
->assertBadRequest();
}
}