Document::factory()->create()->id, 'doctor_id' => User::factory()->create()->id, 'status' => ReportStatusEnum::Approved->name, 'body' => 'متن', 'submitted_at' => '2026-09-21 10:00:00', ], $overrides); } public function test_guest_and_non_admin_are_blocked(): void { $this->get(route('admin.reports.index'))->assertRedirect(route('login')); $this->actingAs(User::factory()->create())->get(route('admin.reports.index'))->assertNotFound(); } public function test_index_renders_with_filters(): void { $admin = $this->adminWithoutPermissions(); $document = Document::factory()->create(['code' => '123456']); $doctor = User::factory()->create(['level' => UserEnum::Doctor->value]); Report::factory()->draft()->create(['created_at' => now()->subMinute()]); Report::factory()->approved()->create(['document_id' => $document->id, 'doctor_id' => $doctor->id]); $this->actingAs($admin)->get(route('admin.reports.index'))->assertOk()->assertInertia(fn (Assert $page) => $page ->component('Reports/index') ->has('reports.data', 2) ->where('reports.data.1.doctor', null) ->where('reports.data.0.doctor.id', $doctor->id)); $this->actingAs($admin)->get(route('admin.reports.index', ['status' => ReportStatusEnum::Draft->value]))->assertInertia(fn (Assert $page) => $page->has('reports.data', 1)); $this->actingAs($admin)->get(route('admin.reports.index', ['search' => '1234']))->assertInertia(fn (Assert $page) => $page->has('reports.data', 1)); } public function test_store_creates_report(): void { $payload = $this->payload(); $this->actingAs($this->adminWithoutPermissions())->post(route('admin.reports.store'), $payload)->assertOk()->assertSessionHas('success'); $this->assertDatabaseHas('reports', ['document_id' => $payload['document_id'], 'doctor_id' => $payload['doctor_id'], 'status' => ReportStatusEnum::Approved->value, 'body' => 'متن']); } public function test_store_validates_input(): void { $this->actingAs($this->adminWithoutPermissions())->postJson(route('admin.reports.store'), [])->assertUnprocessable()->assertJsonValidationErrors(['document_id', 'doctor_id', 'status', 'body', 'submitted_at']); } public function test_edit_renders_report_prop_for_missing_page(): void { $report = Report::factory()->create(); $this->actingAs($this->adminWithoutPermissions())->get(route('admin.reports.edit', $report))->assertInertia(fn (Assert $page) => $page->component('Reports/edit', false)->where('report.id', $report->id)); } public function test_update_changes_report(): void { $report = Report::factory()->draft()->create(); $this->actingAs($this->adminWithoutPermissions())->put(route('admin.reports.update', $report), $this->payload(['status' => ReportStatusEnum::Rejected->name, 'body' => 'جدید']))->assertOk(); $this->assertDatabaseHas('reports', ['id' => $report->id, 'status' => ReportStatusEnum::Rejected->value, 'body' => 'جدید']); } public function test_destroy_deletes_report(): void { $report = Report::factory()->create(); $this->actingAs($this->adminWithoutPermissions())->delete(route('admin.reports.destroy', $report))->assertOk(); $this->assertDatabaseMissing('reports', ['id' => $report->id]); } }