Skip to content

Commit

Permalink
UML-3750 added exception for null DOB (#2984)
Browse files Browse the repository at this point in the history
* UML-3750 added exception for null DOB

* UML-3750 updated tests, added explicity exception

* UML-3750 moved try catch block to cover match logic

* UML-3750 added logger
  • Loading branch information
allenannom authored Dec 19, 2024
1 parent 10c58c4 commit 6b2ef66
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Exception;

use Fig\Http\Message\StatusCodeInterface;
use Throwable;

class ActorDateOfBirthNotSetException extends AbstractApiException
{
public const MESSAGE = 'Actor date of birth is not set';
public const TITLE = 'DOB Not Found';
public const CODE = StatusCodeInterface::STATUS_NOT_FOUND;

public function __construct(?string $message = null, array $additionalData = [], ?Throwable $previous = null)
{
parent::__construct(self::TITLE, $message, self::CODE, $additionalData, $previous);
}
}
24 changes: 18 additions & 6 deletions service-api/app/src/App/src/Service/Lpa/FindActorInLpa.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Service\Lpa;

use App\Exception\ActorDateOfBirthNotSetException;
use App\Service\Lpa\FindActorInLpa\ActorMatch;
use App\Service\Lpa\FindActorInLpa\ActorMatchingInterface;
use App\Service\Lpa\FindActorInLpa\FindActorInLpaInterface;
Expand Down Expand Up @@ -129,17 +130,28 @@ private function checkForActorMatch(ActorMatchingInterface $actor, array $matchD
$this->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;
Expand Down
9 changes: 9 additions & 0 deletions service-api/app/src/App/src/Service/Lpa/SiriusPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
}

Expand Down
55 changes: 54 additions & 1 deletion service-api/app/test/AppTest/Service/Lpa/FindActorInLpaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand All @@ -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);
Expand All @@ -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(
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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'
);
}
}

0 comments on commit 6b2ef66

Please sign in to comment.