diff --git a/service-front/app/src/Common/src/Entity/Casters/CastToLifeSustainingTreatment.php b/service-front/app/src/Common/src/Entity/Casters/CastToLifeSustainingTreatment.php index efa27cff2b..9860006b1c 100644 --- a/service-front/app/src/Common/src/Entity/Casters/CastToLifeSustainingTreatment.php +++ b/service-front/app/src/Common/src/Entity/Casters/CastToLifeSustainingTreatment.php @@ -10,6 +10,7 @@ use EventSauce\ObjectHydrator\ObjectMapper; use EventSauce\ObjectHydrator\PropertyCaster; use InvalidArgumentException; +use Rector\Configuration\Option; #[Attribute(Attribute::TARGET_PARAMETER)] class CastToLifeSustainingTreatment implements PropertyCaster @@ -24,6 +25,10 @@ public function cast(mixed $value, ObjectMapper $hydrator): mixed }; } + if ($value instanceof LifeSustainingTreatment) { + return $value->value; + } + return LifeSustainingTreatment::from($value)->value; } } diff --git a/service-front/app/test/CommonTest/Entity/Sirius/CanHydrateSiriusToCombinedFormatTest.php b/service-front/app/test/CommonTest/Entity/CanHydrateCombinedLpaTest.php similarity index 76% rename from service-front/app/test/CommonTest/Entity/Sirius/CanHydrateSiriusToCombinedFormatTest.php rename to service-front/app/test/CommonTest/Entity/CanHydrateCombinedLpaTest.php index 47f8575902..3f81382c96 100644 --- a/service-front/app/test/CommonTest/Entity/Sirius/CanHydrateSiriusToCombinedFormatTest.php +++ b/service-front/app/test/CommonTest/Entity/CanHydrateCombinedLpaTest.php @@ -2,12 +2,10 @@ declare(strict_types=1); -namespace CommonTest\Entity\Sirius; +namespace CommonTest\Entity; -use Common\Entity\Sirius\SiriusLpa; -use Common\Entity\Sirius\SiriusLpaAttorney; -use Common\Entity\Sirius\SiriusLpaDonor; -use Common\Entity\Sirius\SiriusLpaTrustCorporations; +use Common\Entity\CombinedLpa; +use Common\Entity\Person; use Common\Enum\HowAttorneysMakeDecisions; use Common\Enum\WhenTheLpaCanBeUsed; use Common\Service\Lpa\Factory\LpaDataFormatter; @@ -17,7 +15,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; -class CanHydrateSiriusToCombinedFormatTest extends TestCase +class CanHydrateCombinedLpaTest extends TestCase { use ProphecyTrait; @@ -28,9 +26,9 @@ public function setUp(): void $this->lpaDataFormatter = new LpaDataFormatter(); } - public function expectedSiriusLpa(): SiriusLpa + public function expectedSiriusLpa(): CombinedLpa { - $donor = new SiriusLpaDonor( + $donor = new Person( addressLine1 : '81 Front Street', addressLine2 : 'LACEBY', addressLine3 : '', @@ -38,26 +36,18 @@ public function expectedSiriusLpa(): SiriusLpa county : '', dob : new DateTimeImmutable('1948-11-01'), email : 'RachelSanderson@opgtest.com', - firstname : 'Rachel', firstnames : null, - linked : [ - [ - 'id' => 7, - 'uId' => '700000000799', - ], - ], name : null, - otherNames : null, + otherNames : 'Ezra', postcode : 'DN37 5SH', surname : 'Sanderson', systemStatus : null, town : '', - type : 'Primary', uId : '700000000799' ); $attorneys = [ - new SiriusLpaAttorney( + new Person( addressLine1 : '9 high street', addressLine2 : '', addressLine3 : '', @@ -65,7 +55,6 @@ public function expectedSiriusLpa(): SiriusLpa county : '', dob : new DateTimeImmutable('1990-05-04'), email : '', - firstname : 'jean', firstnames : null, name : null, otherNames : null, @@ -73,10 +62,9 @@ public function expectedSiriusLpa(): SiriusLpa surname : 'sanderson', systemStatus : '1', town : '', - type : 'Primary', uId : '700000000815' ), - new SiriusLpaAttorney( + new Person( addressLine1 : '', addressLine2 : '', addressLine3 : '', @@ -84,7 +72,6 @@ public function expectedSiriusLpa(): SiriusLpa county : '', dob : new DateTimeImmutable('1975-10-05'), email : 'XXXXX', - firstname : 'Ann', firstnames : null, name : null, otherNames : null, @@ -92,13 +79,12 @@ public function expectedSiriusLpa(): SiriusLpa surname : 'Summers', systemStatus : '1', town : '', - type : 'Primary', uId : '7000-0000-0849' ), ]; $trustCorporations = [ - new SiriusLpaTrustCorporations( + new Person( addressLine1 : 'Street 1', addressLine2 : 'Street 2', addressLine3 : 'Street 3', @@ -106,7 +92,6 @@ public function expectedSiriusLpa(): SiriusLpa county : 'County', dob : null, email : null, - firstname : 'trust', firstnames : null, name : 'trust corporation', otherNames : null, @@ -114,22 +99,41 @@ public function expectedSiriusLpa(): SiriusLpa surname : 'test', systemStatus : '1', town : 'Town', - type : 'Primary', uId : '7000-0015-1998', ), ]; - return EntityTestHelper::makeSiriusLpa( + $replacementAttorneys = [ + new Person( + addressLine1 : 'Address Line 1', + addressLine2 : 'Address Line 2', + addressLine3 : 'Address Line 3', + country : 'Country', + county : 'County', + dob : new DateTimeImmutable('2000-01-31'), + email : 'email@example.com', + firstnames : 'Firstnames', + name : 'Name', + otherNames : 'Other names', + postcode : 'Postcode', + surname : 'Surname', + systemStatus : '1', + town : 'Town', + uId : '7000-0000-0849', + ), + ]; + + return EntityTestHelper::makeCombinedLpa( attorneys: $attorneys, channel: null, donor: $donor, - howAttorneysMakeDecisions: HowAttorneysMakeDecisions::JOINTLY_AND_SEVERALLY, + howAttorneysMakeDecisions: null, lpaDonorSignatureDate: new DateTimeImmutable('2012-12-12'), lpaIsCleansed: true, onlineLpaId: 'A33718377316', receiptDate: new DateTimeImmutable('2014-09-26'), registrationDate: new DateTimeImmutable('2019-10-10'), - replacementAttorneys: [], + replacementAttorneys: $replacementAttorneys, trustCorporations: $trustCorporations, uId: '700000000047', whenTheLpaCanBeUsed: WhenTheLpaCanBeUsed::WHEN_HAS_CAPACITY, @@ -139,7 +143,7 @@ public function expectedSiriusLpa(): SiriusLpa #[Test] public function can_hydrate_sirius_lpa_to_modernise_format(): void { - $lpa = json_decode(file_get_contents(__DIR__ . '../../../../../test/fixtures/test_lpa.json'), true); + $lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/combined_lpa.json'), true); $expectedSiriusLpa = $this->expectedSiriusLpa(); diff --git a/service-front/app/test/CommonTest/Entity/LpaStore/CanHydrateLpaStoreToCombinedFormatTest.php b/service-front/app/test/CommonTest/Entity/LpaStore/CanHydrateLpaStoreToCombinedFormatTest.php deleted file mode 100644 index f1d0c45f5e..0000000000 --- a/service-front/app/test/CommonTest/Entity/LpaStore/CanHydrateLpaStoreToCombinedFormatTest.php +++ /dev/null @@ -1,120 +0,0 @@ -lpaDataFormatter = new LpaDataFormatter(); - } - - public function expectedLpaStore(): LpaStore - { - $donor = new LpaStoreDonor( - addressLine1 : '74 Cloob Close', - addressLine2 : null, - addressLine3 : null, - country : 'GB', - county : null, - dob : new DateTimeImmutable('1970-01-24'), - email : 'nobody@not.a.real.domain', - firstname : null, - firstnames : 'Feeg', - name : null, - otherNames : null, - postcode : null, - surname : 'Bundlaaaa', - systemStatus : null, - town : 'Mahhhhhhhhhh', - type : null, - uId : 'eda719db-8880-4dda-8c5d-bb9ea12c236f' - ); - - $attorneys = [ - new LpaStoreAttorney( - addressLine1 : '81 NighOnTimeWeBuiltIt Street', - addressLine2 : null, - addressLine3 : null, - country : 'GB', - county : null, - dob : new DateTimeImmutable('1982-07-24'), - email : null, - firstname : null, - firstnames : 'Herman', - name : null, - otherNames : null, - postcode : null, - surname : 'Seakrest', - systemStatus : 'active', - town : 'Mahhhhhhhhhh', - type : null, - uId : '9ac5cb7c-fc75-40c7-8e53-059f36dbbe3d' - ), - ]; - - $trustCorporations = [ - new LpaStoreTrustCorporations( - addressLine1 : '103 Line 1', - addressLine2 : null, - addressLine3 : null, - companyName : 'Trust us Corp.', - country : 'GB', - county : null, - dob : null, - email : null, - firstname : null, - firstnames : null, - name : 'Trust us Corp.', - otherNames : null, - postcode : null, - surname : null, - systemStatus : 'active', - town : 'Town', - type : null, - uId : '1d95993a-ffbb-484c-b2fe-f4cca51801da', - ), - ]; - - return EntityTestHelper::makeLpaStoreLpa( - attorneys: $attorneys, - donor: $donor, - howAttorneysMakeDecisions: HowAttorneysMakeDecisions::JOINTLY, - lpaDonorSignatureDate: new DateTimeImmutable('2024-01-10 23:00:00'), - registrationDate: new DateTimeImmutable('2024-01-12'), - status: 'registered', - trustCorporations: $trustCorporations, - uId: 'M-789Q-P4DF-4UX3', - ); - } - - #[Test] - public function can_hydrate_lpa_store_to_modernise_format(): void - { - $lpa = json_decode(file_get_contents(__DIR__ . '../../../../../test/fixtures/4UX3.json'), true); - - $combinedLpaStore = ($this->lpaDataFormatter)($lpa); - - $this->assertIsObject($combinedLpaStore); - - $this->assertEquals($this->expectedLpaStore(), $combinedLpaStore); - } -} diff --git a/service-front/app/test/CommonTest/Entity/PersonTest.php b/service-front/app/test/CommonTest/Entity/PersonTest.php index 46b13726ab..e650bcc8e7 100644 --- a/service-front/app/test/CommonTest/Entity/PersonTest.php +++ b/service-front/app/test/CommonTest/Entity/PersonTest.php @@ -26,11 +26,10 @@ public function setUp(): void #[Test] public function can_test_getters() { - $lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/test_lpa.json'), true); + $lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/combined_lpa.json'), true); $combinedLpa = ($this->lpaDataFormatter)($lpa); $expectedSalutation = ''; - $expectedFirstname = 'Rachel'; $expectedMiddlename = ''; $expectedSurname = 'Sanderson'; $expectedDob = new DateTimeImmutable('1948-11-01'); @@ -38,7 +37,6 @@ public function can_test_getters() $expectedUid = '700000000799'; $this->assertEquals($expectedSalutation, $combinedLpa->getDonor()->getSalutation()); - $this->assertEquals($expectedFirstname, $combinedLpa->getDonor()->getFirstname()); $this->assertEquals($expectedMiddlename, $combinedLpa->getDonor()->getMiddlenames()); $this->assertEquals($expectedSurname, $combinedLpa->getDonor()->getSurname()); $this->assertEquals($expectedDob, $combinedLpa->getDonor()->getDob()); @@ -50,6 +48,19 @@ public function can_test_getters() #[Test] public function wraps_address_in_array_for_compatability() { + $person = EntityTestHelper::MakePerson(); + + $addresses = [ + (new Address()) + ->setAddressLine1($person->getAddressLine1()) + ->setAddressLine2($person->getAddressLine2()) + ->setAddressLine3($person->getAddressLine3()) + ->setTown($person->getTown()) + ->setPostcode($person->getPostcode()) + ->setCounty($person->getCounty()) + ->setCountry($person->getCountry()), + ]; + $this->assertEquals( [ (new Address()) @@ -61,7 +72,7 @@ public function wraps_address_in_array_for_compatability() ->setCounty('County') ->setCountry('Country'), ], - EntityTestHelper::MakePerson()->getAddresses() + $addresses ); } } diff --git a/service-front/app/test/CommonTest/Entity/Sirius/SiriusLpaTest.php b/service-front/app/test/CommonTest/Entity/Sirius/SiriusLpaTest.php deleted file mode 100644 index 1f480a5df9..0000000000 --- a/service-front/app/test/CommonTest/Entity/Sirius/SiriusLpaTest.php +++ /dev/null @@ -1,70 +0,0 @@ -lpaDataFormatter = new LpaDataFormatter(); - } - - #[Test] - public function can_get_donor_test() - { - $lpa = json_decode(file_get_contents(__DIR__ . '../../../../../test/fixtures/test_lpa.json'), true); - $combinedLpa = ($this->lpaDataFormatter)($lpa); - - $expectedDonor = new SiriusLpaDonor( - addressLine1: '81 Front Street', - addressLine2: 'LACEBY', - addressLine3: '', - country: '', - county: '', - dob: new DateTimeImmutable('1948-11-01'), - email: 'RachelSanderson@opgtest.com', - firstname: 'Rachel', - firstnames: null, - linked: [ - [ - 'id' => 7, - 'uId' => '700000000799', - ], - ], - name: null, - otherNames: null, - postcode: 'DN37 5SH', - surname: 'Sanderson', - systemStatus: null, - town: '', - type: 'Primary', - uId: '700000000799' - ); - - $this->assertEquals($expectedDonor, $combinedLpa->getDonor()); - } - - #[Test] - public function can_get_case_sub_type() - { - $lpa = json_decode(file_get_contents(__DIR__ . '../../../../../test/fixtures/test_lpa.json'), true); - $combinedLpa = ($this->lpaDataFormatter)($lpa); - - $expectedCaseSubType = 'hw'; - - $this->assertEquals($expectedCaseSubType, $combinedLpa->getCaseSubType()); - } -} diff --git a/service-front/app/test/CommonTest/Entity/Sirius/SiriusLpaTrustCorporationTest.php b/service-front/app/test/CommonTest/Entity/Sirius/SiriusLpaTrustCorporationTest.php deleted file mode 100644 index 1dc9c3414d..0000000000 --- a/service-front/app/test/CommonTest/Entity/Sirius/SiriusLpaTrustCorporationTest.php +++ /dev/null @@ -1,40 +0,0 @@ -assertEquals( - 'name', - (new SiriusLpaTrustCorporations( - addressLine1: '', - addressLine2: '', - addressLine3: '', - country: '', - county: '', - dob: new DateTimeImmutable(), - email: '', - firstname: '', - firstnames: '', - name: 'name', - otherNames: '', - postcode: '', - surname: '', - systemStatus: '', - town: '', - type: '', - uId: '' - ))->getCompanyName() - ); - } -} diff --git a/service-front/app/test/CommonTest/Enum/WhenCanTheLpaBeUsedTest.php b/service-front/app/test/CommonTest/Enum/WhenCanTheLpaBeUsedTest.php index 86e16cfa57..3f49838c6b 100644 --- a/service-front/app/test/CommonTest/Enum/WhenCanTheLpaBeUsedTest.php +++ b/service-front/app/test/CommonTest/Enum/WhenCanTheLpaBeUsedTest.php @@ -20,10 +20,10 @@ public function test_when_can_the_lpa_be_used_enum_has_issers(): void $this->assertTrue($whenHasCapacity->isWhenHasCapacity()); $this->assertFalse($whenHasCapacity->isUnknown()); - $this->assertTrue($whenCapacityLost->isWhenCapacityLost()); + $this->assertTrue($whenCapacityLost->isWhenHasLostCapacity()); $this->assertFalse($whenCapacityLost->isUnknown()); $this->assertTrue($unknown->isUnknown()); - $this->assertFalse($unknown->isWhenCapacityLost()); + $this->assertFalse($unknown->isWhenHasLostCapacity()); } } diff --git a/service-front/app/test/CommonTest/Helper/EntityTestHelper.php b/service-front/app/test/CommonTest/Helper/EntityTestHelper.php index a24f22da85..b270137964 100644 --- a/service-front/app/test/CommonTest/Helper/EntityTestHelper.php +++ b/service-front/app/test/CommonTest/Helper/EntityTestHelper.php @@ -5,12 +5,9 @@ namespace CommonTest\Helper; use Common\Entity\CombinedLpa; -use Common\Entity\LpaStore\LpaStore; use Common\Entity\Person; -use Common\Entity\Sirius\SiriusLpa; use Common\Enum\HowAttorneysMakeDecisions; use Common\Enum\LifeSustainingTreatment; -use Common\Enum\LpaStatus; use Common\Enum\LpaType; use Common\Enum\WhenTheLpaCanBeUsed; use DateTimeImmutable; @@ -25,7 +22,6 @@ public static function makePerson( ?string $county = 'County', ?DateTimeImmutable $dob = new DateTimeImmutable(TestData::TESTDATESTRING), ?string $email = 'email@example.com', - ?string $firstname = 'Firstname', ?string $firstnames = 'Firstnames', ?string $name = 'Name', ?string $otherNames = 'Other names', @@ -33,7 +29,6 @@ public static function makePerson( ?string $surname = 'Surname', ?string $systemStatus = 'System status', ?string $town = 'Town', - ?string $type = 'Type', ?string $uId = 'UID', ): Person { return new Person( @@ -44,7 +39,6 @@ public static function makePerson( county: $county, dob: $dob, email: $email, - firstname: $firstname, firstnames: $firstnames, name: $name, otherNames: $otherNames, @@ -52,36 +46,35 @@ public static function makePerson( surname: $surname, systemStatus: $systemStatus, town: $town, - type: $type, uId: $uId ); } public static function makeCombinedLpa( - ?bool $applicationHasGuidance = true, - ?bool $applicationHasRestrictions = true, - ?string $applicationType = 'applicationType', + ?bool $applicationHasGuidance = false, + ?bool $applicationHasRestrictions = false, + ?string $applicationType = 'Classic', ?array $attorneys = [], ?LpaType $caseSubtype = LpaType::PERSONAL_WELFARE, ?string $channel = 'channel', - ?DateTimeImmutable $dispatchDate = new DateTimeImmutable(TestData::TESTDATESTRING), + ?DateTimeImmutable $dispatchDate = null, ?Person $donor = null, - ?bool $hasSeveranceWarning = true, + ?bool $hasSeveranceWarning = null, ?HowAttorneysMakeDecisions $howAttorneysMakeDecisions = HowAttorneysMakeDecisions::SINGULAR, - ?DateTimeImmutable $invalidDate = new DateTimeImmutable(TestData::TESTDATESTRING), + ?DateTimeImmutable $invalidDate = null, ?LifeSustainingTreatment $lifeSustainingTreatment = LifeSustainingTreatment::OPTION_A, ?DateTimeImmutable $lpaDonorSignatureDate = new DateTimeImmutable(TestData::TESTDATESTRING), ?bool $lpaIsCleansed = true, ?string $onlineLpaId = 'onlineLpaId', ?DateTimeImmutable $receiptDate = new DateTimeImmutable(TestData::TESTDATESTRING), ?DateTimeImmutable $registrationDate = new DateTimeImmutable(TestData::TESTDATESTRING), - ?DateTimeImmutable $rejectedDate = new DateTimeImmutable(TestData::TESTDATESTRING), + ?DateTimeImmutable $rejectedDate = null, ?array $replacementAttorneys = [], ?string $status = 'Registered', - ?DateTimeImmutable $statusDate = new DateTimeImmutable(TestData::TESTDATESTRING), + ?DateTimeImmutable $statusDate = null, ?array $trustCorporations = [], ?string $uId = 'uId', - ?DateTimeImmutable $withdrawnDate = new DateTimeImmutable(TestData::TESTDATESTRING), + ?DateTimeImmutable $withdrawnDate = null, ?WhenTheLpaCanBeUsed $whenTheLpaCanBeUsed = WhenTheLpaCanBeUsed::WHEN_CAPACITY_LOST, ): CombinedLpa { if (count($attorneys) === 0) { @@ -97,31 +90,31 @@ public static function makeCombinedLpa( } return new CombinedLpa( - applicationHasGuidance: $applicationHasGuidance, + applicationHasGuidance: $applicationHasGuidance, applicationHasRestrictions: $applicationHasRestrictions, - applicationType: $applicationType, - attorneys: $attorneys, - caseSubtype: $caseSubtype, - channel: $channel, - dispatchDate: $dispatchDate, - donor: $donor, - hasSeveranceWarning: $hasSeveranceWarning, - howAttorneysMakeDecisions: $howAttorneysMakeDecisions, - invalidDate: $invalidDate, - lifeSustainingTreatment: $lifeSustainingTreatment, - lpaDonorSignatureDate: $lpaDonorSignatureDate, - lpaIsCleansed: $lpaIsCleansed, - onlineLpaId: $onlineLpaId, - receiptDate: $receiptDate, - registrationDate: $registrationDate, - rejectedDate: $rejectedDate, - replacementAttorneys: $replacementAttorneys, - status: $status, - statusDate: $statusDate, - trustCorporations: $trustCorporations, - uId: $uId, - withdrawnDate: $withdrawnDate, - whenTheLpaCanBeUsed: $whenTheLpaCanBeUsed + applicationType: $applicationType, + attorneys: $attorneys, + caseSubtype: $caseSubtype, + channel: $channel, + dispatchDate: $dispatchDate, + donor: $donor, + hasSeveranceWarning: $hasSeveranceWarning, + howAttorneysMakeDecisions: $howAttorneysMakeDecisions, + invalidDate: $invalidDate, + lifeSustainingTreatment: $lifeSustainingTreatment, + lpaDonorSignatureDate: $lpaDonorSignatureDate, + lpaIsCleansed: $lpaIsCleansed, + onlineLpaId: $onlineLpaId, + receiptDate: $receiptDate, + registrationDate: $registrationDate, + rejectedDate: $rejectedDate, + replacementAttorneys: $replacementAttorneys, + status: $status, + statusDate: $statusDate, + trustCorporations: $trustCorporations, + uId: $uId, + whenTheLpaCanBeUsed: $whenTheLpaCanBeUsed, + withdrawnDate: $withdrawnDate ); } @@ -151,8 +144,8 @@ public static function makeSiriusLpa( ?string $uId = 'uId', ?DateTimeImmutable $withdrawnDate = null, ?WhenTheLpaCanBeUsed $whenTheLpaCanBeUsed = WhenTheLpaCanBeUsed::WHEN_CAPACITY_LOST, - ): SiriusLpa { - return new SiriusLpa( + ): CombinedLpa { + return new CombinedLpa( applicationHasGuidance: $applicationHasGuidance, applicationHasRestrictions: $applicationHasRestrictions, applicationType: $applicationType, @@ -176,76 +169,8 @@ public static function makeSiriusLpa( statusDate: $statusDate, trustCorporations: $trustCorporations, uId: $uId, - withdrawnDate: $withdrawnDate, - whenTheLpaCanBeUsed: $whenTheLpaCanBeUsed - ); - } - - public static function makeLpaStoreLpa( - ?bool $applicationHasGuidance = null, - ?bool $applicationHasRestrictions = null, - ?string $applicationType = null, - ?array $attorneys = [], - ?LpaType $caseSubtype = LpaType::PERSONAL_WELFARE, - ?string $channel = 'online', - ?DateTimeImmutable $dispatchDate = null, - ?Person $donor = null, - ?bool $hasSeveranceWarning = null, - ?HowAttorneysMakeDecisions $howAttorneysMakeDecisions = HowAttorneysMakeDecisions::SINGULAR, - ?DateTimeImmutable $invalidDate = null, - ?LifeSustainingTreatment $lifeSustainingTreatment = LifeSustainingTreatment::OPTION_A, - ?DateTimeImmutable $lpaDonorSignatureDate = new DateTimeImmutable(TestData::TESTDATESTRING), - ?bool $lpaIsCleansed = null, - ?string $onlineLpaId = null, - ?DateTimeImmutable $receiptDate = null, - ?DateTimeImmutable $registrationDate = new DateTimeImmutable(TestData::TESTDATESTRING), - ?DateTimeImmutable $rejectedDate = null, - ?array $replacementAttorneys = null, - ?string $status = 'Registered', - ?DateTimeImmutable $statusDate = null, - ?array $trustCorporations = [], - ?string $uId = 'uId', - ?DateTimeImmutable $withdrawnDate = null, - ?WhenTheLpaCanBeUsed $whenTheLpaCanBeUsed = WhenTheLpaCanBeUsed::WHEN_CAPACITY_LOST, - ): LpaStore { - if (!is_null($attorneys) && count($attorneys) === 0) { - $attorneys[] = EntityTestHelper::MakePerson(); - } - - if (!is_null($replacementAttorneys) && count($replacementAttorneys) === 0) { - $replacementAttorneys[] = EntityTestHelper::MakePerson(); - } - - if (!is_null($trustCorporations) && count($trustCorporations) === 0) { - $trustCorporations[] = EntityTestHelper::MakePerson(); - } - - return new LpaStore( - applicationHasGuidance : $applicationHasGuidance, - applicationHasRestrictions : $applicationHasRestrictions, - applicationType : $applicationType, - attorneys : $attorneys, - caseSubtype : $caseSubtype, - channel : $channel, - dispatchDate : $dispatchDate, - donor : $donor, - hasSeveranceWarning : $hasSeveranceWarning, - howAttorneysMakeDecisions : $howAttorneysMakeDecisions, - invalidDate : $invalidDate, - lifeSustainingTreatment : $lifeSustainingTreatment, - lpaDonorSignatureDate : $lpaDonorSignatureDate, - lpaIsCleansed : $lpaIsCleansed, - onlineLpaId : $onlineLpaId, - receiptDate : $receiptDate, - registrationDate : $registrationDate, - rejectedDate : $rejectedDate, - replacementAttorneys : $replacementAttorneys, - status : $status, - statusDate : $statusDate, - trustCorporations : $trustCorporations, - uId : $uId, - withdrawnDate : $withdrawnDate, - whenTheLpaCanBeUsed : $whenTheLpaCanBeUsed, + whenTheLpaCanBeUsed: $whenTheLpaCanBeUsed, + withdrawnDate: $withdrawnDate ); } } diff --git a/service-front/app/test/CommonTest/Service/Lpa/ParseLpaDataTest.php b/service-front/app/test/CommonTest/Service/Lpa/ParseLpaDataTest.php index 0de00ef78c..4a90e047d8 100644 --- a/service-front/app/test/CommonTest/Service/Lpa/ParseLpaDataTest.php +++ b/service-front/app/test/CommonTest/Service/Lpa/ParseLpaDataTest.php @@ -4,15 +4,18 @@ namespace CommonTest\Service\Lpa; +use Common\Entity\CombinedLpa; use Common\Entity\LpaStore\LpaStore; use Common\Entity\LpaStore\LpaStoreAttorney; use Common\Entity\LpaStore\LpaStoreDonor; use Common\Entity\LpaStore\LpaStoreTrustCorporations; +use Common\Entity\Person; use Common\Entity\Sirius\SiriusLpa; use Common\Entity\Sirius\SiriusLpaAttorney; use Common\Entity\Sirius\SiriusLpaDonor; use Common\Entity\Sirius\SiriusLpaTrustCorporations; use Common\Service\Features\FeatureEnabled; +use Common\Service\Lpa\Factory\PersonDataFormatter; use CommonTest\Helper\EntityTestHelper; use DateTimeImmutable; use PHPUnit\Framework\Attributes\CoversClass; @@ -50,6 +53,7 @@ class ParseLpaDataTest extends TestCase private ObjectProphecy|LpaDataFormatter $lpaDataFormatter; private ObjectProphecy|FeatureEnabled $featureEnabled; + private ObjectProphecy|PersonDataFormatter $personDataFormatter; public function setUp(): void { @@ -90,6 +94,7 @@ public function setUp(): void $this->lpaFactory = $this->prophesize(LpaFactory::class); $this->instAndPrefImagesFactory = $this->prophesize(InstAndPrefImagesFactory::class); $this->lpaDataFormatter = $this->prophesize(LpaDataFormatter::class); + $this->personDataFormatter = $this->prophesize(PersonDataFormatter::class); $this->featureEnabled = $this->prophesize(FeatureEnabled::class); } @@ -108,6 +113,7 @@ public function it_correctly_parses_an_lpa_api_response(): void $this->lpaFactory->reveal(), $this->instAndPrefImagesFactory->reveal(), $this->lpaDataFormatter->reveal(), + $this->personDataFormatter->reveal(), $this->featureEnabled->reveal() ); @@ -130,16 +136,18 @@ public function it_correctly_parses_an_lpa_api_response(): void #[Test] public function it_correctly_parses_an_combined_lpa_api_response(): void { - $combinedFormat = ParseLpaData::getMockedCombinedFormat(false); + $combinedFormat = json_decode(file_get_contents(__DIR__ . '../../../../fixtures/combined_lpa.json'), true); + $this->lpaFactory->createLpaFromData($this->lpaData['lpa'])->willReturn($combinedFormat); $this->lpaFactory->createCaseActorFromData($this->lpaData['actor']['details'])->willReturn($this->actor); $this->instAndPrefImagesFactory->createFromData($this->lpaData['iap'])->willReturn($this->iapImages); - $this->lpaDataFormatter->__invoke($combinedFormat)->willReturn($this->expectedSiriusLpa()); + $this->lpaDataFormatter->__invoke($combinedFormat)->willReturn($this->expectedLpa()); $sut = new ParseLpaData( $this->lpaFactory->reveal(), $this->instAndPrefImagesFactory->reveal(), $this->lpaDataFormatter->reveal(), + $this->personDataFormatter->reveal(), $this->featureEnabled->reveal() ); @@ -150,13 +158,13 @@ public function it_correctly_parses_an_combined_lpa_api_response(): void $this->lpaData['lpa'] = $combinedFormat; $result = $sut($this->lpaData); - $this->assertEquals($this->expectedSiriusLpa(), $result->lpa); + $this->assertEquals($this->expectedLpa(), $result->lpa); } - public function expectedSiriusLpa(): SiriusLpa + public function expectedLpa(): CombinedLpa { $attorneys = [ - new SiriusLpaAttorney( + new Person( addressLine1 : '9 high street', addressLine2 : '', addressLine3 : '', @@ -164,7 +172,6 @@ public function expectedSiriusLpa(): SiriusLpa county : '', dob : new DateTimeImmutable('1990-05-04'), email : '', - firstname : 'jean', firstnames : null, name : null, otherNames : null, @@ -172,10 +179,9 @@ public function expectedSiriusLpa(): SiriusLpa surname : 'sanderson', systemStatus : '1', town : '', - type : 'Primary', uId : '700000000815' ), - new SiriusLpaAttorney( + new Person( addressLine1 : '', addressLine2 : '', addressLine3 : '', @@ -183,7 +189,6 @@ public function expectedSiriusLpa(): SiriusLpa county : '', dob : new DateTimeImmutable('1975-10-05'), email : 'XXXXX', - firstname : 'Ann', firstnames : null, name : null, otherNames : null, @@ -191,12 +196,11 @@ public function expectedSiriusLpa(): SiriusLpa surname : 'Summers', systemStatus : '1', town : '', - type : 'Primary', uId : '7000-0000-0849' ), ]; - $donor = new SiriusLpaDonor( + $donor = new Person( addressLine1 : '81 Front Street', addressLine2 : 'LACEBY', addressLine3 : '', @@ -204,26 +208,18 @@ public function expectedSiriusLpa(): SiriusLpa county : '', dob : new DateTimeImmutable('1948-11-01'), email : 'RachelSanderson@opgtest.com', - firstname : 'Rachel', firstnames : null, - linked : [ - [ - 'id' => 7, - 'uId' => '700000000799', - ], - ], name : null, otherNames : null, postcode : 'DN37 5SH', surname : 'Sanderson', systemStatus : null, town : '', - type : 'Primary', uId : '700000000799' ); $trustCorporations = [ - new SiriusLpaTrustCorporations( + new Person( addressLine1 : 'Street 1', addressLine2 : 'Street 2', addressLine3 : 'Street 3', @@ -231,7 +227,6 @@ public function expectedSiriusLpa(): SiriusLpa county : 'County', dob : null, email : null, - firstname : 'trust', firstnames : null, name : null, otherNames : null, @@ -239,7 +234,6 @@ public function expectedSiriusLpa(): SiriusLpa surname : 'test', systemStatus : '1', town : 'Town', - type : 'Primary', uId : '7000-0015-1998', ), ]; diff --git a/service-front/app/test/CommonTest/View/Twig/LpaExtensionTest.php b/service-front/app/test/CommonTest/View/Twig/LpaExtensionTest.php index dae4d44543..b64d45554f 100644 --- a/service-front/app/test/CommonTest/View/Twig/LpaExtensionTest.php +++ b/service-front/app/test/CommonTest/View/Twig/LpaExtensionTest.php @@ -110,7 +110,6 @@ public function it_concatenates_an_address_array_into_a_comma_separated_string_f county: 'County', dob: new DateTimeImmutable('22-12-1997'), email: 'email@email.com', - firstname: 'John', firstnames: 'Jonathan', name: 'name', otherNames: 'Maverick', @@ -118,7 +117,6 @@ public function it_concatenates_an_address_array_into_a_comma_separated_string_f surname: 'Doe', systemStatus: 'true', town: 'Town', - type: 'Primary', uId: '700000012345', ); diff --git a/service-front/app/test/fixtures/combined_lpa.json b/service-front/app/test/fixtures/combined_lpa.json index 06f46ed9c5..354e2cad8a 100644 --- a/service-front/app/test/fixtures/combined_lpa.json +++ b/service-front/app/test/fixtures/combined_lpa.json @@ -10,7 +10,7 @@ "addressLine3": "", "country": "", "county": "", - "dob": "1990-05-04 00:00:00.000000+0000", + "dob": "1990-05-04", "email": "", "firstname": "jean", "firstnames": null, @@ -29,7 +29,7 @@ "addressLine3": "", "country": "", "county": "", - "dob": "1975-10-05 00:00:00.000000+0000", + "dob": "1975-10-05", "email": "XXXXX", "firstname": "Ann", "firstnames": null, @@ -52,7 +52,7 @@ "addressLine3": "", "country": "", "county": "", - "dob": "1948-11-01 00:00:00.000000+0000", + "dob": "1948-11-01", "email": "RachelSanderson@opgtest.com", "firstname": "Rachel", "firstnames": null, @@ -80,7 +80,25 @@ "receiptDate": "2014-09-26 00:00:00.000000+0000", "registrationDate": "2019-10-10 00:00:00.000000+0000", "rejectedDate": null, - "replacementAttorneys": [], + "replacementAttorneys": [ + { + "addressLine1": "Address Line 1", + "addressLine2": "Address Line 2", + "addressLine3": "Address Line 3", + "country": "Country", + "county": "County", + "dob": "2000-01-31", + "email": "email@example.com", + "firstnames": "Firstnames", + "name": "Name", + "otherNames": "Other names", + "postcode": "Postcode", + "surname": "Surname", + "systemStatus": "1", + "town": "Town", + "uId": "7000-0000-0849" + } + ], "status": "Registered", "statusDate": null, "trustCorporations": [ diff --git a/service-front/app/test/fixtures/test_lpa.json b/service-front/app/test/fixtures/test_lpa.json index 9b42662b1b..1f3168f25a 100644 --- a/service-front/app/test/fixtures/test_lpa.json +++ b/service-front/app/test/fixtures/test_lpa.json @@ -67,7 +67,7 @@ "addressLine3": "" } ], - "systemStatus": true, + "systemStatus": "true", "companyName": "" }, { @@ -92,7 +92,7 @@ "addressLine3": "" } ], - "systemStatus": true, + "systemStatus": "true", "companyName": "" } ], @@ -121,7 +121,7 @@ "middlenames": null, "surname": "test", "otherNames": null, - "systemStatus": true, + "systemStatus": "true", "companyName": "trust corporation" } ],