feat(appointment): implement immutable booking mode after first save and update API documentation

This commit is contained in:
hamed
2026-07-15 23:33:00 +03:30
parent ad94c165e8
commit 2df16c6d29
5 changed files with 176 additions and 32 deletions
@@ -0,0 +1,58 @@
<?php
namespace App\Tests\Appointment;
use App\Doctor\Entity\Doctor;
use App\Tests\ApiTestCase;
/**
* نوع نوبت‌دهی (booking_mode) پس از اولین ثبت غیرقابل‌تغییر است.
*/
class BookingModeImmutableTest extends ApiTestCase
{
private function makeDoctor(): array
{
$owner = $this->createUser(['ROLE_DOCTOR']);
$doctor = new Doctor($owner, 'دکتر قفل');
$this->em->persist($doctor);
$this->em->flush();
return [$owner, $doctor];
}
public function testFirstSaveCommitsAndSecondSaveKeepsSameMode(): void
{
[$owner, $doctor] = $this->makeDoctor();
$this->authJson('POST', '/api/v1/appointment-settings/weekly-schedule', $owner, [
'doctor_uuid' => $doctor->getUuid(),
'schedule' => [],
'meta' => ['booking_mode' => 'slot'],
]);
$this->assertSame(201, $this->responseCode());
// همان mode دوباره → مجاز
$this->authJson('PATCH', '/api/v1/appointment-settings/weekly-schedule/' . $doctor->getUuid(), $owner, [
'meta' => ['booking_mode' => 'slot'],
]);
$this->assertSame(200, $this->responseCode());
}
public function testCannotChangeModeAfterCommit(): void
{
[$owner, $doctor] = $this->makeDoctor();
$this->authJson('POST', '/api/v1/appointment-settings/weekly-schedule', $owner, [
'doctor_uuid' => $doctor->getUuid(),
'schedule' => [],
'meta' => ['booking_mode' => 'slot'],
]);
$this->assertSame(201, $this->responseCode());
// تلاش برای تغییر به سرویس → 422 قفل
$res = $this->authJson('PATCH', '/api/v1/appointment-settings/weekly-schedule/' . $doctor->getUuid(), $owner, [
'meta' => ['booking_mode' => 'service'],
]);
$this->assertSame(422, $this->responseCode());
$this->assertStringContainsString('قابل تغییر نیست', json_encode($res, JSON_UNESCAPED_UNICODE));
}
}