Add feature tests for Doctor-related functionalities

This commit is contained in:
2026-09-21 05:41:06 +03:30
parent e987a528ef
commit 6e92ebaada
29 changed files with 2634 additions and 29 deletions
@@ -0,0 +1,92 @@
<?php
namespace Tests\Feature\Http\Client;
use App\Enums\DocumentModalityEnum;
use App\Enums\DocumentPriorityEnum;
use App\Enums\PetTypeEnum;
use App\Enums\UserEnum;
use App\Models\Pet;
use App\Models\Shift;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class FastRequestControllerTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Queue::fake();
Storage::fake('public');
}
public function test_routes_require_authentication(): void
{
$this->get(route('dashboard.fastRequests.create'))->assertRedirect(route('login'));
$this->post(route('dashboard.fastRequests.store'))->assertRedirect(route('login'));
}
public function test_create_returns_own_pets_and_doctors_currently_on_shift(): void
{
Carbon::setTestNow('2026-09-21 10:00:00');
$user = User::factory()->create();
Pet::factory()->count(2)->create(['owner_id' => $user->id]);
Pet::factory()->create();
$onShift = User::factory()->create(['level' => UserEnum::Doctor->value]);
Shift::factory()->onDate('2026-09-21')->between('08:00', '16:00')->forDoctor($onShift)->create();
Shift::factory()->onDate('2026-09-22')->forDoctor()->create();
$this->actingAs($user)->getJson(route('dashboard.fastRequests.create'))
->assertOk()
->assertJsonCount(2, 'pets')
->assertJsonCount(1, 'doctors')
->assertJsonPath('doctors.0.id', $onShift->id);
}
public function test_store_creates_document_with_pet_invoice_and_files(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->postJson(route('dashboard.fastRequests.store'), [
'modality' => DocumentModalityEnum::CtScan->value,
'priority' => DocumentPriorityEnum::Medium->name,
'pet' => ['name' => 'Rex', 'type' => PetTypeEnum::Dog->name],
'scan_files' => [UploadedFile::fake()->image('scan.jpg')],
'history_files' => [UploadedFile::fake()->image('history.jpg')],
]);
$response->assertOk()
->assertJsonPath('document.modality', DocumentModalityEnum::CtScan->value)
->assertJsonPath('document.pet.name', 'Rex')
->assertJsonPath('document.invoice.amount', DocumentModalityEnum::CtScan->price());
$this->assertDatabaseCount('documents', 1);
$this->assertDatabaseCount('invoices', 1);
$this->assertDatabaseCount('media', 2);
}
public function test_store_validates_payload(): void
{
$this->actingAs(User::factory()->create())->postJson(route('dashboard.fastRequests.store'), [])
->assertUnprocessable()
->assertJsonValidationErrors(['modality', 'priority', 'pet']);
}
public function test_store_rejects_pet_of_another_user(): void
{
$pet = Pet::factory()->create();
$this->actingAs(User::factory()->create())->postJson(route('dashboard.fastRequests.store'), [
'modality' => DocumentModalityEnum::CtScan->value,
'priority' => DocumentPriorityEnum::Medium->name,
'pet_id' => $pet->id,
])->assertUnprocessable()->assertJsonValidationErrors('pet_id');
}
}