Skip to content

Commit

Permalink
Fixup address extraction in caster for Sirius Lpas
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperaj committed Dec 16, 2024
1 parent 08719df commit bb34d82
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public function cast(mixed $value, ObjectMapper $hydrator): ?string
return $value[$this->fieldName];
}

// little recursive magic to handle Sirius' multiple address structure.
if (is_array($value) && is_array($value = array_pop($value))) {
return $this->cast($value, $hydrator);
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,80 +8,77 @@
use App\Entity\Sirius\SiriusLpaAttorney;
use App\Entity\Sirius\SiriusLpaDonor;
use App\Entity\Sirius\SiriusLpaTrustCorporation;
use App\Enum\ActorStatus;
use App\Enum\LifeSustainingTreatment;
use App\Enum\LpaType;
use App\Service\Features\FeatureEnabled;
use App\Service\Lpa\LpaDataFormatter;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;

class CanHydrateSiriusToModerniseFormatTest extends TestCase
{
use ProphecyTrait;

private LpaDataFormatter $lpaDataFormatter;
private FeatureEnabled|ObjectProphecy $featureEnabled;

public function setUp(): void
{
$this->featureEnabled = $this->prophesize(FeatureEnabled::class);
$this->lpaDataFormatter = new LpaDataFormatter();
}

public function expectedSiriusLpa(): SiriusLpa
{
return new SiriusLpa(
applicationHasGuidance: false,
applicationHasRestrictions: false,
applicationType: 'Classic',
attorneys: [
new SiriusLpaAttorney(
addressLine1: '9 high street',
addressLine2: '',
addressLine3: '',
country: '',
county: '',
dob: new DateTimeImmutable('1990-05-04'),
email: '',
firstname: 'jean',
id: '9',
middlenames: null,
otherNames: null,
postcode: 'DN37 5SH',
surname: 'sanderson',
systemStatus: '1',
town: '',
type: 'Primary',
uId: '700000000815'
),
new SiriusLpaAttorney(
addressLine1: '',
addressLine2: '',
addressLine3: '',
country: '',
county: '',
dob: new DateTimeImmutable('1975-10-05'),
email: 'XXXXX',
firstname: 'Ann',
id: '12',
middlenames: null,
otherNames: null,
postcode: '',
surname: 'Summers',
systemStatus: '1',
town: '',
type: 'Primary',
uId: '700000000849'
),
],
attorneyActDecisions: null,
caseSubtype: LpaType::fromShortName('personal-welfare'),
channel: null,
dispatchDate: null,
donor: new SiriusLpaDonor(
applicationHasGuidance: false,
applicationHasRestrictions: false,
applicationType: 'Classic',
attorneys: [
new SiriusLpaAttorney(
addressLine1: '9 high street',
addressLine2: '',
addressLine3: '',
country: '',
county: '',
dob: new DateTimeImmutable('1990-05-04'),
email: '',
firstname: 'jean',
id: '9',
middlenames: '',
otherNames: null,
postcode: 'DN37 5SH',
surname: 'sanderson',
systemStatus: ActorStatus::ACTIVE,
town: '',
uId: '700000000815'
),
new SiriusLpaAttorney(
addressLine1: '',
addressLine2: '',
addressLine3: '',
country: '',
county: '',
dob: new DateTimeImmutable('1975-10-05'),
email: 'XXXXX',
firstname: 'Ann',
id: '12',
middlenames: null,
otherNames: null,
postcode: '',
surname: 'Summers',
systemStatus: ActorStatus::ACTIVE,
town: '',
uId: '700000000849'
),
],
caseAttorneyJointly: false,
caseAttorneyJointlyAndJointlyAndSeverally: false,
caseAttorneyJointlyAndSeverally: true,
caseSubtype: LpaType::fromShortName('personal-welfare'),
channel: null,
dispatchDate: null,
donor: new SiriusLpaDonor(
addressLine1: '81 Front Street',
addressLine2: 'LACEBY',
addressLine3: '',
Expand All @@ -92,74 +89,67 @@ public function expectedSiriusLpa(): SiriusLpa
firstname: 'Rachel',
id: '7',
linked: [
[
'id' => 7,
'uId' => '700000000799',
],
],
[
'id' => 7,
'uId' => '700000000799',
],
],
middlenames: 'Emma',
otherNames: null,
postcode: 'DN37 5SH',
surname: 'Sanderson',
systemStatus: null,
town: '',
type: 'Primary',
uId: '700000000799'
),
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: [
new SiriusLpaTrustCorporation(
addressLine1: 'Street 1',
addressLine2: 'Street 2',
addressLine3: 'Street 3',
companyName: 'trust corporation',
country: 'GB',
county: 'County',
dob: null,
email: null,
firstname: 'trust',
id: '3485',
middlenames: null,
otherNames: null,
postcode: 'ABC 123',
surname: 'test',
systemStatus: '1',
town: 'Town',
type: 'Primary',
uId: '700000151998',
),
],
uId: '700000000047',
withdrawnDate: null
hasSeveranceWarning: null,
invalidDate: null,
lifeSustainingTreatment: LifeSustainingTreatment::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: [
new SiriusLpaTrustCorporation(
addressLine1: 'Street 1',
addressLine2: 'Street 2',
addressLine3: 'Street 3',
companyName: 'trust corporation',
country: 'GB',
county: 'County',
dob: null,
email: null,
firstname: 'trust',
id: '3485',
middlenames: null,
otherNames: null,
postcode: 'ABC 123',
surname: 'test',
systemStatus: ActorStatus::ACTIVE,
town: 'Town',
uId: '700000151998',
),
],
uId: '700000000047',
whenTheLpaCanBeUsed: null,
withdrawnDate: null
);
}

#[Test]
public function can_hydrate_sirius_lpa_to_modernise_format(): void
{
$this->featureEnabled
->__invoke('support_datastore_lpas')
->willReturn(true);

$lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/test_lpa.json'), true);

$expectedSiriusLpa = $this->expectedSiriusLpa();

$combinedSiriusLpa = ($this->lpaDataFormatter)($lpa);

$this->assertIsObject($combinedSiriusLpa);

$this->assertEquals($expectedSiriusLpa, $combinedSiriusLpa);
}
}
41 changes: 21 additions & 20 deletions service-api/app/test/AppTest/Entity/SiriusLpaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public function it_can_be_instantiated(): void
country: null,
county: null,
dob: new DateTimeImmutable(
'1962-4-18', new DateTimeZone('UTC')
),
'1962-4-18',
new DateTimeZone('UTC')
),
email: null,
firstname: null,
id: null,
Expand All @@ -51,24 +52,24 @@ public function it_can_be_instantiated(): void
channel: 'online',
dispatchDate: null,
donor: new SiriusLpaDonor(
addressLine1: null,
addressLine2: null,
addressLine3: null,
country: null,
county: null,
dob: new DateTimeImmutable('1962-4-18', new DateTimeZone('UTC')),
email: null,
firstname: null,
id: null,
linked: null,
middlenames: null,
otherNames: null,
postcode: null,
surname: null,
systemStatus: null,
town: null,
uId: '700000000012',
),
addressLine1: null,
addressLine2: null,
addressLine3: null,
country: null,
county: null,
dob: new DateTimeImmutable('1962-4-18', new DateTimeZone('UTC')),
email: null,
firstname: null,
id: null,
linked: null,
middlenames: null,
otherNames: null,
postcode: null,
surname: null,
systemStatus: null,
town: null,
uId: '700000000012',
),
hasSeveranceWarning: null,
invalidDate: null,
lifeSustainingTreatment: null,
Expand Down

0 comments on commit bb34d82

Please sign in to comment.