diff --git a/service-api/app/src/App/src/Exception/ActorDateOfBirthNotSetException.php b/service-api/app/src/App/src/Exception/ActorDateOfBirthNotSetException.php new file mode 100644 index 0000000000..f7f87941e7 --- /dev/null +++ b/service-api/app/src/App/src/Exception/ActorDateOfBirthNotSetException.php @@ -0,0 +1,20 @@ +logger->debug( 'Doing actor data comparison against actor with id {actor_id}', [ - 'actor_id' => $actor->getUid(), - 'to_match' => $matchData, - 'actor_data' => array_merge($actorData, ['dob' => $actor->getDob()]), + 'actor_id' => $actor->getUid(), + 'to_match' => $matchData, ] ); $match = self::MATCH; + try { + $match = $actor->getDob()->format('Y-m-d') !== $matchData['dob'] + ? $match | self::NO_MATCH__DOB + : $match; + } catch (ActorDateOfBirthNotSetException $exception) { + $this->logger->warning( + 'Actor DOB is null', + [ + 'actor_id' => $actor->getUid(), + 'error' => $exception->getMessage(), + ] + ); + + return self::NO_MATCH__DOB; + } - $match = $actor->getDob()->format('Y-m-d') !== $matchData['dob'] - ? $match | self::NO_MATCH__DOB - : $match; $match = $actorData['first_names'] !== $matchData['first_names'] ? $match | self::NO_MATCH__FIRSTNAMES : $match; diff --git a/service-api/app/src/App/src/Service/Lpa/SiriusPerson.php b/service-api/app/src/App/src/Service/Lpa/SiriusPerson.php index 03dc1f8a47..966f8bd081 100644 --- a/service-api/app/src/App/src/Service/Lpa/SiriusPerson.php +++ b/service-api/app/src/App/src/Service/Lpa/SiriusPerson.php @@ -4,11 +4,13 @@ namespace App\Service\Lpa; +use App\Exception\ActorDateOfBirthNotSetException; use App\Service\Lpa\AccessForAll\AddAccessForAllActorInterface; use App\Service\Lpa\FindActorInLpa\ActorMatchingInterface; use App\Service\Lpa\GetAttorneyStatus\GetAttorneyStatusInterface; use App\Service\Lpa\GetTrustCorporationStatus\GetTrustCorporationStatusInterface; use ArrayAccess; +use Exception; use DateTimeImmutable; use DateTimeInterface; use IteratorAggregate; @@ -81,8 +83,15 @@ public function getPostcode(): string return (string)$this->person['addresses'][0]['postcode']; } + /** + * @throws Exception + */ public function getDob(): DateTimeInterface { + if (is_null($this->person['dob'])) { + throw new ActorDateOfBirthNotSetException('Actor DOB is not set'); + } + return new DateTimeImmutable($this->person['dob']); } diff --git a/service-api/app/test/AppTest/Service/Lpa/FindActorInLpaTest.php b/service-api/app/test/AppTest/Service/Lpa/FindActorInLpaTest.php index 2613bb54f8..8ef9b85be0 100644 --- a/service-api/app/test/AppTest/Service/Lpa/FindActorInLpaTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/FindActorInLpaTest.php @@ -9,6 +9,7 @@ use App\Entity\Sirius\SiriusLpa as CombinedSiriusLpa; use App\Entity\Sirius\SiriusLpaAttorney; use App\Entity\Sirius\SiriusLpaDonor; +use App\Exception\ActorDateOfBirthNotSetException; use App\Service\Lpa\FindActorInLpa; use App\Service\Lpa\FindActorInLpa\ActorMatch; use App\Service\Lpa\GetAttorneyStatus; @@ -50,6 +51,7 @@ public function returns_actor_and_lpa_details_if_match_found(?ActorMatch $expect $this->ghostAttorneyFixtureOld(), $this->multipleAddressAttorneyFixtureOld(), $this->activeAttorneyFixtureOld(), + $this->nullDOBAttorneyFixtureOld(), ], ], $this->loggerProphecy->reveal(), @@ -71,9 +73,13 @@ public function returns_actor_and_lpa_details_if_match_found(?ActorMatch $expect ->__invoke($this->activeAttorneyFixtureOld()) ->willReturn(AttorneyStatus::ACTIVE_ATTORNEY); // active attorney + $this->getAttorneyStatusProphecy + ->__invoke($this->nullDOBAttorneyFixtureOld()) + ->willReturn(AttorneyStatus::ACTIVE_ATTORNEY); // null DoB + $sut = new FindActorInLpa( $this->getAttorneyStatusProphecy->reveal(), - $this->loggerProphecy->reveal() + $this->loggerProphecy->reveal(), ); $matchData = $sut($lpa, $userData); @@ -90,6 +96,7 @@ public function returns_actor_and_lpa_details_if_match_found_combined_sirius( $this->inactiveAttorneyFixture(), $this->ghostAttorneyFixture(), $this->activeAttorneyFixture(), + $this->nullDOBAttorneyFixture(), ]; $lpa = new CombinedSiriusLpa( @@ -132,6 +139,10 @@ public function returns_actor_and_lpa_details_if_match_found_combined_sirius( ->__invoke($this->activeAttorneyFixture()) ->willReturn(AttorneyStatus::ACTIVE_ATTORNEY); // active attorney + $this->getAttorneyStatusProphecy + ->__invoke($this->nullDOBAttorneyFixture()) + ->willReturn(AttorneyStatus::ACTIVE_ATTORNEY); // null DoB + $sut = new FindActorInLpa( $this->getAttorneyStatusProphecy->reveal(), $this->loggerProphecy->reveal() @@ -442,4 +453,46 @@ private static function donorFixture(): SiriusLpaDonor uId: '700000001111' ); } + + public static function nullDOBAttorneyFixtureOld(): SiriusPerson + { + return new SiriusPerson( + [ + 'uId' => '7000000055555', + 'dob' => null, + 'firstname' => 'Testering', + 'surname' => 'Testing', + 'addresses' => [ + [ + 'postcode' => 'Ab1 2Cd', + ], + ], + 'systemStatus' => true, + ], + new Logger('test-output'), + ); + } + + public static function nullDOBAttorneyFixture(): SiriusLpaAttorney + { + return new SiriusLpaAttorney( + addressLine1: null, + addressLine2: null, + addressLine3: null, + country: null, + county: null, + dob: null, + email: null, + firstname: 'Testering', + id: '7', + middlenames: null, + otherNames: null, + postcode: 'PY1 3Kd', + surname: 'Person', + systemStatus: null, + town: null, + type: null, + uId: '700000001111' + ); + } }