Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UML-3671 rework find actor lpa #2878

Merged
merged 52 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e3a7321
accept new combined lpa
nickdavis2001 Oct 10, 2024
6453bf8
tidy up refactor to make this file easier to work with
nickdavis2001 Oct 10, 2024
7e7bf71
2 more refactors
nickdavis2001 Oct 10, 2024
578f07e
WIP tests
nickdavis2001 Oct 16, 2024
68f7169
refactor
nickdavis2001 Oct 16, 2024
2460edb
allow mutiple types
nickdavis2001 Oct 16, 2024
7c84610
refactor tests
nickdavis2001 Oct 16, 2024
3ce7614
make Person objects for fixtures for new combined obj
nickdavis2001 Oct 16, 2024
0c166bf
refactor
nickdavis2001 Oct 16, 2024
904e572
move GetAttorneyStatus to Person, refactor tests more, WIP (some tests
nickdavis2001 Oct 17, 2024
f80abc4
tests (WIP)
nickdavis2001 Oct 17, 2024
bddc3e5
refactor
nickdavis2001 Oct 17, 2024
673301c
more testa fixed
nickdavis2001 Oct 17, 2024
211ad53
all tests pass
nickdavis2001 Oct 17, 2024
4a240a8
take out inactive attorney for combined
nickdavis2001 Oct 17, 2024
531cb8a
Fix up points found in review.
cooperaj Nov 5, 2024
3352e77
Fix up points found in review.
cooperaj Nov 5, 2024
6d3f87c
integration tests (WIP_
nickdavis2001 Nov 7, 2024
e6a562c
WIP fix test
nickdavis2001 Nov 7, 2024
b7628cd
tests (WIP) commas
nickdavis2001 Nov 7, 2024
e74f597
tests (WIP)
nickdavis2001 Nov 7, 2024
0f38063
WUP fix some tests
nickdavis2001 Nov 11, 2024
29b12a1
WIP fix more tests
nickdavis2001 Nov 11, 2024
6597d84
WIP fixing tests
nickdavis2001 Nov 11, 2024
d1c5dca
API Integration tests all pass locally
nickdavis2001 Nov 11, 2024
30c3b27
Merge branch 'main' into UML-3671-findActorLpa
nickdavis2001 Nov 11, 2024
bffe018
fix acceptance test
nickdavis2001 Nov 11, 2024
225a2f8
Rework of how names are handled.
cooperaj Nov 12, 2024
1858e4b
Fix test that for some reason wasn't flagging as failing locally (eve…
cooperaj Nov 12, 2024
c16e10c
fix 7 further acceptance tests
nickdavis2001 Nov 13, 2024
3d445b2
fix tests
nickdavis2001 Nov 13, 2024
20c2a60
fix tests, uid renamed to lpaUId for clarity
nickdavis2001 Nov 14, 2024
e389097
Merge branch 'main' into UML-3671-findActorLpa
nickdavis2001 Nov 14, 2024
aba1bda
fussy linter
nickdavis2001 Nov 14, 2024
a8ba199
test serialisation of ActorMatch
nickdavis2001 Nov 14, 2024
09c678f
fix case sensitive array access which was broken, remove check for
nickdavis2001 Nov 14, 2024
e926ce3
Merge branch 'main' into UML-3671-findActorLpa
nickdavis2001 Nov 14, 2024
ab07778
Fix first name for interim Person object.
cooperaj Nov 14, 2024
61d2045
new test to provide coverage of new Sirius combined classes
nickdavis2001 Nov 14, 2024
b2467f9
Merge branch 'UML-3671-findActorLpa' of github.com:ministryofjustice/…
nickdavis2001 Nov 14, 2024
b4e4a79
Merge branch 'main' into UML-3671-findActorLpa
nickdavis2001 Nov 14, 2024
25c7478
linter fixes
nickdavis2001 Nov 14, 2024
1c710f2
fussy linter
nickdavis2001 Nov 14, 2024
a4ac8c9
fussy linter
nickdavis2001 Nov 14, 2024
d780c0b
LPAStore tests
nickdavis2001 Nov 14, 2024
cf001bc
test actorToken
nickdavis2001 Nov 14, 2024
c13cfae
fix more coverage and bugfix
nickdavis2001 Nov 14, 2024
bc3e2a4
coverage ignores for trust corp
nickdavis2001 Nov 14, 2024
93e893e
Cleanup interface attributes
cooperaj Nov 18, 2024
2bb0989
Merge branch 'main' into UML-3671-findActorLpa
cooperaj Nov 18, 2024
ba9fb17
Fix broken seeding for access for all lpas
cooperaj Nov 19, 2024
ad503b5
Merge branch 'main' into UML-3671-findActorLpa
cooperaj Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .idea/opg-use-an-lpa.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/phpunit.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3089,18 +3089,24 @@ public function iProvideTheDetailsFromAValidPaperDocumentThatAlreadyHasAnActivat

$expectedResponse = [
'donor' => [
'id' => $this->lpa->donor->id,
'uId' => $this->lpa->donor->uId,
'email' => $this->lpa->donor->email,
'dob' => $this->lpa->donor->dob,
'salutation' => $this->lpa->donor->salutation,
'firstname' => $this->lpa->donor->firstname,
'middlenames' => $this->lpa->donor->middlenames,
'surname' => $this->lpa->donor->surname,
'companyName' => $this->lpa->donor->companyName,
'addresses' => json_decode(json_encode($this->lpa->donor->addresses), true)
],
'caseSubtype' => $this->lpa->caseSubtype,
'activationKeyDueDate' => $activationKeyDueDate,
];
$this->ui->assertSession()->statusCodeEquals(StatusCodeInterface::STATUS_BAD_REQUEST);
$this->ui->assertSession()->responseContains('LPA has an activation key already');

Assert::assertEquals($expectedResponse, $this->getResponseAsJson()['data']);
Assert::assertEquals($expectedResponse,$this->getResponseAsJson()['data']);
}

/**
Expand Down
164 changes: 77 additions & 87 deletions service-api/app/features/context/Integration/LpaContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@

use App\DataAccess\Repository\Response\InstructionsAndPreferencesImages;
use App\DataAccess\Repository\Response\InstructionsAndPreferencesImagesResult;
use App\Entity\Sirius\SiriusLpa;
use App\Exception\ApiException;
use App\Exception\BadRequestException;
use App\Exception\NotFoundException;
use App\Service\ActorCodes\ActorCodeService;
use App\Service\Log\RequestTracing;
use App\Service\Lpa\AccessForAll\AccessForAllLpaService;
use App\Service\Lpa\AccessForAll\AccessForAllValidation;
use App\Service\Lpa\AccessForAll\AddAccessForAllLpa;
use App\Service\Lpa\AddLpa\AddLpa;
use App\Service\Lpa\FindActorInLpa\ActorMatch;
use App\Service\Lpa\GetInstructionsAndPreferencesImages;
use App\Service\Lpa\RemoveLpa;
use App\Service\Lpa\SiriusLpaManager;
Expand Down Expand Up @@ -309,16 +312,10 @@ public function iAttemptToAddTheSameLPAAgain(): void
);

$addLpaService = $this->container->get(AddLpa::class);

$expectedResponse = [
'donor' => [
'uId' => $this->lpa->donor->uId,
'firstname' => $this->lpa->donor->firstname,
'middlenames' => $this->lpa->donor->middlenames,
'surname' => $this->lpa->donor->surname,
],
'caseSubtype' => $this->lpa->caseSubtype,
'lpaActorToken' => $this->userLpaActorToken,
'donor' => new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)),
'caseSubtype' => $this->lpa->caseSubtype,
'lpaActorToken' => $this->userLpaActorToken,
];

try {
Expand Down Expand Up @@ -385,24 +382,19 @@ public function iProvideTheAttorneyDetailsFromAValidPaperLPADocument(): void

$lpaMatchResponse = $addOlderLpa->validateRequest($this->userId, $data);

$expectedResponse = [
'actor' => new SiriusPerson(json_decode(json_encode($this->lpa->attorneys[0]), true)),
'role' => 'attorney',
'lpa-id' => $this->lpa->uId,
'caseSubtype' => $this->lpa->caseSubtype,
'donor' => [
'uId' => $this->lpa->donor->uId,
'firstname' => $this->lpa->donor->firstname,
'middlenames' => $this->lpa->donor->middlenames,
'surname' => $this->lpa->donor->surname,
],
'attorney' => [
'uId' => $this->lpa->attorneys[0]->uId,
'firstname' => $this->lpa->attorneys[0]->firstname,
'middlenames' => $this->lpa->attorneys[0]->middlenames,
'surname' => $this->lpa->attorneys[0]->surname,
],
];
$expectedLpaArray = json_decode(json_encode($this->lpa), true);
$expectedLpaArray['original_attorneys'] = $expectedLpaArray['attorneys'];
$expectedLpaArray['activeAttorneys'] = $expectedLpaArray['attorneys'];
$expectedLpaArray['inactiveAttorneys'] = [];
$expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray);
$expectedResponse = new AccessForAllValidation(
new ActorMatch(
new SiriusPerson(json_decode(json_encode($this->lpa->attorneys[0]), true)),
'attorney',
$this->lpa->uId),
$expectedLpa,
null,
);

Assert::assertEquals($expectedResponse, $lpaMatchResponse);
}
Expand Down Expand Up @@ -1601,18 +1593,19 @@ public function iConfirmDetailsShownToMeOfTheFoundLPAAreCorrect(): void

$lpaMatchResponse = $addOlderLpa->validateRequest($this->userId, $data);

$expectedResponse = [
'actor' => new SiriusPerson(json_decode(json_encode($lpa->donor), true)),
'role' => 'donor',
'lpa-id' => $lpa->uId,
'caseSubtype' => $lpa->caseSubtype,
'donor' => [
'uId' => $lpa->donor->uId,
'firstname' => $lpa->donor->firstname,
'middlenames' => $lpa->donor->middlenames,
'surname' => $lpa->donor->surname,
],
];
$expectedLpaArray = json_decode(json_encode($this->lpa), true);
$expectedLpaArray['original_attorneys'] = $expectedLpaArray['attorneys'];
$expectedLpaArray['activeAttorneys'] = $expectedLpaArray['attorneys'];
$expectedLpaArray['inactiveAttorneys'] = [];
$expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray);
$expectedResponse = new AccessForAllValidation(
new ActorMatch(
new SiriusPerson(json_decode(json_encode($lpa->donor), true)),
'donor',
$lpa->uId),
$expectedLpa,
null,
);

Assert::assertEquals($expectedResponse, $lpaMatchResponse);
}
Expand Down Expand Up @@ -1881,18 +1874,19 @@ public function iProvideDetailsThatMatchAValidPaperDocument($firstnames, $lastna
$addAccessForAllLpa = $this->container->get(AddAccessForAllLpa::class);
$lpaMatchResponse = $addAccessForAllLpa->validateRequest($this->userId, $data);

$expectedResponse = [
'actor' => new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)),
'role' => 'donor',
'lpa-id' => $this->lpa->uId,
'caseSubtype' => $this->lpa->caseSubtype,
'donor' => [
'uId' => $this->lpa->donor->uId,
'firstname' => $this->lpa->donor->firstname,
'middlenames' => $this->lpa->donor->middlenames,
'surname' => $this->lpa->donor->surname,
],
];
$expectedLpaArray = json_decode(json_encode($this->lpa), true);
$expectedLpaArray['original_attorneys'] = $expectedLpaArray['attorneys'];
$expectedLpaArray['activeAttorneys'] = $expectedLpaArray['attorneys'];
$expectedLpaArray['inactiveAttorneys'] = [];
$expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray);
$expectedResponse = new AccessForAllValidation(
new ActorMatch(
new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)),
'donor',
$this->lpa->uId),
$expectedLpa,
null
);

Assert::assertEquals($expectedResponse, $lpaMatchResponse);
}
Expand Down Expand Up @@ -1943,18 +1937,19 @@ public function iProvideTheDetailsFromAValidPaperLPADocument(): void
$addOlderLpa = $this->container->get(AddAccessForAllLpa::class);
$lpaMatchResponse = $addOlderLpa->validateRequest($this->userId, $data);

$expectedResponse = [
'actor' => new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)),
'role' => 'donor',
'lpa-id' => $this->lpa->uId,
'caseSubtype' => $this->lpa->caseSubtype,
'donor' => [
'uId' => $this->lpa->donor->uId,
'firstname' => $this->lpa->donor->firstname,
'middlenames' => $this->lpa->donor->middlenames,
'surname' => $this->lpa->donor->surname,
],
];
$expectedLpaArray = json_decode(json_encode($this->lpa), true);
$expectedLpaArray['original_attorneys'] = $expectedLpaArray['attorneys'];
$expectedLpaArray['activeAttorneys'] = $expectedLpaArray['attorneys'];
$expectedLpaArray['inactiveAttorneys'] = [];
$expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray);
$expectedResponse = new AccessForAllValidation(
new ActorMatch(
new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)),
'donor',
$this->lpa->uId),
$expectedLpa,
null
);

Assert::assertEquals($expectedResponse, $lpaMatchResponse);
}
Expand Down Expand Up @@ -2015,12 +2010,7 @@ public function iProvideTheDetailsFromAValidPaperDocumentThatAlreadyHasAnActivat
Assert::assertEquals('LPA has an activation key already', $ex->getMessage());
Assert::assertEquals(
[
'donor' => [
'uId' => $this->lpa->donor->uId,
'firstname' => $this->lpa->donor->firstname,
'middlenames' => $this->lpa->donor->middlenames,
'surname' => $this->lpa->donor->surname,
],
'donor' => new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)),
'caseSubtype' => $this->lpa->caseSubtype,
'activationKeyDueDate' => $activationKeyDueDate,
],
Expand Down Expand Up @@ -2751,18 +2741,19 @@ public function iRequestForANewActivationKeyAgain(): void
$addOlderLpa = $this->container->get(AddAccessForAllLpa::class);
$response = $addOlderLpa->validateRequest($this->userId, $data);

$expectedResponse = [
'actor' => new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)),
'role' => 'donor',
'lpa-id' => $this->lpa->uId,
'caseSubtype' => $this->lpa->caseSubtype,
'donor' => [
'uId' => $this->lpa->donor->uId,
'firstname' => $this->lpa->donor->firstname,
'middlenames' => $this->lpa->donor->middlenames,
'surname' => $this->lpa->donor->surname,
],
];
$expectedLpaArray = json_decode(json_encode($this->lpa), true);
$expectedLpaArray['original_attorneys'] = $expectedLpaArray['attorneys'];
$expectedLpaArray['activeAttorneys'] = $expectedLpaArray['attorneys'];
$expectedLpaArray['inactiveAttorneys'] = [];
$expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray);
$expectedResponse = new AccessForAllValidation(
new ActorMatch(
new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)),
'donor',
$this->lpa->uId),
$expectedLpa,
null
);

Assert::assertEquals($expectedResponse, $response);
}
Expand Down Expand Up @@ -2834,13 +2825,12 @@ public function iProvideTheDetailsFromAValidPaperLPAWhichIHaveAlreadyAddedToMyAc
StatusCodeInterface::STATUS_OK,
$this->lpa
);

$expectedResponse = [
'donor' => [
'uId' => $this->lpa->donor->uId,
'firstname' => $this->lpa->donor->firstname,
'middlenames' => $this->lpa->donor->middlenames,
'surname' => $this->lpa->donor->surname,
'donor' => [
'uId' => $this->lpa->donor->uId,
'firstname' => $this->lpa->donor->firstname,
'middlenames' => $this->lpa->donor->middlenames,
'surname' => $this->lpa->donor->surname,
],
'caseSubtype' => $this->lpa->caseSubtype,
'lpaActorToken' => $this->userLpaActorToken,
Expand Down
40 changes: 34 additions & 6 deletions service-api/app/src/App/src/Entity/Lpa.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
use App\Enum\HowAttorneysMakeDecisions;
use App\Enum\LifeSustainingTreatment;
use App\Enum\LpaType;
use App\Service\Lpa\IsValid\IsValidInterface;
use App\Service\Lpa\ResolveActor\CombinedHasActorTrait;
use App\Service\Lpa\ResolveActor\HasActorInterface;
use DateTimeImmutable;
use EventSauce\ObjectHydrator\DoNotSerialize;
use DateTimeZone;
use JsonSerializable;

class Lpa implements JsonSerializable
class Lpa implements
JsonSerializable,
HasActorInterface,
IsValidInterface
{
use CombinedHasActorTrait;

public function __construct(
public readonly ?bool $applicationHasGuidance,
public readonly ?bool $applicationHasRestrictions,
Expand All @@ -22,7 +30,7 @@ public function __construct(
public readonly ?LpaType $caseSubtype,
public readonly ?string $channel,
public readonly ?DateTimeImmutable $dispatchDate,
public readonly ?object $donor,
public readonly ?Person $donor,
public readonly ?bool $hasSeveranceWarning,
public readonly ?DateTimeImmutable $invalidDate,
public readonly ?LifeSustainingTreatment $lifeSustainingTreatment,
Expand All @@ -41,17 +49,37 @@ public function __construct(
) {
}

#[DoNotSerialize]
public function jsonSerialize(): mixed
public function jsonSerialize(): array
{
$data = get_object_vars($this);

array_walk($data, function (&$value) {
if ($value instanceof DateTimeImmutable) {
$value = $value->format('Y-m-d H:i:s.uO');
$value = $value->setTimezone(new DateTimeZone('UTC'));
$value = $value->format('Y-m-d\TH:i:s\Z');
}
});

return $data;
}

public function getAttorneys(): array
{
return $this->attorneys ?? [];
}

public function getStatus(): string
{
return $this->status ?? '';
}

public function getUid(): string
{
return $this->uId ?? '';
}

private function getTrustCorporations(): array
{
return $this->trustCorporations ?? [];
}
}
Loading
Loading