diff --git a/service-api/app/src/App/src/Service/Lpa/ResolveActor/SiriusHasActorTrait.php b/service-api/app/src/App/src/Service/Lpa/ResolveActor/SiriusHasActorTrait.php index a56960e4e8..32bcb85783 100644 --- a/service-api/app/src/App/src/Service/Lpa/ResolveActor/SiriusHasActorTrait.php +++ b/service-api/app/src/App/src/Service/Lpa/ResolveActor/SiriusHasActorTrait.php @@ -29,8 +29,13 @@ public function hasActor(string $uid): ?LpaActor private function isADonor(string $uid): ?LpaActor { - foreach ($this->getDonor()['linked'] as $value) { - if ((string) $value['id'] === $uid || $value['uId'] === $uid) { + $linkedDonors = $this->getDonor()->linked ?? $this->getDonor()['linked']; + + foreach ($linkedDonors as $linkedDonor) { + $linkedDonorId = $linkedDonor->id ?? $linkedDonor['id']; + $linkedDonorUid = $linkedDonor->uId ?? $linkedDonor['uId']; + + if ((string) $linkedDonorId === $uid || $linkedDonorUid === $uid) { return new LpaActor($this->getDonor(), ActorType::DONOR); } } diff --git a/service-api/app/test/AppTest/Service/Lpa/ResolveActor/CombinedLpaHasActorTraitTest.php b/service-api/app/test/AppTest/Service/Lpa/ResolveActor/CombinedLpaHasActorTraitTest.php new file mode 100644 index 0000000000..463f85f155 --- /dev/null +++ b/service-api/app/test/AppTest/Service/Lpa/ResolveActor/CombinedLpaHasActorTraitTest.php @@ -0,0 +1,214 @@ +mock = new SiriusLpa( + $applicationHasGuidance = false, + $applicationHasRestrictions = false, + $applicationType = 'Classic', + $attorneyActDecisions = null, + $attorneys = [ + [ + 'addressLine1' => '9 high street', + 'addressLine2' => '', + 'addressLine3' => '', + 'country' => '', + 'county' => '', + 'dob' => null, + 'email' => '', + 'firstname' => 'A', + 'firstnames' => null, + 'name' => null, + 'otherNames' => null, + 'postcode' => 'DN37 5SH', + 'surname' => 'B', + 'systemStatus' => '1', + 'town' => '', + 'type' => 'Primary', + 'uId' => '345678901', + ], + [ + 'addressLine1' => '', + 'addressLine2' => '', + 'addressLine3' => '', + 'country' => '', + 'county' => '', + 'dob' => null, + 'email' => 'XXXXX', + 'firstname' => 'B', + 'firstnames' => null, + 'name' => null, + 'otherNames' => null, + 'postcode' => '', + 'surname' => 'C', + 'systemStatus' => '1', + 'town' => '', + 'type' => 'Primary', + 'uId' => '456789012', + ], + [ + 'addressLine1' => '', + 'addressLine2' => '', + 'addressLine3' => '', + 'country' => '', + 'county' => '', + 'dob' => null, + 'email' => 'XXXXX', + 'firstname' => 'C', + 'firstnames' => null, + 'name' => null, + 'otherNames' => null, + 'postcode' => '', + 'surname' => 'D', + 'systemStatus' => '1', + 'town' => '', + 'type' => 'Primary', + 'uId' => '567890123', + ], + ], + $caseSubtype = LpaType::fromShortName('personal-welfare'), + $channel = null, + $dispatchDate = null, + $donor = (object)[ + 'addressLine1' => '81 Front Street', + 'addressLine2' => 'LACEBY', + 'addressLine3' => '', + 'country' => '', + 'county' => '', + 'dob' => null, + 'email' => 'RachelSanderson@opgtest.com', + 'firstname' => 'Rachel', + 'firstnames' => null, + 'name' => null, + 'otherNames' => null, + 'postcode' => 'DN37 5SH', + 'surname' => 'Sanderson', + 'systemStatus' => null, + 'town' => '', + 'type' => 'Primary', + 'uId' => '123456789', + 'linked' => [ + [ + 'id' => 1, + 'uId' => '123456789', + ], + [ + 'id' => 2, + 'uId' => '234567890', + ], + ], + ], + $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 = [ + [ + 'addressLine1' => 'Street 1', + 'addressLine2' => 'Street 2', + 'addressLine3' => 'Street 3', + 'country' => 'GB', + 'county' => 'County', + 'dob' => null, + 'email' => null, + 'firstname' => 'trust', + 'firstnames' => null, + 'name' => 'A', + 'otherNames' => null, + 'postcode' => 'ABC 123', + 'surname' => 'test', + 'systemStatus' => '1', + 'town' => 'Town', + 'type' => 'Primary', + 'uId' => '678901234', + ], + [ + 'addressLine1' => 'Street 1', + 'addressLine2' => 'Street 2', + 'addressLine3' => 'Street 3', + 'country' => 'GB', + 'county' => 'County', + 'dob' => null, + 'email' => null, + 'firstname' => 'trust', + 'firstnames' => null, + 'name' => 'B', + 'otherNames' => null, + 'postcode' => 'ABC 123', + 'surname' => 'test', + 'systemStatus' => '1', + 'town' => 'Town', + 'type' => 'Primary', + 'uId' => '789012345', + ], + ], + $uId = '700000000047', + $withdrawnDate = null + ); + } + + #[Test] + public function does_not_find_nonexistant_actor(): void + { + $result = $this->mock->hasActor('012345678'); + + $this->assertNull($result); + } + + #[Test] + public function finds_a_donor_actor(): void + { + $result = $this->mock->hasActor('123456789'); + + $this->assertInstanceOf(LpaActor::class, $result); + $this->assertEquals(ActorType::DONOR, $result->actorType); + } + + #[Test] + public function finds_an_attorney_actor(): void + { + $result = $this->mock->hasActor('456789012'); + + $this->assertInstanceOf(LpaActor::class, $result); + $this->assertEquals('B', $result->actor['firstname']); + $this->assertEquals(ActorType::ATTORNEY, $result->actorType); + } + + #[Test] + public function finds_a_trust_corporation_actor(): void + { + $result = $this->mock->hasActor('789012345'); + + $this->assertInstanceOf(LpaActor::class, $result); + $this->assertEquals('B', $result->actor['name']); + $this->assertEquals(ActorType::TRUST_CORPORATION, $result->actorType); + } +}