fix(appointment): fall back to the resource's supervising doctor on public booking

A laser device is not a doctor, so booking one from the public site sent
resource_uuid and no doctor_uuid and got back "doctor_uuid یا resource_uuid
الزامی است" — a message telling the caller to send something it had already
sent. The panel path had resolved this from ClinicResource.supervisor since it
was written; only the public path had not, and the field was defined but never
read there.

A resource with no supervisor now gets its own message pointing at the actual
fix, instead of the generic one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-08-06 17:31:21 +03:30
co-authored by Claude Opus 5
parent 252e20bfe9
commit 12c1d2cbf4
3 changed files with 64 additions and 2 deletions
+33
View File
@@ -105,6 +105,39 @@ class BookForResourceTest extends ApiTestCase
self::assertSame('دکتر یوسفی', $row['resource']['name']);
}
/**
* دستگاه لیزر پزشک نیست؛ پزشکِ ناظرش می‌نشیند.
*
* مسیر پنل این را از قبل داشت و مسیر عمومی نداشت — یعنی همان رزرو از سایت
* ۴۲۲ می‌گرفت با پیامی که می‌گفت `resource_uuid` بفرست، در حالی که فرستاده بود.
*/
public function testBookingForADeviceFallsBackToItsSupervisor(): void
{
[$clinic, $doctor, $address] = $this->clinic();
$device = $this->resource($clinic, $address, 'دستگاه لیزر ۲');
$device->setSupervisor($doctor);
$this->em->flush();
[$res] = $this->book(['resource_uuid' => $device->getUuid()]);
self::assertSame(201, $this->responseCode(), json_encode($res, JSON_UNESCAPED_UNICODE));
self::assertSame($device->getUuid(), $res['data']['data']['resource']['uuid']);
self::assertSame($doctor->getUuid(), $res['data']['data']['doctor']['uuid']);
}
/** پیام باید بگوید ناظر ندارد، نه اینکه uuid نفرستادی. */
public function testADeviceWithoutASupervisorSaysSo(): void
{
[$clinic, , $address] = $this->clinic();
$device = $this->resource($clinic, $address, 'دستگاه بی‌ناظر');
[$res] = $this->book(['resource_uuid' => $device->getUuid()]);
self::assertSame(422, $this->responseCode(), json_encode($res, JSON_UNESCAPED_UNICODE));
self::assertSame('resource_uuid', $res['errors'][0]['field']);
self::assertStringContainsString('پزشک ناظر', $res['errors'][0]['message']);
}
public function testTheOldDoctorOnlyPathIsUntouched(): void
{
[, $doctor] = $this->clinic();