feat(invoice): implement recorder identity resolution for payments and update related tests
This commit is contained in:
@@ -111,6 +111,72 @@ class InvoiceShowSessionTest extends ApiTestCase
|
||||
self::assertSame(40_000, $s['consumables_total_rials']);
|
||||
}
|
||||
|
||||
/**
|
||||
* ستون «ثبتکننده» باید نامِ زندهٔ کاربر و شناسههای لینکش را بدهد؛ عکسِ
|
||||
* `created_by_name` ممکن است شمارهٔ موبایلِ زمانی باشد که کاربر پروفایل نداشته.
|
||||
*/
|
||||
public function testShowResolvesRecorderIdentityFromUser(): void
|
||||
{
|
||||
[$owner, $doctor] = $this->doctor();
|
||||
$record = $this->patientRecord($doctor);
|
||||
|
||||
$recorderDoctor = new Doctor($this->createUser(['ROLE_DOCTOR']), 'دکتر ثبتکننده');
|
||||
$this->em->persist($recorderDoctor);
|
||||
$recorder = $recorderDoctor->getUser();
|
||||
$recorder->setRealName('دکتر ثبتکننده');
|
||||
|
||||
$session = new PatientSession($record);
|
||||
$this->em->persist($session);
|
||||
$this->em->flush();
|
||||
|
||||
$payment = new SessionPayment($session, 'cash', 500_000, 1_700_100_000);
|
||||
// عکسِ کهنه: همان چیزی که هنگام ثبت ذخیره شده بود.
|
||||
$payment->setCreatedByName($recorder->getMobileNumber())->setCreatedBy($recorder);
|
||||
$this->em->persist($payment);
|
||||
$session->addPayment($payment);
|
||||
|
||||
$invoice = new Invoice('doctor', $doctor->getId());
|
||||
$invoice->setPatientSessionId($session->getId());
|
||||
$this->em->persist($invoice);
|
||||
$this->em->flush();
|
||||
|
||||
$res = $this->authJson('GET', '/api/v1/billing/invoices/' . $invoice->getUuid(), $owner);
|
||||
self::assertSame(200, $this->responseCode());
|
||||
|
||||
$row = $res['data']['data']['session']['payments'][0];
|
||||
self::assertSame('دکتر ثبتکننده', $row['created_by_name']);
|
||||
self::assertSame($recorder->getUuid(), $row['created_by']['user_uuid']);
|
||||
self::assertSame('doctor', $row['created_by']['role']);
|
||||
self::assertSame($recorderDoctor->getUuid(), $row['created_by']['doctor_uuid']);
|
||||
}
|
||||
|
||||
/** کاربرِ حذفشده: هویتی نیست، پس همان عکسِ ذخیرهشده میماند. */
|
||||
public function testShowKeepsSnapshotNameWhenRecorderUnknown(): void
|
||||
{
|
||||
[$owner, $doctor] = $this->doctor();
|
||||
$record = $this->patientRecord($doctor);
|
||||
|
||||
$session = new PatientSession($record);
|
||||
$this->em->persist($session);
|
||||
$this->em->flush();
|
||||
|
||||
$payment = new SessionPayment($session, 'cash', 100_000, 1_700_100_000);
|
||||
$payment->setCreatedByName('منشی قدیمی');
|
||||
$this->em->persist($payment);
|
||||
$session->addPayment($payment);
|
||||
|
||||
$invoice = new Invoice('doctor', $doctor->getId());
|
||||
$invoice->setPatientSessionId($session->getId());
|
||||
$this->em->persist($invoice);
|
||||
$this->em->flush();
|
||||
|
||||
$res = $this->authJson('GET', '/api/v1/billing/invoices/' . $invoice->getUuid(), $owner);
|
||||
|
||||
$row = $res['data']['data']['session']['payments'][0];
|
||||
self::assertSame('منشی قدیمی', $row['created_by_name']);
|
||||
self::assertNull($row['created_by']);
|
||||
}
|
||||
|
||||
public function testShowSessionNullWhenInvoiceHasNoSession(): void
|
||||
{
|
||||
[$owner, $doctor] = $this->doctor();
|
||||
|
||||
Reference in New Issue
Block a user