feat(doctor): prevent duplicate doctor imports based on medical system code

This commit is contained in:
hamed
2026-07-11 19:56:58 +03:30
parent 6c67d522ba
commit 23590370b2
3 changed files with 44 additions and 0 deletions
+26
View File
@@ -164,6 +164,32 @@ class DoctorImportTest extends ApiTestCase
$this->assertSame('مطب دکتر صفورا حجازی نیا', $doctor->getAddresses()->first()->getName());
}
public function testManualDoctorWithSameCodeIsNeverDuplicated(): void
{
$admin = $this->createUser(['ROLE_USER', 'ROLE_ADMIN']);
$code = $this->freshCode();
$owner = $this->createUser(['ROLE_USER', 'ROLE_DOCTOR']);
$manual = new Doctor($owner, 'پزشک دستی');
$manual->setMedicalSystemCode($code);
$this->em->persist($manual);
$this->em->flush();
$data = $this->authJson('POST', '/api/v1/admin/doctors/import', $admin, $this->importPayload($code));
$this->assertSame(200, $this->responseCode());
$this->assertFalse($data['data']['created']);
$this->assertSame('duplicate', $data['data']['skipped']);
$this->assertSame($manual->getUuid(), $data['data']['uuid']);
$this->em->clear();
$count = $this->em->getRepository(Doctor::class)->count(['medicalSystemCode' => $code]);
$this->assertSame(1, $count);
$doctor = $this->em->getRepository(Doctor::class)->findOneBy(['medicalSystemCode' => $code]);
$this->assertSame('پزشک دستی', $doctor->getName());
$this->assertSame('manual', $doctor->getSource());
}
public function testValidationErrors(): void
{
$admin = $this->createUser(['ROLE_USER', 'ROLE_ADMIN']);