From c94ceaa027c51af25998c02b506415918db2c9f8 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Wed, 22 Jul 2026 16:47:52 +0330 Subject: [PATCH] feat: add test for clinic owner viewing slots when online booking is disabled --- .../OnlineBookingManagementTest.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/Appointment/OnlineBookingManagementTest.php b/tests/Appointment/OnlineBookingManagementTest.php index 2778cc02..a629eb31 100644 --- a/tests/Appointment/OnlineBookingManagementTest.php +++ b/tests/Appointment/OnlineBookingManagementTest.php @@ -4,6 +4,8 @@ namespace App\Tests\Appointment; use App\Appointment\Entity\WeeklySchedule; use App\Appointment\Service\SlotCalculatorService; +use App\Auth\Entity\User; +use App\Clinic\Entity\Clinic; use App\Doctor\Entity\Doctor; use App\Tests\ApiTestCase; @@ -120,4 +122,50 @@ class OnlineBookingManagementTest extends ApiTestCase self::assertSame(200, $this->responseCode()); self::assertSame([], $body['data']['sessions']); } + + /** + * سناریوی واقعیِ گزارش‌شده: پزشک عضو کلینیک، نوبت‌دهی آنلاینِ کلینیک خاموش، + * مالک کلینیک از پنل «نوبت‌ها» با management=1 باید اسلات‌ها را ببیند. + */ + public function testClinicOwnerSeesClinicSlotsWhenBookingDisabled(): void + { + $doctorOwner = $this->createUser(['ROLE_DOCTOR']); + $doctor = new Doctor($doctorOwner, 'دکتر احمدی'); + $this->em->persist($doctor); + + $clinicOwner = $this->createUser(['ROLE_USER', 'ROLE_CLINIC']); + $clinic = new Clinic($clinicOwner); + $clinic->setName('کلینیک تخصصی نمونه'); + $clinic->getDoctors()->add($doctor); + $this->em->persist($clinic); + + $date = date('Y-m-d', strtotime('tomorrow')); + $dayKey = (string)(((int) date('w', strtotime($date)) + 1) % 7); + + // برنامهٔ نوبت‌دهی در محیط کلینیک با نوبت‌دهی آنلاینِ خاموش. + $schedule = new WeeklySchedule($doctor, [ + $dayKey => ['sessions' => [[ + 'active' => true, 'start_time' => '10:00', 'end_time' => '12:00', + 'duration_per_patient' => 30, 'location_id' => 1, + ]]], + ], $clinic); + $schedule->setMeta(['online_booking_enabled' => false]); + $this->em->persist($schedule); + $this->em->flush(); + + $uri = sprintf( + '/api/v1/appointment-slots?doctor_uuid=%s&date=%s&clinic_uuid=%s&management=1', + $doctor->getUuid(), $date, $clinic->getUuid(), + ); + + // مالک کلینیک → اسلات می‌بیند. + $body = $this->authJson('GET', $uri, $clinicOwner); + self::assertSame(200, $this->responseCode()); + self::assertNotSame([], $body['data']['sessions'], 'مالک کلینیک باید اسلات‌های محیط کلینیک را ببیند'); + + // بدون احراز → عمومی، خالی. + $this->client->request('GET', $uri); + $anon = json_decode($this->client->getResponse()->getContent(), true); + self::assertSame([], $anon['data']['sessions']); + } }