Skip to content

Commit

Permalink
UML-3570 refactor templates to work with combined format summary (#2904)
Browse files Browse the repository at this point in the history
* UML-3619 Convert incoming LPAs to combined format (repository layer)

* feature flag by separate templates

* drop unused template

* UML-3570 fixed relevant test cases, added more tests, added new enum and cast, updated fixtures


* UML-3570 updated tests, added verbose to ui test

* revert api changes (to be extracted to new branch)

* more api revert

* ensure LpaType is accessible, fix addresses, make mock combined data dynamic

* UML-3570 removed original, inactive and active attoryneys

* reinstate mocked values

* bump cov

* revert api

* fix sniffs

* fix sniffs

* UML-3570 updated tests

* UML-3570 updated WhenTheLpaCanBeUsed.php lint

* UML-3570 added more test cases and updated templates with feature flags

* UML-3570 added new combined lpa templates depending on if the feature flag is enabled
address test cases

* UML-3570 added more tests for code coverage

* UML-3570 reverted change

* UML-3570 removed final references to original, inactive, and active attorneys

* UML-3570 updated tests
updated references to addressline1,2,3
added getters

* UML-3570 fixed - referenced incorrect key for attoryneys

---------

Co-authored-by: Alex Saunders <[email protected]>
Co-authored-by: SeemaMenon <[email protected]>
  • Loading branch information
3 people authored Dec 2, 2024
1 parent 1145cae commit 85d4675
Show file tree
Hide file tree
Showing 33 changed files with 762 additions and 103 deletions.
27 changes: 6 additions & 21 deletions service-api/app/features/context/Integration/LpaContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,7 @@ public function iProvideTheAttorneyDetailsFromAValidPaperLPADocument(): void
$lpaMatchResponse = $addOlderLpa->validateRequest($this->userId, $data);

$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);
$expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray);
$expectedResponse = new AccessForAllValidation(
new ActorMatch(
new SiriusPerson(json_decode(json_encode($this->lpa->attorneys[0]), true)),
Expand Down Expand Up @@ -1594,10 +1591,7 @@ public function iConfirmDetailsShownToMeOfTheFoundLPAAreCorrect(): void
$lpaMatchResponse = $addOlderLpa->validateRequest($this->userId, $data);

$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);
$expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray);
$expectedResponse = new AccessForAllValidation(
new ActorMatch(
new SiriusPerson(json_decode(json_encode($lpa->donor), true)),
Expand Down Expand Up @@ -1875,10 +1869,7 @@ public function iProvideDetailsThatMatchAValidPaperDocument($firstnames, $lastna
$lpaMatchResponse = $addAccessForAllLpa->validateRequest($this->userId, $data);

$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);
$expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray);
$expectedResponse = new AccessForAllValidation(
new ActorMatch(
new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)),
Expand Down Expand Up @@ -1938,10 +1929,7 @@ public function iProvideTheDetailsFromAValidPaperLPADocument(): void
$lpaMatchResponse = $addOlderLpa->validateRequest($this->userId, $data);

$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);
$expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray);
$expectedResponse = new AccessForAllValidation(
new ActorMatch(
new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)),
Expand Down Expand Up @@ -2739,13 +2727,10 @@ public function iRequestForANewActivationKeyAgain(): void
);

$addOlderLpa = $this->container->get(AddAccessForAllLpa::class);
$response = $addOlderLpa->validateRequest($this->userId, $data);
$response = $addOlderLpa->validateRequest($this->userId, $data);

$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);
$expectedLpa = new \App\Service\Lpa\SiriusLpa($expectedLpaArray);
$expectedResponse = new AccessForAllValidation(
new ActorMatch(
new SiriusPerson(json_decode(json_encode($this->lpa->donor), true)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function validateDetails(string $code, string $uid, string $dob): ?array
$actor = ($this->resolveActor)($lpa->getData(), $actorUid);

$lpaData = $lpa->getData();
unset($lpaData['original_attorneys']);

return [
'actor' => $actor,
Expand Down
3 changes: 0 additions & 3 deletions service-api/app/src/App/src/Service/Lpa/SiriusLpa.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public function __construct(private array $lpa)
}

$this->transformArrayToSiriusPersons('attorneys');
$this->transformArrayToSiriusPersons('original_attorneys');
$this->transformArrayToSiriusPersons('inactiveAttorneys');
$this->transformArrayToSiriusPersons('activeAttorneys');
$this->transformArrayToSiriusPersons('trustCorporations');
}

Expand Down
15 changes: 1 addition & 14 deletions service-api/app/src/App/src/Service/Lpa/SiriusLpaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,13 @@ public function getByUid(string $uid): ?LpaInterface
$lpaData = $lpa->getData();

if ($lpaData['attorneys'] !== null) {
$lpaData['original_attorneys'] = $lpaData['attorneys'];
$lpaData['activeAttorneys'] = array_values(
$lpaData['attorneys'] = array_values(
array_filter($lpaData['attorneys'], function ($attorney) {
return ($this->getAttorneyStatus)($attorney) === AttorneyStatus::ACTIVE_ATTORNEY;
})
);
}

if ($lpaData['attorneys'] !== null) {
$lpaData['original_attorneys'] = $lpaData['attorneys'];
$lpaData['inactiveAttorneys'] = array_values(
array_filter($lpaData['attorneys'], function ($attorney) {
return ($this->getAttorneyStatus)($attorney) === AttorneyStatus::INACTIVE_ATTORNEY;
})
);
}

if ($lpaData['trustCorporations'] !== null) {
$lpaData['trustCorporations'] = array_values(
array_filter($lpaData['trustCorporations'], function ($trustCorporation) {
Expand Down Expand Up @@ -93,7 +83,6 @@ public function getByUserLpaActorToken(string $token, string $userId): ?array
}

$lpaData = $lpa->getData();
unset($lpaData['original_attorneys']);

$result = [
'user-lpa-actor-token' => $map['Id'],
Expand Down Expand Up @@ -183,7 +172,6 @@ public function getByViewerCode(string $viewerCode, string $donorSurname, ?strin
}

$lpaData = $lpa->getData();
unset($lpaData['original_attorneys']);

$result = [
'date' => $lpa->getLookupTime()->format('c'),
Expand Down Expand Up @@ -241,7 +229,6 @@ private function lookupAndFormatLpas(array $lpaActorMaps): array
$actor = ($this->resolveActor)($lpaData, (string) $item['ActorId']);

$added = $item['Added']->format('Y-m-d H:i:s');
unset($lpaData['original_attorneys']);

//Extract and return only LPA's where status is Registered or Cancelled
if (($this->isValidLpa)($lpaData)) {
Expand Down
17 changes: 0 additions & 17 deletions service-api/app/test/AppTest/Service/Lpa/SiriusLpaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,8 @@ public function can_get_by_id(): void
[
'attorneys' => [
['id' => 1, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => true],
['id' => 2, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => false],
['id' => 3, 'firstname' => 'A', 'systemStatus' => true],
['id' => 4, 'surname' => 'B', 'systemStatus' => true],
['id' => 5, 'systemStatus' => true],
],
'original_attorneys' => [
['id' => 1, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => true],
['id' => 2, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => false],
['id' => 3, 'firstname' => 'A', 'systemStatus' => true],
['id' => 4, 'surname' => 'B', 'systemStatus' => true],
['id' => 5, 'systemStatus' => true],
],
'trustCorporations' => [
new SiriusPerson(
Expand All @@ -135,14 +126,6 @@ public function can_get_by_id(): void
'systemStatus' => true,
]),
],
'inactiveAttorneys' => [
['id' => 2, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => false],
],
'activeAttorneys' => [
['id' => 1, 'firstname' => 'A', 'surname' => 'B', 'systemStatus' => true],
['id' => 3, 'firstname' => 'A', 'systemStatus' => true],
['id' => 4, 'surname' => 'B', 'systemStatus' => true],
],
],
),
$lpaResponse->getLookupTime()
Expand Down
2 changes: 1 addition & 1 deletion service-front/app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"cs-check": "@dc-php /app/vendor/bin/phpcs",
"cs-fix": "@dc-php /app/vendor/bin/phpcbf",
"unit-test": "@dc-php /app/vendor/bin/phpunit --colors=always",
"ui-test": "@dc-php -dapc.enable_cli=1 /app/vendor/bin/behat -p acceptance --colors",
"ui-test": "@dc-php -dapc.enable_cli=1 /app/vendor/bin/behat -p acceptance --colors -vv",
"int-test": "@dc-php /app/vendor/bin/behat -p integration --colors",
"extract": "@dc-php console.php translation:update"
}
Expand Down
42 changes: 41 additions & 1 deletion service-front/app/features/actor-view-lpa.feature
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,44 @@ Feature: View an LPA that I have added to my account
Given I have added an LPA to my account
And I am on the dashboard page
When I request to view an LPA where all actors do not have an also known by name
Then I will not see the also known as field
Then I will not see the also known as field

@integration @ui @ff:support_datastore_lpas:true
Scenario Outline: The user can view a Combined LPA added to their account
Given I have added a Combined LPA to my account
And I am on the dashboard page
When I request to view an LPA which status is "<status>"
Then The full LPA is displayed with the correct <message>
Examples:
| status | message |
| Registered | This LPA is registered |

@integration @ui @ff:support_datastore_lpas:true
Scenario: The user cannot view a Combined LPA added to their account whose status has changed Revoked
Given I have added a Combined LPA to my account
And I am on the dashboard page
And The LPA has been revoked
When I request to view an LPA whose status changed to Revoked
Then I am taken back to the dashboard page
And The Revoked LPA details are not displayed

@ui @ff:support_datastore_lpas:true
Scenario: The user can view a Combined LPA and see trust corporation details in attorney sections
Given I have added a Combined LPA to my account
And I am on the dashboard page
When I request to view an LPA which has a trust corporation added
Then I can see the trust corporation trust corporation in the list of attorneys

@ui @ff:support_datastore_lpas:true
Scenario: The user can only see active attorneys in the attorney section of Combined LPA summary
Given I have added a Combined LPA to my account
And I am on the dashboard page
When I request to view an LPA which has an inactive attorney named 'Harold Stallman'
Then I will not see 'Harold Stallman' in the attorney section of LPA summary

@ui @ff:support_datastore_lpas:true
Scenario: Show also known as when an actor has other names defined of Combined LPA
Given I have added a Combined LPA to my account
And I am on the dashboard page
When I request to view an LPA with a donor who is also known as 'Ezra'
Then I will see Ezra in the also known as field
8 changes: 4 additions & 4 deletions service-front/app/features/bootstrap/behat.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
//'debug' => true,
],
'feature_flags' => [
'delete_lpa_feature' => true,
'instructions_and_preferences' => true,
'allow_gov_one_login' => true,
'support_datastore_lpas' => false,
'delete_lpa_feature' => true,
'instructions_and_preferences' => true,
'allow_gov_one_login' => true,
'support_datastore_lpas' => false,
],
'notify' => [
'api' => [
Expand Down
28 changes: 28 additions & 0 deletions service-front/app/features/context/BaseUiContextTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
namespace BehatTest\Context;

use Aws\MockHandler as AwsMockHandler;
use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\MinkExtension\Context\MinkContext;
use BehatTest\Context\UI\BaseUiContext;
use BehatTest\Context\UI\SharedState;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use Monolog\Handler\TestHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;

/**
* Trait BaseUiContextTrait
Expand All @@ -37,6 +41,30 @@ public function gatherContexts(BeforeScenarioScope $scope): void
$this->awsFixtures = $this->base->awsFixtures;
}

/**
* @AfterScenario
*/
public function outputLogsOnFailure(AfterScenarioScope $scope): void
{
$logger = $this->base->container->get(LoggerInterface::class);

if ($logger instanceof Logger) {
/** @var TestHandler $testHandler */
$testHandler = array_filter(
$logger->getHandlers(),
fn ($handler) => $handler instanceof TestHandler
)[0];

if (!$scope->getTestResult()->isPassed()) {
foreach ($testHandler->getRecords() as $record) {
print_r($record['formatted']);
}
}

$logger->reset();
}
}

/**
* Checks the response for a particular header being set with a specified value
*
Expand Down
59 changes: 59 additions & 0 deletions service-front/app/features/context/UI/LpaContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3111,6 +3111,7 @@ public function iRequestToViewAnLPAWithADonorWhoIsAlsoKnownAs($name): void
{
$this->ui->assertPageContainsText('View LPA summary');
$this->lpa->donor->otherNames = $name;

$this->mockApiGetLpaByIdAndGetImagesById();
}

Expand Down Expand Up @@ -3246,4 +3247,62 @@ public function iReturnToTheDashboard(): void
{
$this->ui->assertPageAddress('/lpa/dashboard');
}

/**
* @Given I have added a Combined LPA to my account
*/
public function iHaveAddedACombinedLpaToMyAccount(): void
{
$this->iHaveBeenGivenAccessToUseACombinedLPAViaCredentials();

$this->dashboardLPAs = [$this->userLpaActorToken => $this->lpaData];
}

/**
* @Given I have been given access to use a Combined LPA via credentials
*/
public function iHaveBeenGivenAccessToUseACombinedLPAViaCredentials(): void
{
$this->lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/combined_lpa.json'));

$this->userLpaActorToken = '987654321';
$this->actorId = 9;

$this->lpaData = [
'user-lpa-actor-token' => $this->userLpaActorToken,
'date' => 'today',
'actor' => [
'type' => 'primary-attorney',
'details' => [
'addresses' => [
[
'addressLine1' => '',
'addressLine2' => '',
'addressLine3' => '',
'country' => '',
'county' => '',
'id' => 0,
'postcode' => '',
'town' => '',
'type' => 'Primary',
],
],
'companyName' => null,
'dob' => '1975-10-05',
'email' => 'string',
'firstname' => 'Ian',
'id' => 0,
'middlenames' => null,
'salutation' => 'Mr',
'surname' => 'Deputy',
'systemStatus' => true,
'uId' => '700000000054',
],
],
'applicationHasRestrictions' => true,
'applicationHasGuidance' => false,
'lpa' => $this->lpa,
'added' => '2021-10-5 12:00:00',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use Actor\Form\CancelCode;
use Common\Entity\CaseActor;
use Common\Entity\Lpa;
use Common\Entity\Person;
use Common\Exception\InvalidRequestException;
use Common\Handler\{AbstractHandler, CsrfGuardAware, Traits\CsrfGuard, Traits\Session, Traits\User, UserAware};
use Common\Service\Features\FeatureEnabled;
use Common\Service\Lpa\{LpaService, ViewerCodeService};
use DateTime;
use Laminas\Diactoros\Response\HtmlResponse;
Expand Down Expand Up @@ -36,6 +38,7 @@ public function __construct(
private LpaService $lpaService,
private ViewerCodeService $viewerCodeService,
LoggerInterface $logger,
private FeatureEnabled $featureEnabled,
) {
parent::__construct($renderer, $urlHelper, $logger);

Expand Down Expand Up @@ -159,10 +162,15 @@ public function handle(ServerRequestInterface $request): ResponseInterface
);
}

$templateName = 'actor::check-access-codes';
if (($this->featureEnabled)('support_datastore_lpas')) {
$templateName = 'actor::check-access-codes-combined-lpa';
}

/** @var FlashMessagesInterface $flash */
$flash = $request->getAttribute(FlashMessageMiddleware::FLASH_ATTRIBUTE);

return new HtmlResponse($this->renderer->render('actor::check-access-codes', [
return new HtmlResponse($this->renderer->render($templateName, [
'actorToken' => $actorLpaToken,
'user' => $user,
'lpa' => $lpa,
Expand All @@ -171,7 +179,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
]));
}

private function idMatch(CaseActor $actor, array $code): bool
private function idMatch(CaseActor|Person $actor, array $code): bool
{
return $actor->getId() === $code['ActorId']
|| intval($actor->getUId()) === $code['ActorId'];
Expand Down
Loading

0 comments on commit 85d4675

Please sign in to comment.