my/clinic-doctors now reports has_schedule per doctor, and the appointments page builds tabs from it. A doctor with no working days had a tab that could only ever show an empty timeline. The flag is resolved with one query for the whole list rather than one per doctor. Clinic owners now read this authenticated endpoint too instead of the public clinic doctor-list, which is where the flag lives; admin keeps the public list and, with no flag present, hides nobody. Also repairs fallout from making the resource supervisor mandatory: four test classes build resources through their own helpers and were failing with 422. The supervisorFor helper moved to ApiTestCase so all domains share one, rather than copying it per suite. Full backend suite is green again (1306 tests) — the previous commit only ran tests/Resource and missed this. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
98 lines
3.5 KiB
PHP
98 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Resource;
|
|
|
|
use App\Auth\Entity\User;
|
|
use App\Clinic\Entity\Clinic;
|
|
use App\Doctor\Entity\Doctor;
|
|
use App\Doctor\Entity\DoctorAddress;
|
|
use App\Resource\Entity\ResourceType;
|
|
use App\Staff\Entity\ClinicStaff;
|
|
use App\Tests\ApiTestCase;
|
|
|
|
/**
|
|
* فیکسچرهای مشترک دامنهٔ منبع. هر تست به یک محیط با آدرس و یک نوع منبع نیاز دارد،
|
|
* و برای سنجش مرز ۴۰۴ به یک محیط بیگانه.
|
|
*/
|
|
abstract class ResourceTestCase extends ApiTestCase
|
|
{
|
|
/** @return array{0: User, 1: Clinic, 2: DoctorAddress} */
|
|
protected function clinicWithAddress(string $addressName = 'شعبهٔ مرکزی'): array
|
|
{
|
|
$user = $this->createUser(['ROLE_USER', 'ROLE_CLINIC']);
|
|
$clinic = new Clinic($user);
|
|
$clinic->setName('کلینیک منابع');
|
|
$this->em->persist($clinic);
|
|
$this->em->flush();
|
|
|
|
$address = DoctorAddress::forClinic($clinic->getId());
|
|
$address->setName($addressName);
|
|
$this->em->persist($address);
|
|
$this->em->flush();
|
|
|
|
return [$user, $clinic, $address];
|
|
}
|
|
|
|
/** آدرس دوم همان محیط — برای سنجش قاعدهٔ «همهٔ اعضای استخر در یک شعبه». */
|
|
protected function extraAddress(Clinic $clinic, string $name = 'شعبهٔ دوم'): DoctorAddress
|
|
{
|
|
$address = DoctorAddress::forClinic($clinic->getId());
|
|
$address->setName($name);
|
|
$this->em->persist($address);
|
|
$this->em->flush();
|
|
|
|
return $address;
|
|
}
|
|
|
|
/** @return array{0: User, 1: Doctor, 2: DoctorAddress} */
|
|
protected function doctorWithAddress(): array
|
|
{
|
|
$user = $this->createUser(['ROLE_USER', 'ROLE_DOCTOR']);
|
|
$doctor = new Doctor($user, 'دکتر منبع');
|
|
$doctor->setMobileNumber($user->getMobileNumber());
|
|
$this->em->persist($doctor);
|
|
$this->em->flush();
|
|
|
|
$address = DoctorAddress::forDoctor($doctor);
|
|
$address->setName('مطب شخصی');
|
|
$this->em->persist($address);
|
|
$this->em->flush();
|
|
|
|
return [$user, $doctor, $address];
|
|
}
|
|
|
|
protected function resourceType(DoctorAddress $address, string $code = 'device', string $name = 'دستگاه'): ResourceType
|
|
{
|
|
$type = new ResourceType($address->tenantEntityType(), $address->tenantEntityId(), $code, $name);
|
|
$this->em->persist($type);
|
|
$this->em->flush();
|
|
|
|
return $type;
|
|
}
|
|
|
|
protected function staff(DoctorAddress $address, string $name = 'اپراتور یک'): ClinicStaff
|
|
{
|
|
$staff = new ClinicStaff($address->tenantEntityType(), $address->tenantEntityId(), $name);
|
|
$this->em->persist($staff);
|
|
$this->em->flush();
|
|
|
|
return $staff;
|
|
}
|
|
|
|
/** @param array<string, mixed> $body */
|
|
protected function createResource(User $user, DoctorAddress $address, ResourceType $type, array $body = []): array
|
|
{
|
|
return $this->authJson('POST', '/api/v1/resource', $user, $body + [
|
|
'address_uuid' => $address->getUuid(),
|
|
'type_uuid' => $type->getUuid(),
|
|
'name' => 'لیزر آلکساندرایت ۱',
|
|
'supervisor_doctor_uuid' => $this->supervisorFor($address)->getUuid(),
|
|
]);
|
|
}
|
|
|
|
protected function createSkill(User $user, string $name = 'لیزر آلکساندرایت'): array
|
|
{
|
|
return $this->authJson('POST', '/api/v1/skills', $user, ['name' => $name]);
|
|
}
|
|
}
|