feat(doctor): ensure default office address creation during doctor import
This commit is contained in:
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user