From bc986192dbc9d576ca739aa24f6fd5ffb1addcfb Mon Sep 17 00:00:00 2001 From: Allen Annom <49309320+allenannom@users.noreply.github.com> Date: Mon, 4 Nov 2024 09:41:38 +0000 Subject: [PATCH] returning mocked combined lpa data for the frontend (#2900) * returning mocked combined lpa data for the frontend * fixed ParseLpaDataTest.php * fixed ParseLpaDataTest.php --- .../Common/src/Service/Lpa/ParseLpaData.php | 167 ++++++++- .../Service/Lpa/ParseLpaDataTest.php | 317 +++++++++++++++++- 2 files changed, 479 insertions(+), 5 deletions(-) diff --git a/service-front/app/src/Common/src/Service/Lpa/ParseLpaData.php b/service-front/app/src/Common/src/Service/Lpa/ParseLpaData.php index 8aa2675bd9..c650081c6c 100644 --- a/service-front/app/src/Common/src/Service/Lpa/ParseLpaData.php +++ b/service-front/app/src/Common/src/Service/Lpa/ParseLpaData.php @@ -5,6 +5,7 @@ namespace Common\Service\Lpa; use ArrayObject; +use Common\Service\Features\FeatureEnabled; use Exception; use Common\Service\Lpa\Factory\LpaDataFormatter; @@ -21,6 +22,7 @@ public function __construct( private LpaFactory $lpaFactory, private InstAndPrefImagesFactory $imagesFactory, private LpaDataFormatter $lpaDataFormatter, + private FeatureEnabled $featureEnabled, ) { } @@ -46,10 +48,10 @@ public function __invoke(array $data): ArrayObject case 'lpa': //introduce feature flag here #3551 //the lpaData array converted to object using hydrator - if ($this->featureFlags['support_datastore_lpas'] ?? false) { - $data['lpa'] = ($this->lpaDataFormatter)($dataItem); - } - else { + if (($this->featureEnabled)('support_datastore_lpas')) { + $mockedCombinedLpa = $this->getMockedCombinedFormat(); + $data['lpa'] = ($this->lpaDataFormatter)($mockedCombinedLpa); + } else { $data['lpa'] = $this->lpaFactory->createLpaFromData($dataItem); } break; @@ -68,4 +70,161 @@ public function __invoke(array $data): ArrayObject return new ArrayObject($data, ArrayObject::ARRAY_AS_PROPS); } + + private function getMockedCombinedFormat(): array + { + return [ + 'id' => 2, + 'uId' => '700000000047', + 'receiptDate' => '2014-09-26', + 'registrationDate' => '2019-10-10', + 'rejectedDate' => null, + 'donor' => [ + 'id' => 7, + 'uId' => '700000000799', + 'linked' => [['id' => 7, 'uId' => '700000000799']], + 'dob' => '1948-11-01', + 'email' => 'RachelSanderson@opgtest.com', + 'salutation' => 'Mr', + 'firstname' => 'Rachel', + 'middlenames' => 'Emma', + 'surname' => 'Sanderson', + 'addresses' => [ + [ + 'id' => 7, + 'town' => '', + 'county' => '', + 'postcode' => 'DN37 5SH', + 'country' => '', + 'type' => 'Primary', + 'addressLine1' => '81 Front Street', + 'addressLine2' => 'LACEBY', + 'addressLine3' => '', + ], + ], + 'companyName' => null, + ], + 'applicationType' => 'Classic', + 'caseSubtype' => 'hw', + 'status' => 'Registered', + 'lpaIsCleansed' => true, + 'caseAttorneySingular' => false, + 'caseAttorneyJointlyAndSeverally' => true, + 'caseAttorneyJointly' => false, + 'caseAttorneyJointlyAndJointlyAndSeverally' => false, + 'onlineLpaId' => 'A33718377316', + 'cancellationDate' => null, + 'attorneys' => [ + [ + 'id' => 9, + 'uId' => '700000000815', + 'dob' => '1990-05-04', + 'email' => '', + 'salutation' => '', + 'firstname' => 'jean', + 'middlenames' => '', + 'surname' => 'sanderson', + 'addresses' => [ + [ + 'id' => 9, + 'town' => '', + 'county' => '', + 'postcode' => 'DN37 5SH', + 'country' => '', + 'type' => 'Primary', + 'addressLine1' => '9 high street', + 'addressLine2' => '', + 'addressLine3' => '', + ], + ], + 'systemStatus' => true, + 'companyName' => '', + ], + [ + 'id' => 12, + 'uId' => '7000-0000-0849', + 'dob' => '1975-10-05', + 'email' => 'XXXXX', + 'salutation' => 'Mrs', + 'firstname' => 'Ann', + 'middlenames' => '', + 'surname' => 'Summers', + 'addresses' => [ + [ + 'id' => 12, + 'town' => '', + 'county' => '', + 'postcode' => '', + 'country' => '', + 'type' => 'Primary', + 'addressLine1' => '', + 'addressLine2' => '', + 'addressLine3' => '', + ], + ], + 'systemStatus' => true, + 'companyName' => '', + ], + ], + 'replacementAttorneys' => [], + 'trustCorporations' => [ + [ + 'addresses' => [ + [ + 'id' => 3207, + 'town' => 'Town', + 'county' => 'County', + 'postcode' => 'ABC 123', + 'country' => 'GB', + 'type' => 'Primary', + 'addressLine1' => 'Street 1', + 'addressLine2' => 'Street 2', + 'addressLine3' => 'Street 3', + ], + ], + 'id' => 3485, + 'uId' => '7000-0015-1998', + 'dob' => null, + 'email' => null, + 'salutation' => null, + 'firstname' => 'trust', + 'middlenames' => null, + 'surname' => 'test', + 'otherNames' => null, + 'systemStatus' => true, + 'companyName' => 'trust corporation', + ], + ], + 'certificateProviders' => [ + [ + 'id' => 11, + 'uId' => '7000-0000-0831', + 'dob' => null, + 'email' => null, + 'salutation' => 'Miss', + 'firstname' => 'Danielle', + 'middlenames' => null, + 'surname' => 'Hart ', + 'addresses' => [ + [ + 'id' => 11, + 'town' => '', + 'county' => '', + 'postcode' => 'SK14 0RH', + 'country' => '', + 'type' => 'Primary', + 'addressLine1' => '50 Fordham Rd', + 'addressLine2' => 'HADFIELD', + 'addressLine3' => '', + ], + ], + ], + ], + 'attorneyActDecisions' => null, + 'applicationHasRestrictions' => false, + 'applicationHasGuidance' => false, + 'lpaDonorSignatureDate' => '2012-12-12', + 'lifeSustainingTreatment' => 'Option A', + ]; + } } diff --git a/service-front/app/test/CommonTest/Service/Lpa/ParseLpaDataTest.php b/service-front/app/test/CommonTest/Service/Lpa/ParseLpaDataTest.php index f667c031dd..996e570cf2 100644 --- a/service-front/app/test/CommonTest/Service/Lpa/ParseLpaDataTest.php +++ b/service-front/app/test/CommonTest/Service/Lpa/ParseLpaDataTest.php @@ -4,6 +4,14 @@ namespace CommonTest\Service\Lpa; +use Common\Entity\Sirius\SiriusLpa; +use Common\Entity\Sirius\SiriusLpaAttorney; +use Common\Entity\Sirius\SiriusLpaDonor; +use Common\Entity\Sirius\SiriusLpaTrustCorporations; +use Common\Enum\LpaType; +use Common\Enum\LifeSustainingTreatment; +use Common\Service\Features\FeatureEnabled; +use DateTimeImmutable; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use Common\Entity\CaseActor; @@ -37,6 +45,7 @@ class ParseLpaDataTest extends TestCase private ObjectProphecy|InstAndPrefImagesFactory $instAndPrefImagesFactory; private ObjectProphecy|LpaDataFormatter $lpaDataFormatter; + private ObjectProphecy|FeatureEnabled $featureEnabled; public function setUp(): void { @@ -77,6 +86,7 @@ public function setUp(): void $this->lpaFactory = $this->prophesize(LpaFactory::class); $this->instAndPrefImagesFactory = $this->prophesize(InstAndPrefImagesFactory::class); $this->lpaDataFormatter = $this->prophesize(LpaDataFormatter::class); + $this->featureEnabled = $this->prophesize(FeatureEnabled::class); } /** @@ -93,8 +103,14 @@ public function it_correctly_parses_an_lpa_api_response(): void $sut = new ParseLpaData( $this->lpaFactory->reveal(), $this->instAndPrefImagesFactory->reveal(), - $this->lpaDataFormatter->reveal() + $this->lpaDataFormatter->reveal(), + $this->featureEnabled->reveal() ); + + $this->featureEnabled + ->__invoke('support_datastore_lpas') + ->willReturn(false); + $result = $sut( [ $this->lpaId => $this->lpaData, @@ -106,4 +122,303 @@ public function it_correctly_parses_an_lpa_api_response(): void $this->assertEquals($this->actor, $result->{$this->lpaId}->actor['details']); $this->assertEquals($this->iapImages, $result->{$this->lpaId}->iap); } + + #[Test] + public function it_correctly_parses_an_combined_lpa_api_response(): void + { + $combinedFormat = $this->getMockedCombinedFormat(); + $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()); + + $sut = new ParseLpaData( + $this->lpaFactory->reveal(), + $this->instAndPrefImagesFactory->reveal(), + $this->lpaDataFormatter->reveal(), + $this->featureEnabled->reveal() + ); + + $this->featureEnabled + ->__invoke('support_datastore_lpas') + ->willReturn(true); + + $this->lpaData['lpa'] = $combinedFormat; + $result = $sut( + $this->lpaData + ); + + $this->assertEquals($this->expectedSiriusLpa(), $result->lpa); + } + + private function getMockedCombinedFormat(): array + { + return [ + 'id' => 2, + 'uId' => '700000000047', + 'receiptDate' => '2014-09-26', + 'registrationDate' => '2019-10-10', + 'rejectedDate' => null, + 'donor' => [ + 'id' => 7, + 'uId' => '700000000799', + 'linked' => [['id' => 7, 'uId' => '700000000799']], + 'dob' => '1948-11-01', + 'email' => 'RachelSanderson@opgtest.com', + 'salutation' => 'Mr', + 'firstname' => 'Rachel', + 'middlenames' => 'Emma', + 'surname' => 'Sanderson', + 'addresses' => [ + [ + 'id' => 7, + 'town' => '', + 'county' => '', + 'postcode' => 'DN37 5SH', + 'country' => '', + 'type' => 'Primary', + 'addressLine1' => '81 Front Street', + 'addressLine2' => 'LACEBY', + 'addressLine3' => '', + ], + ], + 'companyName' => null, + ], + 'applicationType' => 'Classic', + 'caseSubtype' => 'hw', + 'status' => 'Registered', + 'lpaIsCleansed' => true, + 'caseAttorneySingular' => false, + 'caseAttorneyJointlyAndSeverally' => true, + 'caseAttorneyJointly' => false, + 'caseAttorneyJointlyAndJointlyAndSeverally' => false, + 'onlineLpaId' => 'A33718377316', + 'cancellationDate' => null, + 'attorneys' => [ + [ + 'id' => 9, + 'uId' => '700000000815', + 'dob' => '1990-05-04', + 'email' => '', + 'salutation' => '', + 'firstname' => 'jean', + 'middlenames' => '', + 'surname' => 'sanderson', + 'addresses' => [ + [ + 'id' => 9, + 'town' => '', + 'county' => '', + 'postcode' => 'DN37 5SH', + 'country' => '', + 'type' => 'Primary', + 'addressLine1' => '9 high street', + 'addressLine2' => '', + 'addressLine3' => '', + ], + ], + 'systemStatus' => true, + 'companyName' => '', + ], + [ + 'id' => 12, + 'uId' => '7000-0000-0849', + 'dob' => '1975-10-05', + 'email' => 'XXXXX', + 'salutation' => 'Mrs', + 'firstname' => 'Ann', + 'middlenames' => '', + 'surname' => 'Summers', + 'addresses' => [ + [ + 'id' => 12, + 'town' => '', + 'county' => '', + 'postcode' => '', + 'country' => '', + 'type' => 'Primary', + 'addressLine1' => '', + 'addressLine2' => '', + 'addressLine3' => '', + ], + ], + 'systemStatus' => true, + 'companyName' => '', + ], + ], + 'replacementAttorneys' => [], + 'trustCorporations' => [ + [ + 'addresses' => [ + [ + 'id' => 3207, + 'town' => 'Town', + 'county' => 'County', + 'postcode' => 'ABC 123', + 'country' => 'GB', + 'type' => 'Primary', + 'addressLine1' => 'Street 1', + 'addressLine2' => 'Street 2', + 'addressLine3' => 'Street 3', + ], + ], + 'id' => 3485, + 'uId' => '7000-0015-1998', + 'dob' => null, + 'email' => null, + 'salutation' => null, + 'firstname' => 'trust', + 'middlenames' => null, + 'surname' => 'test', + 'otherNames' => null, + 'systemStatus' => true, + 'companyName' => 'trust corporation', + ], + ], + 'certificateProviders' => [ + [ + 'id' => 11, + 'uId' => '7000-0000-0831', + 'dob' => null, + 'email' => null, + 'salutation' => 'Miss', + 'firstname' => 'Danielle', + 'middlenames' => null, + 'surname' => 'Hart ', + 'addresses' => [ + [ + 'id' => 11, + 'town' => '', + 'county' => '', + 'postcode' => 'SK14 0RH', + 'country' => '', + 'type' => 'Primary', + 'addressLine1' => '50 Fordham Rd', + 'addressLine2' => 'HADFIELD', + 'addressLine3' => '', + ], + ], + ], + ], + 'attorneyActDecisions' => null, + 'applicationHasRestrictions' => false, + 'applicationHasGuidance' => false, + 'lpaDonorSignatureDate' => '2012-12-12', + 'lifeSustainingTreatment' => 'Option A', + ]; + } + + public function expectedSiriusLpa(): SiriusLpa + { + return new SiriusLpa( + applicationHasGuidance: false, + applicationHasRestrictions: false, + applicationType : 'Classic', + attorneyActDecisions : null, + attorneys: [ + new SiriusLpaAttorney( + addressLine1 : '9 high street', + addressLine2 : '', + addressLine3 : '', + country : '', + county : '', + dob : new DateTimeImmutable('1990-05-04'), + email : '', + firstname : 'jean', + firstnames : null, + name : null, + otherNames : null, + postcode : 'DN37 5SH', + surname : 'sanderson', + systemStatus : '1', + town : '', + type : 'Primary', + uId : '700000000815' + ), + new SiriusLpaAttorney( + addressLine1 : '', + addressLine2 : '', + addressLine3 : '', + country : '', + county : '', + dob : new DateTimeImmutable('1975-10-05'), + email : 'XXXXX', + firstname : 'Ann', + firstnames : null, + name : null, + otherNames : null, + postcode : '', + surname : 'Summers', + systemStatus : '1', + town : '', + type : 'Primary', + uId : '7000-0000-0849' + ), + ], + caseSubtype : LpaType::fromShortName('personal-welfare'), + channel : null, + dispatchDate : null, + donor : 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' + ), + hasSeveranceWarning : null, + invalidDate : null, + lifeSustainingTreatment : LifeSustainingTreatment::fromShortName('Option A'), + lpaDonorSignatureDate : new DateTimeImmutable('2012-12-12'), + lpaIsCleansed : true, + onlineLpaId : 'A33718377316', + receiptDate : new DateTimeImmutable('2014-09-26'), + registrationDate : new DateTimeImmutable('2019-10-10'), + rejectedDate : null, + replacementAttorneys : [], + status : 'Registered', + statusDate : null, + trustCorporations : [ + new SiriusLpaTrustCorporations( + addressLine1 : 'Street 1', + addressLine2 : 'Street 2', + addressLine3 : 'Street 3', + country : 'GB', + county : 'County', + dob : null, + email : null, + firstname : 'trust', + firstnames : null, + name : null, + otherNames : null, + postcode : 'ABC 123', + surname : 'test', + systemStatus : '1', + town : 'Town', + type : 'Primary', + uId : '7000-0015-1998', + ), + ], + uId : '700000000047', + withdrawnDate : null + ); + } + }