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'); } }