Files
clinicpro/tests/Appointment/PatientLookupTest.php
T
hamed 5d5089244b feat: add mobile-based patient lookup for appointment booking
- Implemented a new endpoint `/api/v1/my/appointment/patient-lookup` to search for patients by mobile number before booking an appointment.
- Updated the `NewAppointmentModal` component to utilize the new patient lookup feature, allowing for direct booking if the patient is found with a national code.
- Enhanced the appointment booking form to handle mobile input normalization and display relevant fields based on the search results.
- Added tests for the new patient lookup functionality, ensuring proper behavior for found and not found cases, as well as validation for mobile input.
- Updated sidebar tests to reflect changes in the sidebar component structure and functionality.
2026-07-15 18:27:29 +03:30

82 lines
2.6 KiB
PHP

<?php
namespace App\Tests\Appointment;
use App\Auth\Entity\User;
use App\Tests\ApiTestCase;
/**
* GET /api/v1/my/appointment/patient-lookup — mobile-first patient search used
* by the booking form before asking for national code / name.
*/
class PatientLookupTest extends ApiTestCase
{
private function booker(): User
{
return $this->createUser(['ROLE_DOCTOR']);
}
private function mobile(): string
{
return '09' . str_pad((string) random_int(0, 999_999_999), 9, '0', STR_PAD_LEFT);
}
private function nationalCode(): string
{
return '00' . str_pad((string) random_int(0, 99_999_999), 8, '0', STR_PAD_LEFT);
}
public function testFoundWithNationalCode(): void
{
$mobile = $this->mobile();
$nc = $this->nationalCode();
$patient = $this->createUser(['ROLE_USER'], $mobile);
$patient->setRealName('علی محمدی');
$patient->setNationalCode($nc);
$this->em->flush();
$res = $this->authJson('GET', '/api/v1/my/appointment/patient-lookup?mobile=' . $mobile, $this->booker());
self::assertSame(200, $this->responseCode());
self::assertTrue($res['data']['found']);
self::assertSame('علی محمدی', $res['data']['name']);
self::assertSame($nc, $res['data']['national_code']);
}
public function testFoundWithoutNationalCode(): void
{
$mobile = $this->mobile();
$patient = $this->createUser(['ROLE_USER'], $mobile);
$patient->setRealName('بدون کدملی');
$this->em->flush();
$res = $this->authJson('GET', '/api/v1/my/appointment/patient-lookup?mobile=' . $mobile, $this->booker());
self::assertSame(200, $this->responseCode());
self::assertTrue($res['data']['found']);
self::assertNull($res['data']['national_code']);
}
public function testNotFound(): void
{
$res = $this->authJson('GET', '/api/v1/my/appointment/patient-lookup?mobile=' . $this->mobile(), $this->booker());
self::assertSame(200, $this->responseCode());
self::assertFalse($res['data']['found']);
}
public function testInvalidMobileIs422(): void
{
$this->authJson('GET', '/api/v1/my/appointment/patient-lookup?mobile=123', $this->booker());
self::assertSame(422, $this->responseCode());
}
public function testPlainUserIsForbidden(): void
{
$this->authJson('GET', '/api/v1/my/appointment/patient-lookup?mobile=' . $this->mobile(), $this->createUser(['ROLE_USER']));
self::assertSame(403, $this->responseCode());
}
}