Files
clinicpro/tests/Appointment/AppointmentCreateReserveTest.php
T
hamedandClaude Fable 5 4678739d15 feat(appointments): backend for clinic workflow (Figma نوبت‌ها) — phase A
Extend Appointment for the clinic-facing appointments area:

- New nullable relations service_section/service_item/staff (بخش/سرویس/پرسنل)
  plus deposit_required/deposit_amount_rials (بیعانه) and is_reserve.
- New statuses following_up (در حال پیگیری) and salon (سالن) with day-of
  transition rules; reserve entries never occupy a slot (several reserves may
  share one day), enforced in refreshActiveSlotKey.
- rescheduleTo(slotStart, slotEnd, isReserve) keeps active_slot_key consistent
  for جا به جایی and reserve transfers.
- New PATCH /api/v1/appointment/{uuid}: partial update covering edit, slot
  move (409 on taken slot, race backstop on the unique key), reserve toggle,
  patient swap (جایگزینی) and optional status transition; optimistic lock via
  version like the status endpoint.
- POST /my/appointment now accepts the workflow fields and is_reserve
  (day-level entry: no past-slot rule, no atomic slot booking); GET
  /my/appointments gains reserve=1 and returns the new fields per row.

Migration Version20260713195434 (+ mirrored on db_test). Docs updated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-13 23:37:32 +03:30

106 lines
4.1 KiB
PHP

<?php
namespace App\Tests\Appointment;
use App\ClinicService\Entity\ServiceItem;
use App\ClinicService\Entity\ServiceSection;
use App\Doctor\Entity\Doctor;
use App\Staff\Entity\ClinicStaff;
use App\Tests\ApiTestCase;
/**
* POST /api/v1/my/appointment extensions (workflow fields + reserve entries)
* and the GET /api/v1/my/appointments ?reserve list split.
*/
class AppointmentCreateReserveTest extends ApiTestCase
{
/** @return array{0: \App\Auth\Entity\User, 1: Doctor} */
private function doctor(): array
{
$owner = $this->createUser(['ROLE_DOCTOR']);
$doctor = new Doctor($owner, 'دکتر');
$this->em->persist($doctor);
$this->em->flush();
return [$owner, $doctor];
}
public function testCreateWithWorkflowFields(): void
{
[$owner, $doctor] = $this->doctor();
$section = new ServiceSection('doctor', $doctor->getId(), 'زیبایی');
$item = new ServiceItem($section, 'لیزر فول بادی');
$staff = new ClinicStaff('doctor', $doctor->getId(), 'سحر ایمانی');
$this->em->persist($section);
$this->em->persist($item);
$this->em->persist($staff);
$this->em->flush();
$start = time() + 86_400;
$res = $this->authJson('POST', '/api/v1/my/appointment', $owner, [
'doctor_uuid' => $doctor->getUuid(),
'slot_start' => $start,
'slot_end' => $start + 2_400,
'patient_mobile' => '09' . random_int(100000000, 999999999),
'patient_name' => 'مریم اسکندری',
'service_section_uuid' => $section->getUuid(),
'service_item_uuid' => $item->getUuid(),
'staff_uuid' => $staff->getUuid(),
'deposit_required' => true,
'deposit_amount_rials' => 5_000_000,
]);
self::assertSame(201, $this->responseCode());
self::assertFalse($res['data']['is_reserve']);
$list = $this->authJson('GET', '/api/v1/my/appointments?limit=50', $owner);
$row = $list['data'][0];
self::assertSame('لیزر فول بادی', $row['service_item']['name']);
self::assertSame('سحر ایمانی', $row['staff']['full_name']);
self::assertTrue($row['deposit_required']);
}
public function testReserveEntriesSkipSlotRulesAndAreListedSeparately(): void
{
[$owner, $doctor] = $this->doctor();
$day = strtotime('today midnight'); // past for a slot booking — fine for a reserve
// two reserves on the same day must both succeed (no slot occupation)
foreach (['ساغر صابری', 'پریسا همتی'] as $name) {
$this->authJson('POST', '/api/v1/my/appointment', $owner, [
'doctor_uuid' => $doctor->getUuid(),
'slot_start' => $day,
'slot_end' => $day,
'patient_mobile' => '09' . random_int(100000000, 999999999),
'patient_name' => $name,
'is_reserve' => true,
]);
self::assertSame(201, $this->responseCode());
}
$reserves = $this->authJson('GET', '/api/v1/my/appointments?reserve=1&limit=50', $owner);
self::assertCount(2, $reserves['data']);
self::assertTrue($reserves['data'][0]['is_reserve']);
// the regular list must not contain reserve entries
$regular = $this->authJson('GET', '/api/v1/my/appointments?limit=50', $owner);
self::assertCount(0, $regular['data']);
}
public function testUnknownServiceUuidIs422(): void
{
[$owner, $doctor] = $this->doctor();
$start = time() + 86_400;
$this->authJson('POST', '/api/v1/my/appointment', $owner, [
'doctor_uuid' => $doctor->getUuid(),
'slot_start' => $start,
'slot_end' => $start + 1_800,
'patient_mobile' => '09' . random_int(100000000, 999999999),
'patient_name' => 'x',
'service_item_uuid' => 'missing-uuid',
]);
self::assertSame(422, $this->responseCode());
}
}