feat(doctor): ensure default office address creation during doctor import

This commit is contained in:
hamed
2026-07-11 19:21:24 +03:30
parent 1508d38daa
commit 6c67d522ba
3 changed files with 108 additions and 0 deletions
+57
View File
@@ -3,6 +3,8 @@
namespace App\Tests\Doctor;
use App\Doctor\Entity\Doctor;
use App\Location\Entity\City;
use App\Location\Entity\Province;
use App\Tests\ApiTestCase;
/**
@@ -107,6 +109,61 @@ class DoctorImportTest extends ApiTestCase
$this->assertSame('claimed', $doctor->getOwnerStatus());
}
public function testImportCreatesDefaultOfficeAddressWithCityAndProvince(): void
{
$admin = $this->createUser(['ROLE_USER', 'ROLE_ADMIN']);
$code = $this->freshCode();
$province = new Province('استان تست ' . $code);
$city = new City('شهر تست ' . $code, $province);
$this->em->persist($province);
$this->em->persist($city);
$this->em->flush();
$payload = $this->importPayload($code);
$payload['states'] = [$province->getId()];
$payload['cities'] = [$city->getId()];
$data = $this->authJson('POST', '/api/v1/admin/doctors/import', $admin, $payload);
$this->assertSame(201, $this->responseCode());
$cityId = $city->getId();
$provinceId = $province->getId();
$this->em->clear();
$doctor = $this->em->getRepository(Doctor::class)->findOneBy(['uuid' => $data['data']['uuid']]);
$this->assertCount(1, $doctor->getAddresses());
$address = $doctor->getAddresses()->first();
$this->assertSame('مطب دکتر صفورا حجازی نیا', $address->getName());
$this->assertSame($cityId, $address->getCity()?->getId());
$this->assertSame($provinceId, $address->getProvince()?->getId());
// ایمپورت مجدد نباید آدرس تکراری بسازد یا نام آدرس را بازنویسی کند
$address->setName('مطب ویرایش‌شده توسط کاربر');
$this->em->flush();
$this->authJson('POST', '/api/v1/admin/doctors/import', $admin, $payload);
$this->assertSame(200, $this->responseCode());
$this->em->clear();
$doctor = $this->em->getRepository(Doctor::class)->findOneBy(['uuid' => $data['data']['uuid']]);
$this->assertCount(1, $doctor->getAddresses());
$this->assertSame('مطب ویرایش‌شده توسط کاربر', $doctor->getAddresses()->first()->getName());
}
public function testImportWithoutLocationStillCreatesOfficeAddress(): void
{
$admin = $this->createUser(['ROLE_USER', 'ROLE_ADMIN']);
$code = $this->freshCode();
$data = $this->authJson('POST', '/api/v1/admin/doctors/import', $admin, $this->importPayload($code));
$this->assertSame(201, $this->responseCode());
$this->em->clear();
$doctor = $this->em->getRepository(Doctor::class)->findOneBy(['uuid' => $data['data']['uuid']]);
$this->assertCount(1, $doctor->getAddresses());
$this->assertSame('مطب دکتر صفورا حجازی نیا', $doctor->getAddresses()->first()->getName());
}
public function testValidationErrors(): void
{
$admin = $this->createUser(['ROLE_USER', 'ROLE_ADMIN']);