From fd015c0614babfe07943b1ba64121d3cf1f7bfee Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Wed, 21 Aug 2024 20:17:57 +0100 Subject: [PATCH 01/20] UML-3460 Return LPA store LPAs via the new endpoint in the new format --- service-api/app/composer.json | 2 + .../app/src/App/src/Entity/Attorney.php | 9 ++ .../src/Entity/Casters/CastSingleDonor.php | 17 ++ .../src/Entity/Casters/CastToCaseSubtype.php | 17 ++ .../Casters/CastToLifeSustainingTreatment.php | 17 ++ .../Casters/CastToWhenTheLpaCanBeUsed.php | 17 ++ .../ExtractAddressLine1FromDataStore.php | 20 +++ .../Casters/ExtractCountryFromDataStore.php | 20 +++ .../Casters/ExtractTownFromDataStore.php | 20 +++ service-api/app/src/App/src/Entity/Donor.php | 64 ++++++++ service-api/app/src/App/src/Entity/Lpa.php | 57 +++++++ service-api/app/src/App/src/Entity/Person.php | 45 ++++++ .../src/App/src/Entity/TrustCorporations.php | 61 ++++++++ .../src/Enum/HowAttorneysMakeDecisions.php | 13 ++ .../App/src/Enum/LifeSustainingTreatment.php | 11 ++ service-api/app/src/App/src/Enum/LpaType.php | 22 +++ .../App/src/Service/Lpa/LpaDataFormatter.php | 36 +++++ .../AppTest/Service/Lpa/LpaServiceTest.php | 145 +++++++++++++++++- 18 files changed, 592 insertions(+), 1 deletion(-) create mode 100644 service-api/app/src/App/src/Entity/Attorney.php create mode 100644 service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php create mode 100644 service-api/app/src/App/src/Entity/Casters/CastToCaseSubtype.php create mode 100644 service-api/app/src/App/src/Entity/Casters/CastToLifeSustainingTreatment.php create mode 100644 service-api/app/src/App/src/Entity/Casters/CastToWhenTheLpaCanBeUsed.php create mode 100644 service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromDataStore.php create mode 100644 service-api/app/src/App/src/Entity/Casters/ExtractCountryFromDataStore.php create mode 100644 service-api/app/src/App/src/Entity/Casters/ExtractTownFromDataStore.php create mode 100644 service-api/app/src/App/src/Entity/Donor.php create mode 100644 service-api/app/src/App/src/Entity/Lpa.php create mode 100644 service-api/app/src/App/src/Entity/Person.php create mode 100644 service-api/app/src/App/src/Entity/TrustCorporations.php create mode 100644 service-api/app/src/App/src/Enum/HowAttorneysMakeDecisions.php create mode 100644 service-api/app/src/App/src/Enum/LifeSustainingTreatment.php create mode 100644 service-api/app/src/App/src/Enum/LpaType.php create mode 100644 service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php diff --git a/service-api/app/composer.json b/service-api/app/composer.json index b9078180b4..116a23d7e5 100644 --- a/service-api/app/composer.json +++ b/service-api/app/composer.json @@ -48,6 +48,7 @@ "aws/aws-sdk-php": "^3.93", "blazon/psr11-monolog": "^5.0", "elie29/zend-phpdi-config": "^9.0", + "eventsauce/object-hydrator": "^1.4", "facile-it/php-openid-client": "^0.3.5", "guzzlehttp/guzzle": "^7.8.1", "guzzlehttp/psr7": "^2.6.2", @@ -55,6 +56,7 @@ "laminas/laminas-cache-storage-adapter-apcu": "^2.4", "laminas/laminas-config-aggregator": "^1.0", "laminas/laminas-diactoros": "^3.0", + "laminas/laminas-hydrator": "^4.15", "laminas/laminas-stdlib": "^3.1", "mezzio/mezzio": "^3.0.1", "mezzio/mezzio-fastroute": "^3.0", diff --git a/service-api/app/src/App/src/Entity/Attorney.php b/service-api/app/src/App/src/Entity/Attorney.php new file mode 100644 index 0000000000..18d84326f0 --- /dev/null +++ b/service-api/app/src/App/src/Entity/Attorney.php @@ -0,0 +1,9 @@ +hydrateObject(Donor::class, $value); + } +} \ No newline at end of file diff --git a/service-api/app/src/App/src/Entity/Casters/CastToCaseSubtype.php b/service-api/app/src/App/src/Entity/Casters/CastToCaseSubtype.php new file mode 100644 index 0000000000..65c6960b0b --- /dev/null +++ b/service-api/app/src/App/src/Entity/Casters/CastToCaseSubtype.php @@ -0,0 +1,17 @@ +value; + } +} \ No newline at end of file diff --git a/service-api/app/src/App/src/Entity/Casters/CastToLifeSustainingTreatment.php b/service-api/app/src/App/src/Entity/Casters/CastToLifeSustainingTreatment.php new file mode 100644 index 0000000000..592150396b --- /dev/null +++ b/service-api/app/src/App/src/Entity/Casters/CastToLifeSustainingTreatment.php @@ -0,0 +1,17 @@ +value; + } +} \ No newline at end of file diff --git a/service-api/app/src/App/src/Entity/Casters/CastToWhenTheLpaCanBeUsed.php b/service-api/app/src/App/src/Entity/Casters/CastToWhenTheLpaCanBeUsed.php new file mode 100644 index 0000000000..d1edd9d52e --- /dev/null +++ b/service-api/app/src/App/src/Entity/Casters/CastToWhenTheLpaCanBeUsed.php @@ -0,0 +1,17 @@ +value; + } +} \ No newline at end of file diff --git a/service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromDataStore.php b/service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromDataStore.php new file mode 100644 index 0000000000..8db2837bd7 --- /dev/null +++ b/service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromDataStore.php @@ -0,0 +1,20 @@ + self::PERSONAL_WELFARE, + 'property-and-affairs' => self::PROPERTY_AND_AFFAIRS, + default => throw new InvalidArgumentException('Invalid shorthand name: ' . $shortName), + }; + } +} \ No newline at end of file diff --git a/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php b/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php new file mode 100644 index 0000000000..ed5fd5d196 --- /dev/null +++ b/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php @@ -0,0 +1,36 @@ +hydrateObject( + Lpa::class, + $lpa + ); + } +} \ No newline at end of file diff --git a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php index e8e90de07f..edddfa904f 100644 --- a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php @@ -11,7 +11,12 @@ Repository\ViewerCodesInterface}; use App\DataAccess\Repository\Response\{InstructionsAndPreferencesImages, InstructionsAndPreferencesImagesResult, Lpa}; use App\Service\Features\FeatureEnabled; -use App\Service\Lpa\{GetAttorneyStatus, GetTrustCorporationStatus, IsValidLpa, LpaService, ResolveActor}; +use App\Service\Lpa\{GetAttorneyStatus, + GetTrustCorporationStatus, + IsValidLpa, + LpaDataFormatter, + LpaService, + ResolveActor}; use DateInterval; use DateTime; use PHPUnit\Framework\Attributes\Test; @@ -38,6 +43,7 @@ class LpaServiceTest extends TestCase private GetTrustCorporationStatus|ObjectProphecy $getTrustCorporationStatusProphecy; private FeatureEnabled|ObjectProphecy $featureEnabledProphecy; private LoggerInterface|ObjectProphecy $loggerProphecy; + private LpaDataFormatter|ObjectProphecy $lpaDataFormatter; public function setUp(): void { @@ -52,6 +58,7 @@ public function setUp(): void $this->isValidLpaProphecy = $this->prophesize(IsValidLpa::class); $this->getTrustCorporationStatusProphecy = $this->prophesize(GetTrustCorporationStatus::class); $this->featureEnabledProphecy = $this->prophesize(FeatureEnabled::class); + $this->lpaDataFormatter = $this->prophesize(LpaDataFormatter::class); $this->loggerProphecy = $this->prophesize(LoggerInterface::class); } @@ -68,6 +75,7 @@ private function getLpaService(): LpaService $this->isValidLpaProphecy->reveal(), $this->getTrustCorporationStatusProphecy->reveal(), $this->featureEnabledProphecy->reveal(), + $this->lpaDataFormatter->reveal(), $this->loggerProphecy->reveal(), ); } @@ -1130,4 +1138,139 @@ public function will_return_empty_lpa_array_when_status_invalid(): void $this->assertEmpty($result); } + + #[Test] + public function can_get_transformed_data_store_lpa_by_id(): void + { + $lpaResponse = [ + 'lpaType' => 'personal-welfare', + 'channel' => 'online', + 'donor' => [ + 'uid' => 'eda719db-8880-4dda-8c5d-bb9ea12c236f', + 'firstNames' => 'Feeg', + 'lastName' => 'Bundlaaaa', + 'address' => [ + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', + ], + 'dateOfBirth' => '1970-01-24', + 'email' => 'nobody@not.a.real.domain', + 'contactLanguagePreference' => 'en', + ], + 'attorneys' => [ + [ + 'uid' => '9ac5cb7c-fc75-40c7-8e53-059f36dbbe3d', + 'firstNames' => 'Herman', + 'lastName' => 'Seakrest', + 'address' => [ + 'line1' => '81 NighOnTimeWeBuiltIt Street', + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', + ], + 'dateOfBirth' => '1982-07-24', + 'status' => 'active', + 'channel' => 'paper', + ], + ], + 'trustCorporations' => [ + [ + 'uid' => '1d95993a-ffbb-484c-b2fe-f4cca51801da', + 'name' => 'Trust us Corp.', + 'companyNumber' => '666123321', + 'address' => [ + 'line1' => '103 Line 1', + 'town' => 'Town', + 'country' => 'GB', + ], + 'status' => 'active', + 'channel' => 'paper', + ], + ], + 'certificateProvider' => [ + 'uid' => '6808960d-12cf-47c5-a2bc-3177deb8599c', + 'firstNames' => 'Vone', + 'lastName' => 'Spust', + 'address' => [ + 'line1' => '122111 Zonnington Way', + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', + ], + 'channel' => 'online', + 'email' => 'a@example.com', + 'phone' => '070009000', + ], + 'lifeSustainingTreatmentOption' => 'option-a', + 'signedAt' => '2024-01-10T23:00:00Z', + 'certificateProviderNotRelatedConfirmedAt' => '2024-01-11T22:00:00Z', + 'howAttorneysMakeDecisions' => 'jointly', + ]; + + $expectedLpaResponse = [ + 'attorneyActDecisions' => [ + 'name' => 'JOINTLY', + 'value' => 'jointly', + ], + 'attorneys' => [ + [ + 'addressLine1' => '81 NighOnTimeWeBuiltIt Street', + 'country' => 'GB', + 'town' => 'Mahhhhhhhhh', + 'dob' => [ + 'date' => '1982-07-24 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'UTC', + ], + 'firstNames' => 'Herman', + 'surName' => 'Seakrest', + 'systemStatus' => 'active', + ], + ], + 'caseSubtype' => [ + 'name' => 'PERSONAL_WELFARE', + 'value' => 'personal-welfare', + ], + 'channel' => 'online', + 'donor' => [ + 'addressLine1' => '74 Cloop Close', + 'country' => 'GB', + 'town' => 'Mahhhhhhhhh', + 'dob' => [ + 'date' => '1970-01-24 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'UTC', + ], + 'email' => 'nobody@not_a_real_domain', + 'firstNames' => 'Feeg', + 'surName' => 'Bundlaaaa', + ], + 'lifeSustainingTreatment' => [ + 'name' => 'OPTION_A', + 'value' => 'option-a', + ], + 'lpaDonorSignatureDate' => [ + 'date' => '2021-01-10 23:00:00.000000', + 'timezone_type' => 2, + 'timezone' => 'Z', + ], + 'trustCorporations' => [ + [ + 'name' => 'Trust us Corp.', + 'addressLine1' => '103 Line 1', + 'country' => 'GB', + 'town' => 'Town', + 'systemStatus' => 'active', + 'companyName' => 'Trust us Corp.', + ], + ], + ]; + + $this->lpaDataFormatter->__invoke( + $lpaResponse + )->willReturn($expectedLpaResponse); + + $actualLpaResponse = ($this->lpaDataFormatter->reveal())($lpaResponse); + + $this->assertEquals($expectedLpaResponse, $actualLpaResponse); + } } From 32a4816d326a08e61341717de54cdaf84be6342b Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Thu, 22 Aug 2024 12:04:16 +0100 Subject: [PATCH 02/20] UML-3460 updating composer lock and test --- service-api/app/composer.lock | 155 +++++++++++++++++- .../AppTest/Service/Lpa/LpaServiceTest.php | 1 - 2 files changed, 148 insertions(+), 8 deletions(-) diff --git a/service-api/app/composer.lock b/service-api/app/composer.lock index 84e1ddbea7..785001026c 100644 --- a/service-api/app/composer.lock +++ b/service-api/app/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c55678a181d41791bf3caa4fe45b6c76", + "content-hash": "1414469c19310606fea6f92ac5bcfe87", "packages": [ { "name": "alphagov/notifications-php-client", @@ -442,6 +442,70 @@ }, "time": "2023-03-28T13:51:38+00:00" }, + { + "name": "eventsauce/object-hydrator", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/EventSaucePHP/ObjectHydrator.git", + "reference": "743ee4524d1a3d7b381ef9f61afcb18e0cc81cb0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/EventSaucePHP/ObjectHydrator/zipball/743ee4524d1a3d7b381ef9f61afcb18e0cc81cb0", + "reference": "743ee4524d1a3d7b381ef9f61afcb18e0cc81cb0", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "php": "^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.4", + "league/construct-finder": "^1.1", + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.7", + "phpunit/phpunit": "^9.5.11", + "ramsey/uuid": "^4.2" + }, + "suggest": { + "league/construct-finder": "Find all classes in a directory for the best dumped hydrators." + }, + "type": "library", + "autoload": { + "psr-4": { + "EventSauce\\ObjectHydrator\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frankdejonge.nl" + } + ], + "description": "Converts structured data into strict objects.", + "keywords": [ + "construction", + "constructor", + "hydration", + "mapper" + ], + "support": { + "issues": "https://github.com/EventSaucePHP/ObjectHydrator/issues", + "source": "https://github.com/EventSaucePHP/ObjectHydrator/tree/1.4.0" + }, + "funding": [ + { + "url": "https://github.com/frankdejonge", + "type": "github" + } + ], + "time": "2023-08-03T07:27:58+00:00" + }, { "name": "facile-it/php-jose-verifier", "version": "0.4.5", @@ -1610,6 +1674,83 @@ ], "time": "2024-01-04T10:50:34+00:00" }, + { + "name": "laminas/laminas-hydrator", + "version": "4.15.0", + "source": { + "type": "git", + "url": "https://github.com/laminas/laminas-hydrator.git", + "reference": "43ccca88313fdcceca37865109dffc69ecd2cf8f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laminas/laminas-hydrator/zipball/43ccca88313fdcceca37865109dffc69ecd2cf8f", + "reference": "43ccca88313fdcceca37865109dffc69ecd2cf8f", + "shasum": "" + }, + "require": { + "laminas/laminas-stdlib": "^3.3", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "webmozart/assert": "^1.10" + }, + "conflict": { + "laminas/laminas-servicemanager": "<3.14.0", + "zendframework/zend-hydrator": "*" + }, + "require-dev": { + "laminas/laminas-coding-standard": "~2.5.0", + "laminas/laminas-eventmanager": "^3.12", + "laminas/laminas-modulemanager": "^2.15.0", + "laminas/laminas-serializer": "^2.17.0", + "laminas/laminas-servicemanager": "^3.22.1", + "phpbench/phpbench": "^1.2.14", + "phpunit/phpunit": "^10.4.2", + "psalm/plugin-phpunit": "^0.18.4", + "vimeo/psalm": "^5.15" + }, + "suggest": { + "laminas/laminas-eventmanager": "^3.2, to support aggregate hydrator usage", + "laminas/laminas-serializer": "^2.9, to use the SerializableStrategy", + "laminas/laminas-servicemanager": "^3.14, to support hydrator plugin manager usage" + }, + "type": "library", + "extra": { + "laminas": { + "component": "Laminas\\Hydrator", + "config-provider": "Laminas\\Hydrator\\ConfigProvider" + } + }, + "autoload": { + "psr-4": { + "Laminas\\Hydrator\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Serialize objects to arrays, and vice versa", + "homepage": "https://laminas.dev", + "keywords": [ + "hydrator", + "laminas" + ], + "support": { + "chat": "https://laminas.dev/chat", + "docs": "https://docs.laminas.dev/laminas-hydrator/", + "forum": "https://discourse.laminas.dev", + "issues": "https://github.com/laminas/laminas-hydrator/issues", + "rss": "https://github.com/laminas/laminas-hydrator/releases.atom", + "source": "https://github.com/laminas/laminas-hydrator" + }, + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" + } + ], + "time": "2023-11-08T11:11:45+00:00" + }, { "name": "laminas/laminas-servicemanager", "version": "3.22.1", @@ -12914,16 +13055,16 @@ }, { "name": "symfony/translation", - "version": "v6.4.8", + "version": "v6.4.10", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "a002933b13989fc4bd0b58e04bf7eec5210e438a" + "reference": "94041203f8ac200ae9e7c6a18fa6137814ccecc9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/a002933b13989fc4bd0b58e04bf7eec5210e438a", - "reference": "a002933b13989fc4bd0b58e04bf7eec5210e438a", + "url": "https://api.github.com/repos/symfony/translation/zipball/94041203f8ac200ae9e7c6a18fa6137814ccecc9", + "reference": "94041203f8ac200ae9e7c6a18fa6137814ccecc9", "shasum": "" }, "require": { @@ -12989,7 +13130,7 @@ "description": "Provides tools to internationalize your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/translation/tree/v6.4.8" + "source": "https://github.com/symfony/translation/tree/v6.4.10" }, "funding": [ { @@ -13005,7 +13146,7 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:49:08+00:00" + "time": "2024-07-26T12:30:32+00:00" }, { "name": "symfony/translation-contracts", diff --git a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php index edddfa904f..bbb77a3a4c 100644 --- a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php @@ -75,7 +75,6 @@ private function getLpaService(): LpaService $this->isValidLpaProphecy->reveal(), $this->getTrustCorporationStatusProphecy->reveal(), $this->featureEnabledProphecy->reveal(), - $this->lpaDataFormatter->reveal(), $this->loggerProphecy->reveal(), ); } From 2d691b3806de0be781f4293d79a9a5b7ac3598da Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Thu, 22 Aug 2024 12:50:22 +0100 Subject: [PATCH 03/20] UML-3460 updating to psr standards --- service-api/app/src/App/src/Entity/Attorney.php | 2 +- service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php | 2 ++ .../app/src/App/src/Entity/Casters/CastToCaseSubtype.php | 2 ++ .../App/src/Entity/Casters/CastToLifeSustainingTreatment.php | 2 ++ .../src/App/src/Entity/Casters/CastToWhenTheLpaCanBeUsed.php | 2 ++ .../App/src/Entity/Casters/ExtractAddressLine1FromDataStore.php | 2 ++ .../src/App/src/Entity/Casters/ExtractCountryFromDataStore.php | 2 ++ .../app/src/App/src/Entity/Casters/ExtractTownFromDataStore.php | 2 ++ service-api/app/src/App/src/Entity/Donor.php | 2 +- service-api/app/src/App/src/Entity/Lpa.php | 2 +- service-api/app/src/App/src/Entity/Person.php | 2 +- service-api/app/src/App/src/Entity/TrustCorporations.php | 2 +- service-api/app/src/App/src/Enum/HowAttorneysMakeDecisions.php | 2 +- service-api/app/src/App/src/Enum/LifeSustainingTreatment.php | 2 +- service-api/app/src/App/src/Enum/LpaType.php | 2 +- service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php | 2 +- 16 files changed, 23 insertions(+), 9 deletions(-) diff --git a/service-api/app/src/App/src/Entity/Attorney.php b/service-api/app/src/App/src/Entity/Attorney.php index 18d84326f0..0577d0b7cb 100644 --- a/service-api/app/src/App/src/Entity/Attorney.php +++ b/service-api/app/src/App/src/Entity/Attorney.php @@ -6,4 +6,4 @@ class Attorney extends Person { -} \ No newline at end of file +} diff --git a/service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php b/service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php index 63839dbdc6..204faeef50 100644 --- a/service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php +++ b/service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php @@ -1,5 +1,7 @@ throw new InvalidArgumentException('Invalid shorthand name: ' . $shortName), }; } -} \ No newline at end of file +} diff --git a/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php b/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php index ed5fd5d196..eb5d8d5280 100644 --- a/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php +++ b/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php @@ -33,4 +33,4 @@ public function __invoke(array $lpa) $lpa ); } -} \ No newline at end of file +} From bfe580216c7ad74f53a7ca4ad24904a24a6777ea Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Thu, 22 Aug 2024 12:55:44 +0100 Subject: [PATCH 04/20] UML-3460 updating to psr standards --- .../app/src/App/src/Entity/Casters/CastSingleDonor.php | 2 +- .../app/src/App/src/Entity/Casters/CastToCaseSubtype.php | 2 +- .../App/src/Entity/Casters/CastToLifeSustainingTreatment.php | 2 +- .../src/App/src/Entity/Casters/CastToWhenTheLpaCanBeUsed.php | 2 +- .../src/Entity/Casters/ExtractAddressLine1FromDataStore.php | 2 +- .../App/src/Entity/Casters/ExtractCountryFromDataStore.php | 2 +- .../src/App/src/Entity/Casters/ExtractTownFromDataStore.php | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php b/service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php index 204faeef50..a64e6a63a5 100644 --- a/service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php +++ b/service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php @@ -16,4 +16,4 @@ public function cast(mixed $value, ObjectMapper $hydrator): mixed { return $hydrator->hydrateObject(Donor::class, $value); } -} \ No newline at end of file +} diff --git a/service-api/app/src/App/src/Entity/Casters/CastToCaseSubtype.php b/service-api/app/src/App/src/Entity/Casters/CastToCaseSubtype.php index faa60f7a6f..d7f192be21 100644 --- a/service-api/app/src/App/src/Entity/Casters/CastToCaseSubtype.php +++ b/service-api/app/src/App/src/Entity/Casters/CastToCaseSubtype.php @@ -16,4 +16,4 @@ public function cast(mixed $value, ObjectMapper $hydrator): string { return LpaType::fromShortName($value)->value; } -} \ No newline at end of file +} diff --git a/service-api/app/src/App/src/Entity/Casters/CastToLifeSustainingTreatment.php b/service-api/app/src/App/src/Entity/Casters/CastToLifeSustainingTreatment.php index b809ec46e8..9957f76eff 100644 --- a/service-api/app/src/App/src/Entity/Casters/CastToLifeSustainingTreatment.php +++ b/service-api/app/src/App/src/Entity/Casters/CastToLifeSustainingTreatment.php @@ -16,4 +16,4 @@ public function cast(mixed $value, ObjectMapper $hydrator): mixed { return LifeSustainingTreatment::from($value)->value; } -} \ No newline at end of file +} diff --git a/service-api/app/src/App/src/Entity/Casters/CastToWhenTheLpaCanBeUsed.php b/service-api/app/src/App/src/Entity/Casters/CastToWhenTheLpaCanBeUsed.php index 8e1c3b82db..1f5d1b9c66 100644 --- a/service-api/app/src/App/src/Entity/Casters/CastToWhenTheLpaCanBeUsed.php +++ b/service-api/app/src/App/src/Entity/Casters/CastToWhenTheLpaCanBeUsed.php @@ -16,4 +16,4 @@ public function cast(mixed $value, ObjectMapper $hydrator): ?string { return HowAttorneysMakeDecisions::from($value)->value; } -} \ No newline at end of file +} diff --git a/service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromDataStore.php b/service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromDataStore.php index 66c7c54c4d..7517e1ef8e 100644 --- a/service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromDataStore.php +++ b/service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromDataStore.php @@ -19,4 +19,4 @@ public function cast(mixed $value, ObjectMapper $hydrator): ?string return null; } -} \ No newline at end of file +} diff --git a/service-api/app/src/App/src/Entity/Casters/ExtractCountryFromDataStore.php b/service-api/app/src/App/src/Entity/Casters/ExtractCountryFromDataStore.php index bffa95c2b8..88165d3516 100644 --- a/service-api/app/src/App/src/Entity/Casters/ExtractCountryFromDataStore.php +++ b/service-api/app/src/App/src/Entity/Casters/ExtractCountryFromDataStore.php @@ -19,4 +19,4 @@ public function cast(mixed $value, ObjectMapper $hydrator): ?string return null; } -} \ No newline at end of file +} diff --git a/service-api/app/src/App/src/Entity/Casters/ExtractTownFromDataStore.php b/service-api/app/src/App/src/Entity/Casters/ExtractTownFromDataStore.php index 5205ab85ec..f5ab53bacb 100644 --- a/service-api/app/src/App/src/Entity/Casters/ExtractTownFromDataStore.php +++ b/service-api/app/src/App/src/Entity/Casters/ExtractTownFromDataStore.php @@ -11,7 +11,7 @@ #[Attribute(Attribute::TARGET_PARAMETER)] class ExtractTownFromDataStore implements PropertyCaster { - public function cast(mixed $value, ObjectMapper $mapper): ?string + public function cast(mixed $value, ObjectMapper $hydrator): ?string { if (is_array($value) && isset($value['town'])) { return $value['town']; @@ -19,4 +19,4 @@ public function cast(mixed $value, ObjectMapper $mapper): ?string return null; } -} \ No newline at end of file +} From efa7b8b954d5d320cba37ac682f96173324ea01c Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Thu, 22 Aug 2024 15:29:46 +0100 Subject: [PATCH 05/20] UML-3460 added test case --- .../AppTest/Service/Lpa/LpaServiceTest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php index bbb77a3a4c..7434f8a692 100644 --- a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php @@ -4,6 +4,8 @@ namespace AppTest\Service\Lpa; +use App\Entity\Casters\CastSingleDonor; +use EventSauce\ObjectHydrator\ObjectMapper; use App\DataAccess\{Repository\InstructionsAndPreferencesImagesInterface, Repository\LpasInterface, Repository\UserLpaActorMapInterface, @@ -44,6 +46,7 @@ class LpaServiceTest extends TestCase private FeatureEnabled|ObjectProphecy $featureEnabledProphecy; private LoggerInterface|ObjectProphecy $loggerProphecy; private LpaDataFormatter|ObjectProphecy $lpaDataFormatter; + private ObjectMapper|ObjectProphecy $hydrator; public function setUp(): void { @@ -60,6 +63,7 @@ public function setUp(): void $this->featureEnabledProphecy = $this->prophesize(FeatureEnabled::class); $this->lpaDataFormatter = $this->prophesize(LpaDataFormatter::class); $this->loggerProphecy = $this->prophesize(LoggerInterface::class); + $this->hydrator = $this->prophesize(ObjectMapper::class); } private function getLpaService(): LpaService @@ -1272,4 +1276,42 @@ public function can_get_transformed_data_store_lpa_by_id(): void $this->assertEquals($expectedLpaResponse, $actualLpaResponse); } + + #[Test] + public function can_cast_single_donor(): void + { + $donor = [ + 'uid' => 'eda719db-8880-4dda-8c5d-bb9ea12c236f', + 'firstNames' => 'Feeg', + 'lastName' => 'Bundlaaaa', + 'address' => [ + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', + ], + 'dateOfBirth' => '1970-01-24', + 'email' => 'nobody@not.a.real.domain', + 'contactLanguagePreference' => 'en', + ]; + + $expectedResult = [ + 'addressLine1' => '74 Cloop Close', + 'country' => 'GB', + 'town' => 'Mahhhhhhhhh', + 'dob' => [ + 'date' => '1970-01-24 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'UTC', + ], + 'email' => 'nobody@not_a_real_domain', + 'firstNames' => 'Feeg', + 'surName' => 'Bundlaaaa', + ]; + + $castSingleDonor = new CastSingleDonor(); + + $result = $castSingleDonor->cast($donor, $this->hydrator); + + $this->assertEquals($expectedResult, $result); + } } From 3eaeac91569d0ebc0a28ebb04dd38fe516c124a6 Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Wed, 28 Aug 2024 11:01:12 +0100 Subject: [PATCH 06/20] UML-3460 serialised objects, transforming enum and datetimes. used inheritance for the entities to help structure datastore and for future sirius implementation --- .../app/src/App/src/Entity/Attorney.php | 9 -- .../src/Entity/Casters/CastSingleDonor.php | 8 +- .../Entity/Casters/DateToStringSerializer.php | 21 +++++ .../Entity/DataStore/DataStoreAttorney.php | 9 ++ .../DataStoreDonor.php} | 4 +- .../App/src/Entity/DataStore/DataStoreLpa.php | 84 +++++++++++++++++++ .../src/Entity/DataStore/DataStorePerson.php | 64 ++++++++++++++ .../DataStoreTrustCorporations.php} | 4 +- service-api/app/src/App/src/Entity/Lpa.php | 34 ++------ service-api/app/src/App/src/Entity/Person.php | 21 +---- .../App/src/Service/Lpa/LpaDataFormatter.php | 35 ++++++-- 11 files changed, 230 insertions(+), 63 deletions(-) delete mode 100644 service-api/app/src/App/src/Entity/Attorney.php create mode 100644 service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php create mode 100644 service-api/app/src/App/src/Entity/DataStore/DataStoreAttorney.php rename service-api/app/src/App/src/Entity/{Donor.php => DataStore/DataStoreDonor.php} (95%) create mode 100644 service-api/app/src/App/src/Entity/DataStore/DataStoreLpa.php create mode 100644 service-api/app/src/App/src/Entity/DataStore/DataStorePerson.php rename service-api/app/src/App/src/Entity/{TrustCorporations.php => DataStore/DataStoreTrustCorporations.php} (94%) diff --git a/service-api/app/src/App/src/Entity/Attorney.php b/service-api/app/src/App/src/Entity/Attorney.php deleted file mode 100644 index 0577d0b7cb..0000000000 --- a/service-api/app/src/App/src/Entity/Attorney.php +++ /dev/null @@ -1,9 +0,0 @@ -hydrateObject(Donor::class, $value); + return $hydrator->hydrateObject(DataStoreDonor::class, $value); } } diff --git a/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php b/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php new file mode 100644 index 0000000000..df5a24c49d --- /dev/null +++ b/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php @@ -0,0 +1,21 @@ +format('d-m-Y H:i:s'); + } + + return $value; + } +} diff --git a/service-api/app/src/App/src/Entity/DataStore/DataStoreAttorney.php b/service-api/app/src/App/src/Entity/DataStore/DataStoreAttorney.php new file mode 100644 index 0000000000..efc2378d96 --- /dev/null +++ b/service-api/app/src/App/src/Entity/DataStore/DataStoreAttorney.php @@ -0,0 +1,9 @@ + [ + DateToStringSerializer::class, + ], + DateTimeInterface::class => [ + DateToStringSerializer::class, + ], + ]); + $defaultSerializerRepository->registerDefaultSerializer( + DateTimeImmutable::class, + DateToStringSerializer::class, + [] + ); $mapper = new ObjectMapperUsingReflection( new DefinitionProvider( - keyFormatter: new KeyFormatterWithoutConversion(), + keyFormatter: new KeyFormatterWithoutConversion(), + defaultSerializerRepository: $defaultSerializerRepository ), ); - return $mapper->hydrateObject( - Lpa::class, + $lpaObject = $mapper->hydrateObject( + DataStoreLpa::class, $lpa ); + + return $mapper->serializeObject( + $lpaObject + ); } } From c8e49bf6d64eb4d0d886fb774d157f73d4afb074 Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Wed, 28 Aug 2024 16:27:44 +0100 Subject: [PATCH 07/20] UML-3460 added tests for casters --- .../src/Entity/DataStore/DataStoreDonor.php | 4 +- .../DataStore/DataStoreTrustCorporations.php | 4 +- .../AppTest/Service/Lpa/LpaServiceTest.php | 191 ++++++++++++++++-- 3 files changed, 181 insertions(+), 18 deletions(-) diff --git a/service-api/app/src/App/src/Entity/DataStore/DataStoreDonor.php b/service-api/app/src/App/src/Entity/DataStore/DataStoreDonor.php index 8255d8c5a6..d24b9a9251 100644 --- a/service-api/app/src/App/src/Entity/DataStore/DataStoreDonor.php +++ b/service-api/app/src/App/src/Entity/DataStore/DataStoreDonor.php @@ -37,7 +37,7 @@ public function __construct( #[MapFrom('firstNames')] ?string $firstnames, #[MapFrom('lastName')] - ?string $surName, + ?string $surname, ?string $otherNames, #[MapFrom('status')] ?string $systemStatus, @@ -56,7 +56,7 @@ public function __construct( $email, $firstname, $firstnames, - $surName, + $surname, $otherNames, $systemStatus ); diff --git a/service-api/app/src/App/src/Entity/DataStore/DataStoreTrustCorporations.php b/service-api/app/src/App/src/Entity/DataStore/DataStoreTrustCorporations.php index fed9bb5033..bae2ae6742 100644 --- a/service-api/app/src/App/src/Entity/DataStore/DataStoreTrustCorporations.php +++ b/service-api/app/src/App/src/Entity/DataStore/DataStoreTrustCorporations.php @@ -34,7 +34,7 @@ public function __construct( ?string $email, ?string $firstname, ?string $firstnames, - ?string $surName, + ?string $surname, ?string $otherNames, #[MapFrom('status')] ?string $systemStatus, @@ -53,7 +53,7 @@ public function __construct( $email, $firstname, $firstnames, - $surName, + $surname, $otherNames, $systemStatus ); diff --git a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php index 7434f8a692..0d6f61fb7c 100644 --- a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php @@ -5,7 +5,17 @@ namespace AppTest\Service\Lpa; use App\Entity\Casters\CastSingleDonor; +use App\Entity\Casters\CastToCaseSubtype; +use App\Entity\Casters\CastToLifeSustainingTreatment; +use App\Entity\Casters\CastToWhenTheLpaCanBeUsed; +use App\Entity\Casters\DateToStringSerializer; +use App\Entity\Casters\ExtractAddressLine1FromDataStore; +use App\Entity\Casters\ExtractCountryFromDataStore; +use App\Entity\Casters\ExtractTownFromDataStore; +use App\Entity\DataStore\DataStoreDonor; +use App\Entity\Person; use EventSauce\ObjectHydrator\ObjectMapper; +use Laminas\Hydrator\HydratorInterface; use App\DataAccess\{Repository\InstructionsAndPreferencesImagesInterface, Repository\LpasInterface, Repository\UserLpaActorMapInterface, @@ -1145,6 +1155,25 @@ public function will_return_empty_lpa_array_when_status_invalid(): void #[Test] public function can_get_transformed_data_store_lpa_by_id(): void { + $donorObj = new Person( + 'Feeg Bundlaaaa', + '74 Cloop Close', + '', + '', + 'GB', + 'Town', + '', + 'Mahhhhhhhhh', + '', + new \DateTimeImmutable('1970-01-24'), + 'nobody@not_a_real_domain', + 'Feeg', + '', + 'Bundlaaaa', + '', + '' + ); + $lpaResponse = [ 'lpaType' => 'personal-welfare', 'channel' => 'online', @@ -1280,6 +1309,7 @@ public function can_get_transformed_data_store_lpa_by_id(): void #[Test] public function can_cast_single_donor(): void { + $donor = [ 'uid' => 'eda719db-8880-4dda-8c5d-bb9ea12c236f', 'firstNames' => 'Feeg', @@ -1294,24 +1324,157 @@ public function can_cast_single_donor(): void 'contactLanguagePreference' => 'en', ]; - $expectedResult = [ - 'addressLine1' => '74 Cloop Close', + $datastoreDonor = new DataStoreDonor( + null, + null, + '74 Cloop Close', + null, + null, + 'GB', + null, + null, + 'Mahhhhhhhhh', + null, + new \DateTimeImmutable('1970-01-24 00:00:00.000000'), + 'nobody@not_a_real_domain', + null, + 'Feeg', + 'Bundlaaaa', + null, + null, + ); + + $castSingleDonor = new CastSingleDonor(); + + $mockHydrator = $this->createMock(ObjectMapper::class); + + $result = $castSingleDonor->cast($donor, $mockHydrator); + print_r($datastoreDonor); + print_r($result); + $this->assertEquals($datastoreDonor, $result); + } + + #[Test] + public function can_cast_case_subtype(): void + { + $caseSubType = 'personal-welfare'; + + $expectedCaseSubType = 'hw'; + + $castToSingleSubType = new CastToCaseSubtype(); + + $mockHydrator = $this->createMock(ObjectMapper::class); + + $result = $castToSingleSubType->cast($caseSubType, $mockHydrator); + + $this->assertEquals($expectedCaseSubType, $result); + } + + #[Test] + public function can_cast_life_sustaining_treatment(): void + { + $lifeSustainingTreatment = 'option-a'; + + $expectedLifeSustainingTreatment = 'option-a'; + + $castToLifeSustainingTreatment = new CastToLifeSustainingTreatment(); + + $mockHydrator = $this->createMock(ObjectMapper::class); + + $result = $castToLifeSustainingTreatment->cast($lifeSustainingTreatment, $mockHydrator); + + $this->assertEquals($expectedLifeSustainingTreatment, $result); + } + + #[Test] + public function can_when_lpa_can_be_used(): void + { + $whenTheLpaCanBeUsed = 'singular'; + + $expectedWhenTheLpaCanBeUsed = 'singular'; + + $castToWhenTheLpaCanBeUsed = new CastToWhenTheLpaCanBeUsed(); + + $mockHydrator = $this->createMock(ObjectMapper::class); + + $result = $castToWhenTheLpaCanBeUsed->cast($whenTheLpaCanBeUsed, $mockHydrator); + + $this->assertEquals($expectedWhenTheLpaCanBeUsed, $result); + } + + #[Test] + public function can_date_to_string_serialised(): void + { + $date = new \DateTimeImmutable('22-12-1997'); + + $expecteDate = '22-12-1997 00:00:00'; + + $castDateToStringSerialize = new DateToStringSerializer(); + + $mockHydrator = $this->createMock(ObjectMapper::class); + + $result = $castDateToStringSerialize->serialize($date, $mockHydrator); + + $this->assertEquals($expecteDate, $result); + } + + #[Test] + public function can_extract_town_from_datastore(): void + { + $address = [ + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', 'country' => 'GB', - 'town' => 'Mahhhhhhhhh', - 'dob' => [ - 'date' => '1970-01-24 00:00:00.000000', - 'timezone_type' => 3, - 'timezone' => 'UTC', - ], - 'email' => 'nobody@not_a_real_domain', - 'firstNames' => 'Feeg', - 'surName' => 'Bundlaaaa', ]; - $castSingleDonor = new CastSingleDonor(); + $expectedTown = 'Mahhhhhhhhhh'; + + $extractTownFromDataStore = new ExtractTownFromDataStore(); + + $mockHydrator = $this->createMock(ObjectMapper::class); + + $result = $extractTownFromDataStore->cast($address, $mockHydrator); + + $this->assertEquals($expectedTown, $result); + } + + #[Test] + public function can_extract_country_from_datastore(): void + { + $address = [ + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', + ]; + + $expectedCountry = 'GB'; + + $extractCountryFromDataStore = new ExtractCountryFromDataStore(); + + $mockHydrator = $this->createMock(ObjectMapper::class); + + $result = $extractCountryFromDataStore->cast($address, $mockHydrator); + + $this->assertEquals($expectedCountry, $result); + } + + #[Test] + public function can_extract_address_one_from_datastore(): void + { + $address = [ + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', + ]; + + $expectedAddressOne = '74 Cloob Close'; + + $extractAddressOneFromDataStore = new ExtractAddressLine1FromDataStore(); + + $mockHydrator = $this->createMock(ObjectMapper::class); - $result = $castSingleDonor->cast($donor, $this->hydrator); + $result = $extractAddressOneFromDataStore->cast($address, $mockHydrator); - $this->assertEquals($expectedResult, $result); + $this->assertEquals($expectedAddressOne, $result); } } From 615c359e3e566009fe9660e0d34d804592d81715 Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Thu, 29 Aug 2024 13:52:36 +0100 Subject: [PATCH 08/20] UML-3460 fixed can_cast_single_donor test --- .../src/Entity/DataStore/DataStoreDonor.php | 4 +- .../App/src/Service/Lpa/LpaDataFormatter.php | 1 - .../AppTest/Service/Lpa/LpaServiceTest.php | 45 ++++++++++--------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/service-api/app/src/App/src/Entity/DataStore/DataStoreDonor.php b/service-api/app/src/App/src/Entity/DataStore/DataStoreDonor.php index d24b9a9251..7e13b60aa9 100644 --- a/service-api/app/src/App/src/Entity/DataStore/DataStoreDonor.php +++ b/service-api/app/src/App/src/Entity/DataStore/DataStoreDonor.php @@ -7,7 +7,7 @@ use App\Entity\Casters\ExtractAddressLine1FromDataStore; use App\Entity\Casters\ExtractCountryFromDataStore; use App\Entity\Casters\ExtractTownFromDataStore; -use DateTimeInterface; +use DateTimeImmutable; use EventSauce\ObjectHydrator\MapFrom; class DataStoreDonor extends DataStorePerson @@ -31,7 +31,7 @@ public function __construct( ?string $town, ?string $type, #[MapFrom('dateOfBirth')] - ?DateTimeInterface $dob, + ?DateTimeImmutable $dob, ?string $email, ?string $firstname, #[MapFrom('firstNames')] diff --git a/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php b/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php index 1a7895923a..3dde010c23 100644 --- a/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php +++ b/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php @@ -4,7 +4,6 @@ namespace App\Service\Lpa; -use App\Entity\Casters\DateSerializer; use App\Entity\Casters\DateToStringSerializer; use App\Entity\DataStore\DataStoreLpa; use DateTimeInterface; diff --git a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php index 0d6f61fb7c..7de82e1c0c 100644 --- a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php @@ -14,7 +14,10 @@ use App\Entity\Casters\ExtractTownFromDataStore; use App\Entity\DataStore\DataStoreDonor; use App\Entity\Person; +use EventSauce\ObjectHydrator\DefinitionProvider; +use EventSauce\ObjectHydrator\KeyFormatterWithoutConversion; use EventSauce\ObjectHydrator\ObjectMapper; +use EventSauce\ObjectHydrator\ObjectMapperUsingReflection; use Laminas\Hydrator\HydratorInterface; use App\DataAccess\{Repository\InstructionsAndPreferencesImagesInterface, Repository\LpasInterface, @@ -1309,34 +1312,34 @@ public function can_get_transformed_data_store_lpa_by_id(): void #[Test] public function can_cast_single_donor(): void { - $donor = [ - 'uid' => 'eda719db-8880-4dda-8c5d-bb9ea12c236f', + 'uId' => '700000000971', 'firstNames' => 'Feeg', + 'surname' => 'Gilson', 'lastName' => 'Bundlaaaa', + 'email' => 'nobody@not.a.real.domain', + 'middlenames' => 'Suzanne', + 'dateOfBirth' => '1970-01-24', 'address' => [ 'line1' => '74 Cloob Close', 'town' => 'Mahhhhhhhhhh', 'country' => 'GB', ], - 'dateOfBirth' => '1970-01-24', - 'email' => 'nobody@not.a.real.domain', - 'contactLanguagePreference' => 'en', ]; - $datastoreDonor = new DataStoreDonor( + $expectedDatastoreDonor = new DataStoreDonor( null, null, - '74 Cloop Close', + '74 Cloob Close', null, null, 'GB', null, null, - 'Mahhhhhhhhh', + 'Mahhhhhhhhhh', null, new \DateTimeImmutable('1970-01-24 00:00:00.000000'), - 'nobody@not_a_real_domain', + 'nobody@not.a.real.domain', null, 'Feeg', 'Bundlaaaa', @@ -1346,12 +1349,14 @@ public function can_cast_single_donor(): void $castSingleDonor = new CastSingleDonor(); - $mockHydrator = $this->createMock(ObjectMapper::class); + $mapper = new ObjectMapperUsingReflection( + new DefinitionProvider( + keyFormatter: new KeyFormatterWithoutConversion(), + ), + ); - $result = $castSingleDonor->cast($donor, $mockHydrator); - print_r($datastoreDonor); - print_r($result); - $this->assertEquals($datastoreDonor, $result); + $result = $castSingleDonor->cast($donor, $mapper); + $this->assertEquals($expectedDatastoreDonor, $result); } #[Test] @@ -1422,8 +1427,8 @@ public function can_date_to_string_serialised(): void public function can_extract_town_from_datastore(): void { $address = [ - 'line1' => '74 Cloob Close', - 'town' => 'Mahhhhhhhhhh', + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', 'country' => 'GB', ]; @@ -1442,8 +1447,8 @@ public function can_extract_town_from_datastore(): void public function can_extract_country_from_datastore(): void { $address = [ - 'line1' => '74 Cloob Close', - 'town' => 'Mahhhhhhhhhh', + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', 'country' => 'GB', ]; @@ -1462,8 +1467,8 @@ public function can_extract_country_from_datastore(): void public function can_extract_address_one_from_datastore(): void { $address = [ - 'line1' => '74 Cloob Close', - 'town' => 'Mahhhhhhhhhh', + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', 'country' => 'GB', ]; From 52e32ab8b569f6b1e4da24180bdf291bfd5daff1 Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Mon, 2 Sep 2024 10:07:33 +0100 Subject: [PATCH 09/20] UML-3460 updated test --- .../src/Entity/DataStore/DataStoreDonor.php | 2 - .../AppTest/Service/Lpa/LpaServiceTest.php | 312 +++++++++++------- 2 files changed, 194 insertions(+), 120 deletions(-) diff --git a/service-api/app/src/App/src/Entity/DataStore/DataStoreDonor.php b/service-api/app/src/App/src/Entity/DataStore/DataStoreDonor.php index 7e13b60aa9..271e6bfa33 100644 --- a/service-api/app/src/App/src/Entity/DataStore/DataStoreDonor.php +++ b/service-api/app/src/App/src/Entity/DataStore/DataStoreDonor.php @@ -13,8 +13,6 @@ class DataStoreDonor extends DataStorePerson { public function __construct( - #[MapFrom('name')] - public readonly ?string $companyName, ?string $name, #[MapFrom('address')] #[ExtractAddressLine1FromDataStore] diff --git a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php index 7de82e1c0c..355cf95496 100644 --- a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php @@ -4,21 +4,23 @@ namespace AppTest\Service\Lpa; -use App\Entity\Casters\CastSingleDonor; -use App\Entity\Casters\CastToCaseSubtype; -use App\Entity\Casters\CastToLifeSustainingTreatment; -use App\Entity\Casters\CastToWhenTheLpaCanBeUsed; -use App\Entity\Casters\DateToStringSerializer; -use App\Entity\Casters\ExtractAddressLine1FromDataStore; -use App\Entity\Casters\ExtractCountryFromDataStore; -use App\Entity\Casters\ExtractTownFromDataStore; +use App\Entity\Casters\{ + CastSingleDonor, + CastToCaseSubtype, + CastToLifeSustainingTreatment, + CastToWhenTheLpaCanBeUsed, + DateToStringSerializer, + ExtractAddressLine1FromDataStore, + ExtractCountryFromDataStore, + ExtractTownFromDataStore, +}; use App\Entity\DataStore\DataStoreDonor; use App\Entity\Person; +use App\Entity\DataStore\DataStoreLpa; use EventSauce\ObjectHydrator\DefinitionProvider; use EventSauce\ObjectHydrator\KeyFormatterWithoutConversion; use EventSauce\ObjectHydrator\ObjectMapper; use EventSauce\ObjectHydrator\ObjectMapperUsingReflection; -use Laminas\Hydrator\HydratorInterface; use App\DataAccess\{Repository\InstructionsAndPreferencesImagesInterface, Repository\LpasInterface, Repository\UserLpaActorMapInterface, @@ -58,7 +60,7 @@ class LpaServiceTest extends TestCase private GetTrustCorporationStatus|ObjectProphecy $getTrustCorporationStatusProphecy; private FeatureEnabled|ObjectProphecy $featureEnabledProphecy; private LoggerInterface|ObjectProphecy $loggerProphecy; - private LpaDataFormatter|ObjectProphecy $lpaDataFormatter; + private LpaDataFormatter $lpaDataFormatter; private ObjectMapper|ObjectProphecy $hydrator; public function setUp(): void @@ -74,9 +76,9 @@ public function setUp(): void $this->isValidLpaProphecy = $this->prophesize(IsValidLpa::class); $this->getTrustCorporationStatusProphecy = $this->prophesize(GetTrustCorporationStatus::class); $this->featureEnabledProphecy = $this->prophesize(FeatureEnabled::class); - $this->lpaDataFormatter = $this->prophesize(LpaDataFormatter::class); $this->loggerProphecy = $this->prophesize(LoggerInterface::class); $this->hydrator = $this->prophesize(ObjectMapper::class); + $this->lpaDataFormatter = new LpaDataFormatter(); } private function getLpaService(): LpaService @@ -1156,44 +1158,33 @@ public function will_return_empty_lpa_array_when_status_invalid(): void } #[Test] - public function can_get_transformed_data_store_lpa_by_id(): void + public function can_serialise_datastore_lpa_to_modernise_format(): void { - $donorObj = new Person( - 'Feeg Bundlaaaa', - '74 Cloop Close', - '', - '', - 'GB', - 'Town', - '', - 'Mahhhhhhhhh', - '', - new \DateTimeImmutable('1970-01-24'), - 'nobody@not_a_real_domain', - 'Feeg', - '', - 'Bundlaaaa', - '', - '' - ); - - $lpaResponse = [ + $lpa = [ + 'uid' => 'M-789Q-P4DF-4UX3', + 'status' => 'registered', + 'registrationDate' => '2024-01-12', + 'updatedAt' => '2024-01-12', 'lpaType' => 'personal-welfare', 'channel' => 'online', - 'donor' => [ + 'donor' => [ 'uid' => 'eda719db-8880-4dda-8c5d-bb9ea12c236f', - 'firstNames' => 'Feeg', - 'lastName' => 'Bundlaaaa', - 'address' => [ - 'line1' => '74 Cloob Close', - 'town' => 'Mahhhhhhhhhh', - 'country' => 'GB', - ], - 'dateOfBirth' => '1970-01-24', - 'email' => 'nobody@not.a.real.domain', - 'contactLanguagePreference' => 'en', + 'firstNames' => 'Feeg', + 'lastName' => 'Bundlaaaa', + 'address' => [ + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', ], - 'attorneys' => [ + 'email' => 'nobody@not.a.real.domain', + 'dateOfBirth' => '1970-01-24', + 'contactLanguagePreference' => 'en', + 'identityCheck' => [ + 'checkedAt' => '2024-01-10', + 'type' => 'one-login', + ] + ], + 'attorneys'=> [ [ 'uid' => '9ac5cb7c-fc75-40c7-8e53-059f36dbbe3d', 'firstNames' => 'Herman', @@ -1203,110 +1194,142 @@ public function can_get_transformed_data_store_lpa_by_id(): void 'town' => 'Mahhhhhhhhhh', 'country' => 'GB', ], - 'dateOfBirth' => '1982-07-24', 'status' => 'active', 'channel' => 'paper', + 'signedAt' => '2024-01-10', ], ], - 'trustCorporations' => [ + 'trustCorporations'=> [ [ - 'uid' => '1d95993a-ffbb-484c-b2fe-f4cca51801da', - 'name' => 'Trust us Corp.', - 'companyNumber' => '666123321', - 'address' => [ - 'line1' => '103 Line 1', - 'town' => 'Town', - 'country' => 'GB', - ], - 'status' => 'active', - 'channel' => 'paper', + 'uid'=> '1d95993a-ffbb-484c-b2fe-f4cca51801da', + 'name'=> 'Trust us Corp.', + 'companyNumber'=> '666123321', + 'address'=> [ + 'line1'=> '103 Line 1', + 'town'=> 'Town', + 'country'=> 'GB', + ], + 'status'=> 'active', + 'channel'=> 'paper', + 'signedAt'=> '2024-01-10', ], ], - 'certificateProvider' => [ + 'certificateProvider'=> [ 'uid' => '6808960d-12cf-47c5-a2bc-3177deb8599c', 'firstNames' => 'Vone', 'lastName' => 'Spust', 'address' => [ - 'line1' => '122111 Zonnington Way', + 'line1'=> '122111 Zonnington Way', 'town' => 'Mahhhhhhhhhh', 'country' => 'GB', ], 'channel' => 'online', 'email' => 'a@example.com', 'phone' => '070009000', + 'signedAt' => '2024-01-10', + 'identityCheck' => [ + 'checkedAt' => '2024-01-10', + 'type' => 'one-login', + ], ], - 'lifeSustainingTreatmentOption' => 'option-a', - 'signedAt' => '2024-01-10T23:00:00Z', - 'certificateProviderNotRelatedConfirmedAt' => '2024-01-11T22:00:00Z', - 'howAttorneysMakeDecisions' => 'jointly', + 'lifeSustainingTreatmentOption'=> 'option-a', + 'signedAt'=> '2024-01-10', + 'howAttorneysMakeDecisions'=> 'jointly', + 'whenTheLpaCanBeUsed'=> 'when-capacity-lost', + 'applicationHasGuidance'=> false, + 'applicationHasRestrictions'=> false, + 'applicationType'=> null, ]; - $expectedLpaResponse = [ - 'attorneyActDecisions' => [ - 'name' => 'JOINTLY', - 'value' => 'jointly', - ], - 'attorneys' => [ + $expectedLpa = [ + "applicationHasGuidance" => false, + "applicationHasRestrictions" => false, + "applicationType" => null, + "attorneyActDecisions" => "jointly", + "attorneys" => [ [ - 'addressLine1' => '81 NighOnTimeWeBuiltIt Street', - 'country' => 'GB', - 'town' => 'Mahhhhhhhhh', - 'dob' => [ - 'date' => '1982-07-24 00:00:00.000000', - 'timezone_type' => 3, - 'timezone' => 'UTC', - ], - 'firstNames' => 'Herman', - 'surName' => 'Seakrest', - 'systemStatus' => 'active', + "name" => null, + "addressLine1" => "81 NighOnTimeWeBuiltIt Street", + "addressLine2" => null, + "addressLine3" => null, + "country" => "GB", + "county" => null, + "postcode" => null, + "town" => "Mahhhhhhhhhh", + "type" => null, + "dob" => null, + "email" => null, + "firstname" => null, + "firstnames" => "Herman", + "surname" => "Seakrest", + "otherNames" => null, + "systemStatus" => "active", ], ], - 'caseSubtype' => [ - 'name' => 'PERSONAL_WELFARE', - 'value' => 'personal-welfare', + "caseSubtype" => "hw", + "channel" => "online", + "dispatchDate" => null, + "donor" => [ + "name" => null, + "addressLine1" => "74 Cloob Close", + "addressLine2" => null, + "addressLine3" => null, + "country" => "GB", + "county" => null, + "postcode" => null, + "town" => "Mahhhhhhhhhh", + "type" => null, + "dob" => "24-01-1970 00:00:00", + "email" => "nobody@not.a.real.domain", + "firstname" => null, + "firstnames" => "Feeg", + "surname" => "Bundlaaaa", + "otherNames" => null, + "systemStatus" => null, ], - 'channel' => 'online', - 'donor' => [ - 'addressLine1' => '74 Cloop Close', - 'country' => 'GB', - 'town' => 'Mahhhhhhhhh', - 'dob' => [ - 'date' => '1970-01-24 00:00:00.000000', - 'timezone_type' => 3, - 'timezone' => 'UTC', - ], - 'email' => 'nobody@not_a_real_domain', - 'firstNames' => 'Feeg', - 'surName' => 'Bundlaaaa', - ], - 'lifeSustainingTreatment' => [ - 'name' => 'OPTION_A', - 'value' => 'option-a', - ], - 'lpaDonorSignatureDate' => [ - 'date' => '2021-01-10 23:00:00.000000', - 'timezone_type' => 2, - 'timezone' => 'Z', - ], - 'trustCorporations' => [ + "hasSeveranceWarning" => null, + "invalidDate" => null, + "lifeSustainingTreatment" => "option-a", + "lpaDonorSignatureDate" => "10-01-2024 00:00:00", + "lpaIsCleansed" => null, + "onlineLpaId" => null, + "receiptDate" => null, + "registrationDate" => "12-01-2024 00:00:00", + "rejectedDate" => null, + "replacementAttorneys" => null, + "status" => "registered", + "statusDate" => null, + "trustCorporations" => [ [ - 'name' => 'Trust us Corp.', - 'addressLine1' => '103 Line 1', - 'country' => 'GB', - 'town' => 'Town', - 'systemStatus' => 'active', - 'companyName' => 'Trust us Corp.', + "name" => "Trust us Corp.", + "addressLine1" => "103 Line 1", + "addressLine2" => null, + "addressLine3" => null, + "country" => "GB", + "county" => null, + "postcode" => null, + "town" => "Town", + "type" => null, + "dob" => null, + "email" => null, + "firstname" => null, + "firstnames" => null, + "surname" => null, + "otherNames" => null, + "systemStatus" => "active", + "companyName" => "Trust us Corp.", ], ], + "uId" => null, + "withdrawnDate" => null, ]; - $this->lpaDataFormatter->__invoke( - $lpaResponse - )->willReturn($expectedLpaResponse); + $newLpa = ($this->lpaDataFormatter)($lpa); - $actualLpaResponse = ($this->lpaDataFormatter->reveal())($lpaResponse); + $jsonLpa = json_encode($newLpa); + $expectedJsonLpa = json_encode($expectedLpa); - $this->assertEquals($expectedLpaResponse, $actualLpaResponse); + $this->assertEquals($expectedJsonLpa, $jsonLpa); } #[Test] @@ -1328,7 +1351,6 @@ public function can_cast_single_donor(): void ]; $expectedDatastoreDonor = new DataStoreDonor( - null, null, '74 Cloob Close', null, @@ -1443,6 +1465,24 @@ public function can_extract_town_from_datastore(): void $this->assertEquals($expectedTown, $result); } + #[Test] + public function cannot_extract_town_from_datastore(): void + { + $address = [ + 'line1' => '74 Cloob Close', + 'town' => '', + 'country' => 'GB', + ]; + + $extractTownFromDataStore = new ExtractTownFromDataStore(); + + $mockHydrator = $this->createMock(ObjectMapper::class); + + $result = $extractTownFromDataStore->cast($address, $mockHydrator); + + $this->assertEquals(null, $result); + } + #[Test] public function can_extract_country_from_datastore(): void { @@ -1463,6 +1503,24 @@ public function can_extract_country_from_datastore(): void $this->assertEquals($expectedCountry, $result); } + #[Test] + public function cannot_extract_country_from_datastore(): void + { + $address = [ + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', + 'country' => '', + ]; + + $extractCountryFromDataStore = new ExtractCountryFromDataStore(); + + $mockHydrator = $this->createMock(ObjectMapper::class); + + $result = $extractCountryFromDataStore->cast($address, $mockHydrator); + + $this->assertEquals(null, $result); + } + #[Test] public function can_extract_address_one_from_datastore(): void { @@ -1482,4 +1540,22 @@ public function can_extract_address_one_from_datastore(): void $this->assertEquals($expectedAddressOne, $result); } + + #[Test] + public function cannot_extract_address_one_from_datastore(): void + { + $address = [ + 'line1' => '', + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', + ]; + + $extractAddressOneFromDataStore = new ExtractAddressLine1FromDataStore(); + + $mockHydrator = $this->createMock(ObjectMapper::class); + + $result = $extractAddressOneFromDataStore->cast($address, $mockHydrator); + + $this->assertEquals(null, $result); + } } From 7f56c22bbe15e6b3851555aed96e2b3406321bfe Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Mon, 2 Sep 2024 10:20:47 +0100 Subject: [PATCH 10/20] UML-3460 updated tests --- .../AppTest/Service/Lpa/LpaServiceTest.php | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php index 355cf95496..546663a89b 100644 --- a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php @@ -15,8 +15,6 @@ ExtractTownFromDataStore, }; use App\Entity\DataStore\DataStoreDonor; -use App\Entity\Person; -use App\Entity\DataStore\DataStoreLpa; use EventSauce\ObjectHydrator\DefinitionProvider; use EventSauce\ObjectHydrator\KeyFormatterWithoutConversion; use EventSauce\ObjectHydrator\ObjectMapper; @@ -1445,6 +1443,22 @@ public function can_date_to_string_serialised(): void $this->assertEquals($expecteDate, $result); } + #[Test] + public function cannot_convert_date_to_string(): void + { + $date = '22-12-1997'; + + $expecteDate = '22-12-1997'; + + $castDateToStringSerialize = new DateToStringSerializer(); + + $mockHydrator = $this->createMock(ObjectMapper::class); + + $result = $castDateToStringSerialize->serialize($date, $mockHydrator); + + $this->assertEquals($expecteDate, $result); + } + #[Test] public function can_extract_town_from_datastore(): void { @@ -1470,7 +1484,7 @@ public function cannot_extract_town_from_datastore(): void { $address = [ 'line1' => '74 Cloob Close', - 'town' => '', + 'town' => null, 'country' => 'GB', ]; @@ -1509,7 +1523,7 @@ public function cannot_extract_country_from_datastore(): void $address = [ 'line1' => '74 Cloob Close', 'town' => 'Mahhhhhhhhhh', - 'country' => '', + 'country' => null, ]; $extractCountryFromDataStore = new ExtractCountryFromDataStore(); @@ -1545,7 +1559,7 @@ public function can_extract_address_one_from_datastore(): void public function cannot_extract_address_one_from_datastore(): void { $address = [ - 'line1' => '', + 'line1' => null, 'town' => 'Mahhhhhhhhhh', 'country' => 'GB', ]; From 80f392084ed9c87848ae61cd07ab6cac401395d9 Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Mon, 2 Sep 2024 10:59:25 +0100 Subject: [PATCH 11/20] UML-3460 renamed datastore to lpa store --- .../src/Entity/Casters/CastSingleDonor.php | 4 +-- ...hp => ExtractAddressLine1FromLpaStore.php} | 2 +- ...ore.php => ExtractCountryFromLpaStore.php} | 2 +- ...aStore.php => ExtractTownFromLpaStore.php} | 2 +- .../Entity/DataStore/DataStoreAttorney.php | 9 ------- .../LpaStore.php} | 8 +++--- .../src/Entity/LpaStore/LpaStoreAttorney.php | 9 +++++++ .../LpaStoreDonor.php} | 16 ++++++------ .../LpaStorePerson.php} | 16 ++++++------ .../LpaStoreTrustCorporations.php} | 16 ++++++------ .../App/src/Service/Lpa/LpaDataFormatter.php | 4 +-- .../AppTest/Service/Lpa/LpaServiceTest.php | 25 ++++++++----------- 12 files changed, 55 insertions(+), 58 deletions(-) rename service-api/app/src/App/src/Entity/Casters/{ExtractAddressLine1FromDataStore.php => ExtractAddressLine1FromLpaStore.php} (86%) rename service-api/app/src/App/src/Entity/Casters/{ExtractCountryFromDataStore.php => ExtractCountryFromLpaStore.php} (87%) rename service-api/app/src/App/src/Entity/Casters/{ExtractTownFromDataStore.php => ExtractTownFromLpaStore.php} (88%) delete mode 100644 service-api/app/src/App/src/Entity/DataStore/DataStoreAttorney.php rename service-api/app/src/App/src/Entity/{DataStore/DataStoreLpa.php => LpaStore/LpaStore.php} (93%) create mode 100644 service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php rename service-api/app/src/App/src/Entity/{DataStore/DataStoreDonor.php => LpaStore/LpaStoreDonor.php} (77%) rename service-api/app/src/App/src/Entity/{DataStore/DataStorePerson.php => LpaStore/LpaStorePerson.php} (78%) rename service-api/app/src/App/src/Entity/{DataStore/DataStoreTrustCorporations.php => LpaStore/LpaStoreTrustCorporations.php} (76%) diff --git a/service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php b/service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php index 82696e291e..60b236ab65 100644 --- a/service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php +++ b/service-api/app/src/App/src/Entity/Casters/CastSingleDonor.php @@ -4,7 +4,7 @@ namespace App\Entity\Casters; -use App\Entity\DataStore\DataStoreDonor; +use App\Entity\LpaStore\LpaStoreDonor; use Attribute; use EventSauce\ObjectHydrator\ObjectMapper; use EventSauce\ObjectHydrator\PropertyCaster; @@ -18,6 +18,6 @@ class CastSingleDonor implements PropertyCaster */ public function cast(mixed $value, ObjectMapper $hydrator): mixed { - return $hydrator->hydrateObject(DataStoreDonor::class, $value); + return $hydrator->hydrateObject(LpaStoreDonor::class, $value); } } diff --git a/service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromDataStore.php b/service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromLpaStore.php similarity index 86% rename from service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromDataStore.php rename to service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromLpaStore.php index 7517e1ef8e..2bd1454b53 100644 --- a/service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromDataStore.php +++ b/service-api/app/src/App/src/Entity/Casters/ExtractAddressLine1FromLpaStore.php @@ -9,7 +9,7 @@ use EventSauce\ObjectHydrator\PropertyCaster; #[Attribute(Attribute::TARGET_PARAMETER)] -class ExtractAddressLine1FromDataStore implements PropertyCaster +class ExtractAddressLine1FromLpaStore implements PropertyCaster { public function cast(mixed $value, ObjectMapper $hydrator): ?string { diff --git a/service-api/app/src/App/src/Entity/Casters/ExtractCountryFromDataStore.php b/service-api/app/src/App/src/Entity/Casters/ExtractCountryFromLpaStore.php similarity index 87% rename from service-api/app/src/App/src/Entity/Casters/ExtractCountryFromDataStore.php rename to service-api/app/src/App/src/Entity/Casters/ExtractCountryFromLpaStore.php index 88165d3516..5c7f47003c 100644 --- a/service-api/app/src/App/src/Entity/Casters/ExtractCountryFromDataStore.php +++ b/service-api/app/src/App/src/Entity/Casters/ExtractCountryFromLpaStore.php @@ -9,7 +9,7 @@ use EventSauce\ObjectHydrator\PropertyCaster; #[Attribute(Attribute::TARGET_PARAMETER)] -class ExtractCountryFromDataStore implements PropertyCaster +class ExtractCountryFromLpaStore implements PropertyCaster { public function cast(mixed $value, ObjectMapper $hydrator): ?string { diff --git a/service-api/app/src/App/src/Entity/Casters/ExtractTownFromDataStore.php b/service-api/app/src/App/src/Entity/Casters/ExtractTownFromLpaStore.php similarity index 88% rename from service-api/app/src/App/src/Entity/Casters/ExtractTownFromDataStore.php rename to service-api/app/src/App/src/Entity/Casters/ExtractTownFromLpaStore.php index f5ab53bacb..f9229a2a09 100644 --- a/service-api/app/src/App/src/Entity/Casters/ExtractTownFromDataStore.php +++ b/service-api/app/src/App/src/Entity/Casters/ExtractTownFromLpaStore.php @@ -9,7 +9,7 @@ use EventSauce\ObjectHydrator\PropertyCaster; #[Attribute(Attribute::TARGET_PARAMETER)] -class ExtractTownFromDataStore implements PropertyCaster +class ExtractTownFromLpaStore implements PropertyCaster { public function cast(mixed $value, ObjectMapper $hydrator): ?string { diff --git a/service-api/app/src/App/src/Entity/DataStore/DataStoreAttorney.php b/service-api/app/src/App/src/Entity/DataStore/DataStoreAttorney.php deleted file mode 100644 index efc2378d96..0000000000 --- a/service-api/app/src/App/src/Entity/DataStore/DataStoreAttorney.php +++ /dev/null @@ -1,9 +0,0 @@ -hydrateObject( - DataStoreLpa::class, + LpaStore::class, $lpa ); diff --git a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php index 546663a89b..d6ba95531d 100644 --- a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php @@ -10,11 +10,11 @@ CastToLifeSustainingTreatment, CastToWhenTheLpaCanBeUsed, DateToStringSerializer, - ExtractAddressLine1FromDataStore, - ExtractCountryFromDataStore, - ExtractTownFromDataStore, + ExtractAddressLine1FromLpaStore, + ExtractCountryFromLpaStore, + ExtractTownFromLpaStore, }; -use App\Entity\DataStore\DataStoreDonor; +use App\Entity\LpaStore\LpaStoreDonor; use EventSauce\ObjectHydrator\DefinitionProvider; use EventSauce\ObjectHydrator\KeyFormatterWithoutConversion; use EventSauce\ObjectHydrator\ObjectMapper; @@ -1348,7 +1348,7 @@ public function can_cast_single_donor(): void ], ]; - $expectedDatastoreDonor = new DataStoreDonor( + $expectedDatastoreDonor = new LpaStoreDonor( null, '74 Cloob Close', null, @@ -1470,7 +1470,7 @@ public function can_extract_town_from_datastore(): void $expectedTown = 'Mahhhhhhhhhh'; - $extractTownFromDataStore = new ExtractTownFromDataStore(); + $extractTownFromDataStore = new ExtractTownFromLpaStore(); $mockHydrator = $this->createMock(ObjectMapper::class); @@ -1484,11 +1484,10 @@ public function cannot_extract_town_from_datastore(): void { $address = [ 'line1' => '74 Cloob Close', - 'town' => null, 'country' => 'GB', ]; - $extractTownFromDataStore = new ExtractTownFromDataStore(); + $extractTownFromDataStore = new ExtractTownFromLpaStore(); $mockHydrator = $this->createMock(ObjectMapper::class); @@ -1508,7 +1507,7 @@ public function can_extract_country_from_datastore(): void $expectedCountry = 'GB'; - $extractCountryFromDataStore = new ExtractCountryFromDataStore(); + $extractCountryFromDataStore = new ExtractCountryFromLpaStore(); $mockHydrator = $this->createMock(ObjectMapper::class); @@ -1523,10 +1522,9 @@ public function cannot_extract_country_from_datastore(): void $address = [ 'line1' => '74 Cloob Close', 'town' => 'Mahhhhhhhhhh', - 'country' => null, ]; - $extractCountryFromDataStore = new ExtractCountryFromDataStore(); + $extractCountryFromDataStore = new ExtractCountryFromLpaStore(); $mockHydrator = $this->createMock(ObjectMapper::class); @@ -1546,7 +1544,7 @@ public function can_extract_address_one_from_datastore(): void $expectedAddressOne = '74 Cloob Close'; - $extractAddressOneFromDataStore = new ExtractAddressLine1FromDataStore(); + $extractAddressOneFromDataStore = new ExtractAddressLine1FromLpaStore(); $mockHydrator = $this->createMock(ObjectMapper::class); @@ -1559,12 +1557,11 @@ public function can_extract_address_one_from_datastore(): void public function cannot_extract_address_one_from_datastore(): void { $address = [ - 'line1' => null, 'town' => 'Mahhhhhhhhhh', 'country' => 'GB', ]; - $extractAddressOneFromDataStore = new ExtractAddressLine1FromDataStore(); + $extractAddressOneFromDataStore = new ExtractAddressLine1FromLpaStore(); $mockHydrator = $this->createMock(ObjectMapper::class); From 33939ff2283c9a705b882053cf680cc4e87ea0fc Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Tue, 3 Sep 2024 11:56:27 +0100 Subject: [PATCH 12/20] UML-3460 using datetime immutable instead of interface --- .../App/src/Entity/Casters/DateToStringSerializer.php | 3 ++- .../src/Entity/LpaStore/LpaStoreTrustCorporations.php | 4 ++-- .../app/test/AppTest/Service/Lpa/LpaServiceTest.php | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php b/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php index df5a24c49d..20fad6a4f5 100644 --- a/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php +++ b/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php @@ -5,6 +5,7 @@ namespace App\Entity\Casters; use DateTimeImmutable; +use DateTimeInterface; use EventSauce\ObjectHydrator\ObjectMapper; use EventSauce\ObjectHydrator\PropertySerializer; @@ -13,7 +14,7 @@ class DateToStringSerializer implements PropertySerializer public function serialize(mixed $value, ObjectMapper $hydrator): mixed { if ($value instanceof DateTimeImmutable) { - return $value->format('d-m-Y H:i:s'); + return $value->format(DateTimeInterface::ATOM); } return $value; diff --git a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php index d25c2c0291..e19e3c0a68 100644 --- a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php +++ b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php @@ -7,7 +7,7 @@ use App\Entity\Casters\ExtractAddressLine1FromLpaStore; use App\Entity\Casters\ExtractCountryFromLpaStore; use App\Entity\Casters\ExtractTownFromLpaStore; -use DateTimeInterface; +use DateTimeImmutable; use EventSauce\ObjectHydrator\MapFrom; class LpaStoreTrustCorporations extends LpaStorePerson @@ -30,7 +30,7 @@ public function __construct( #[ExtractTownFromLpaStore] ?string $town, ?string $type, - ?DateTimeInterface $dob, + ?DateTimeImmutable $dob, ?string $email, ?string $firstname, ?string $firstnames, diff --git a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php index d6ba95531d..b3e2e5429e 100644 --- a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php @@ -1277,7 +1277,7 @@ public function can_serialise_datastore_lpa_to_modernise_format(): void "postcode" => null, "town" => "Mahhhhhhhhhh", "type" => null, - "dob" => "24-01-1970 00:00:00", + "dob" => "1970-01-24T00:00:00+00:00", "email" => "nobody@not.a.real.domain", "firstname" => null, "firstnames" => "Feeg", @@ -1288,11 +1288,11 @@ public function can_serialise_datastore_lpa_to_modernise_format(): void "hasSeveranceWarning" => null, "invalidDate" => null, "lifeSustainingTreatment" => "option-a", - "lpaDonorSignatureDate" => "10-01-2024 00:00:00", + "lpaDonorSignatureDate" => "2024-01-10T00:00:00+00:00", "lpaIsCleansed" => null, "onlineLpaId" => null, "receiptDate" => null, - "registrationDate" => "12-01-2024 00:00:00", + "registrationDate" => "2024-01-12T00:00:00+00:00", "rejectedDate" => null, "replacementAttorneys" => null, "status" => "registered", @@ -1326,7 +1326,7 @@ public function can_serialise_datastore_lpa_to_modernise_format(): void $jsonLpa = json_encode($newLpa); $expectedJsonLpa = json_encode($expectedLpa); - + print_r($jsonLpa); $this->assertEquals($expectedJsonLpa, $jsonLpa); } @@ -1432,7 +1432,7 @@ public function can_date_to_string_serialised(): void { $date = new \DateTimeImmutable('22-12-1997'); - $expecteDate = '22-12-1997 00:00:00'; + $expecteDate = '1997-12-22T00:00:00+00:00'; $castDateToStringSerialize = new DateToStringSerializer(); From ca36a219f2e6abdc415ef07585185e3db98b7a76 Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Tue, 3 Sep 2024 12:05:05 +0100 Subject: [PATCH 13/20] UML-3460 using datetime interface in DateToStringSerializer.php --- .../app/src/App/src/Entity/Casters/DateToStringSerializer.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php b/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php index 20fad6a4f5..e739bfd4d8 100644 --- a/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php +++ b/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php @@ -4,7 +4,6 @@ namespace App\Entity\Casters; -use DateTimeImmutable; use DateTimeInterface; use EventSauce\ObjectHydrator\ObjectMapper; use EventSauce\ObjectHydrator\PropertySerializer; @@ -13,7 +12,7 @@ class DateToStringSerializer implements PropertySerializer { public function serialize(mixed $value, ObjectMapper $hydrator): mixed { - if ($value instanceof DateTimeImmutable) { + if ($value instanceof DateTimeInterface) { return $value->format(DateTimeInterface::ATOM); } From 32fe33db0c86f05890e943551779a0fefba9a094 Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Tue, 3 Sep 2024 16:18:21 +0100 Subject: [PATCH 14/20] UML-3460 removed unnecessary lpastore person created new files for dedicated tests --- .../src/Entity/LpaStore/LpaStoreAttorney.php | 57 ++- .../App/src/Entity/LpaStore/LpaStoreDonor.php | 3 +- .../src/Entity/LpaStore/LpaStorePerson.php | 64 --- .../LpaStore/LpaStoreTrustCorporations.php | 3 +- ...SerialiseLpaStoreToModerniseFormatTest.php | 114 +++++ .../AppTest/Entity/CastSingleDonorTest.php | 73 +++ .../AppTest/Entity/CastToCaseSubtypeTest.php | 34 ++ .../CastToLifeSustainingTreatmentTest.php | 35 ++ .../Entity/CastToWhenTheLpaCanBeUsedTest.php | 34 ++ .../Entity/DateToStringSerializerTest.php | 47 ++ .../ExtractAddressLine1FromLpaStoreTest.php | 51 +++ .../Entity/ExtractCountryFromLpaStoreTest.php | 51 +++ .../Entity/ExtractTownFromLpaStoreTest.php | 51 +++ .../AppTest/Service/Lpa/LpaServiceTest.php | 415 ------------------ 14 files changed, 550 insertions(+), 482 deletions(-) delete mode 100644 service-api/app/src/App/src/Entity/LpaStore/LpaStorePerson.php create mode 100644 service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php create mode 100644 service-api/app/test/AppTest/Entity/CastSingleDonorTest.php create mode 100644 service-api/app/test/AppTest/Entity/CastToCaseSubtypeTest.php create mode 100644 service-api/app/test/AppTest/Entity/CastToLifeSustainingTreatmentTest.php create mode 100644 service-api/app/test/AppTest/Entity/CastToWhenTheLpaCanBeUsedTest.php create mode 100644 service-api/app/test/AppTest/Entity/DateToStringSerializerTest.php create mode 100644 service-api/app/test/AppTest/Entity/ExtractAddressLine1FromLpaStoreTest.php create mode 100644 service-api/app/test/AppTest/Entity/ExtractCountryFromLpaStoreTest.php create mode 100644 service-api/app/test/AppTest/Entity/ExtractTownFromLpaStoreTest.php diff --git a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php index 6961de737b..bdb90c386c 100644 --- a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php +++ b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php @@ -4,6 +4,61 @@ namespace App\Entity\LpaStore; -class LpaStoreAttorney extends LpaStorePerson +use App\Entity\Casters\ExtractAddressLine1FromLpaStore; +use App\Entity\Casters\ExtractCountryFromLpaStore; +use App\Entity\Casters\ExtractTownFromLpaStore; +use App\Entity\Person; +use EventSauce\ObjectHydrator\MapFrom; +use DateTimeImmutable; + +class LpaStoreAttorney extends Person { + public function __construct( + ?string $name, + #[MapFrom('address')] + #[ExtractAddressLine1FromLpaStore] + ?string $addressLine1, + ?string $addressLine2, + ?string $addressLine3, + #[MapFrom('address')] + #[ExtractCountryFromLpaStore] + ?string $country, + ?string $county, + ?string $postcode, + #[MapFrom('address')] + #[ExtractTownFromLpaStore] + ?string $town, + ?string $type, + #[MapFrom('dateOfBirth')] + ?DateTimeImmutable $dob, + ?string $email, + #[MapFrom('firstname')] + ?string $firstname, + #[MapFrom('firstNames')] + ?string $firstnames, + #[MapFrom('lastName')] + ?string $surname, + ?string $otherNames, + #[MapFrom('status')] + ?string $systemStatus, + ) { + parent::__construct( + $name, + $addressLine1, + $addressLine2, + $addressLine3, + $country, + $county, + $postcode, + $town, + $type, + $dob, + $email, + $firstname, + $firstnames, + $surname, + $otherNames, + $systemStatus + ); + } } diff --git a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreDonor.php b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreDonor.php index 511e8a5147..476059f03d 100644 --- a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreDonor.php +++ b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreDonor.php @@ -7,10 +7,11 @@ use App\Entity\Casters\ExtractAddressLine1FromLpaStore; use App\Entity\Casters\ExtractCountryFromLpaStore; use App\Entity\Casters\ExtractTownFromLpaStore; +use App\Entity\Person; use DateTimeImmutable; use EventSauce\ObjectHydrator\MapFrom; -class LpaStoreDonor extends LpaStorePerson +class LpaStoreDonor extends Person { public function __construct( ?string $name, diff --git a/service-api/app/src/App/src/Entity/LpaStore/LpaStorePerson.php b/service-api/app/src/App/src/Entity/LpaStore/LpaStorePerson.php deleted file mode 100644 index 192bdcfaf2..0000000000 --- a/service-api/app/src/App/src/Entity/LpaStore/LpaStorePerson.php +++ /dev/null @@ -1,64 +0,0 @@ -lpaDataFormatter = new LpaDataFormatter(); + } + + #[Test] + public function can_serialise_datastore_lpa_to_modernise_format(): void + { + + $lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/test_lpa.json'), true); + + $expectedLpa = [ + "applicationHasGuidance" => false, + "applicationHasRestrictions" => false, + "applicationType" => "Classic", + "attorneyActDecisions" => null, + "attorneys" => [ + [ + "name" => null, + "addressLine1" => null, + "addressLine2" => null, + "addressLine3" => null, + "country" => null, + "county" => null, + "postcode" => null, + "town" => null, + "type" => null, + "dob" => null, + "email" => "", + "firstname" => "jean", + "firstnames" => null, + "surname" => null, + "otherNames" => null, + "systemStatus" => null, + ], + [ + "name" => null, + "addressLine1" => null, + "addressLine2" => null, + "addressLine3" => null, + "country" => null, + "county" => null, + "postcode" => null, + "town" => null, + "type" => null, + "dob" => null, + "email" => "XXXXX", + "firstname" => "Ann", + "firstnames" => null, + "surname" => null, + "otherNames" => null, + "systemStatus" => null, + ], + ], + "caseSubtype" => null, + "channel" => null, + "dispatchDate" => null, + "donor" => [ + "name" => null, + "addressLine1" => null, + "addressLine2" => null, + "addressLine3" => null, + "country" => null, + "county" => null, + "postcode" => null, + "town" => null, + "type" => null, + "dob" => null, + "email" => "RachelSanderson@opgtest.com", + "firstname" => "Rachel", + "firstnames" => null, + "surname" => null, + "otherNames" => null, + "systemStatus" => null, + ], + "hasSeveranceWarning" => null, + "invalidDate" => null, + "lifeSustainingTreatment" => null, + "lpaDonorSignatureDate" => null, + "lpaIsCleansed" => true, + "onlineLpaId" => "A33718377316", + "receiptDate" => "2014-09-26T00:00:00+00:00", + "registrationDate" => "2019-10-10T00:00:00+00:00", + "rejectedDate" => null, + "replacementAttorneys" => [], + "status" => "Registered", + "statusDate" => null, + "trustCorporations" => [], + "uId" => "700000000047", + "withdrawnDate" => null, + ]; + + $newLpa = ($this->lpaDataFormatter)($lpa); + + $jsonLpa = json_encode($newLpa); + $expectedJsonLpa = json_encode($expectedLpa); + + $this->assertEquals($expectedJsonLpa, $jsonLpa); + } +} \ No newline at end of file diff --git a/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php b/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php new file mode 100644 index 0000000000..1931617f8e --- /dev/null +++ b/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php @@ -0,0 +1,73 @@ +mockHydrator = $this->createMock(ObjectMapper::class); + $this->castSingleDonor = new CastSingleDonor(); + } + + #[Test] + public function can_cast_single_donor(): void + { + $donor = [ + 'uId' => '700000000971', + 'firstNames' => 'Feeg', + 'surname' => 'Gilson', + 'lastName' => 'Bundlaaaa', + 'email' => 'nobody@not.a.real.domain', + 'middlenames' => 'Suzanne', + 'dateOfBirth' => '1970-01-24', + 'address' => [ + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', + ], + ]; + + $expectedDatastoreDonor = new LpaStoreDonor( + null, + '74 Cloob Close', + null, + null, + 'GB', + null, + null, + 'Mahhhhhhhhhh', + null, + new DateTimeImmutable('1970-01-24 00:00:00.000000'), + 'nobody@not.a.real.domain', + null, + 'Feeg', + 'Bundlaaaa', + null, + null, + ); + + $mapper = new ObjectMapperUsingReflection( + new DefinitionProvider( + keyFormatter: new KeyFormatterWithoutConversion(), + ), + ); + + $result = $this->castSingleDonor->cast($donor, $mapper); + $this->assertEquals($expectedDatastoreDonor, $result); + } +} \ No newline at end of file diff --git a/service-api/app/test/AppTest/Entity/CastToCaseSubtypeTest.php b/service-api/app/test/AppTest/Entity/CastToCaseSubtypeTest.php new file mode 100644 index 0000000000..f97784396f --- /dev/null +++ b/service-api/app/test/AppTest/Entity/CastToCaseSubtypeTest.php @@ -0,0 +1,34 @@ +mockHydrator = $this->createMock(ObjectMapper::class); + $this->castToCaseSubtype = new CastToCaseSubtype(); + } + + #[Test] + public function can_cast_case_subtype(): void + { + $caseSubType = 'personal-welfare'; + + $expectedCaseSubType = 'hw'; + + $result = $this->castToCaseSubtype->cast($caseSubType, $this->mockHydrator); + + $this->assertEquals($expectedCaseSubType, $result); + } +} \ No newline at end of file diff --git a/service-api/app/test/AppTest/Entity/CastToLifeSustainingTreatmentTest.php b/service-api/app/test/AppTest/Entity/CastToLifeSustainingTreatmentTest.php new file mode 100644 index 0000000000..07431035b1 --- /dev/null +++ b/service-api/app/test/AppTest/Entity/CastToLifeSustainingTreatmentTest.php @@ -0,0 +1,35 @@ +mockHydrator = $this->createMock(ObjectMapper::class); + $this->castToLifeSustainingTreatment = new CastToLifeSustainingTreatment(); + } + + #[Test] + public function can_cast_life_sustaining_treatment(): void + { + $lifeSustainingTreatment = 'option-a'; + + $expectedLifeSustainingTreatment = 'option-a'; + + $result = $this->castToLifeSustainingTreatment->cast($lifeSustainingTreatment, $this->mockHydrator); + + $this->assertEquals($expectedLifeSustainingTreatment, $result); + } + +} \ No newline at end of file diff --git a/service-api/app/test/AppTest/Entity/CastToWhenTheLpaCanBeUsedTest.php b/service-api/app/test/AppTest/Entity/CastToWhenTheLpaCanBeUsedTest.php new file mode 100644 index 0000000000..bdabc62e00 --- /dev/null +++ b/service-api/app/test/AppTest/Entity/CastToWhenTheLpaCanBeUsedTest.php @@ -0,0 +1,34 @@ +mockHydrator = $this->createMock(ObjectMapper::class); + $this->castToWhenTheLpaCanBeUsed = new CastToWhenTheLpaCanBeUsed(); + } + + #[Test] + public function can_when_lpa_can_be_used(): void + { + $whenTheLpaCanBeUsed = 'singular'; + + $expectedWhenTheLpaCanBeUsed = 'singular'; + + $result = $this->castToWhenTheLpaCanBeUsed->cast($whenTheLpaCanBeUsed, $this->mockHydrator); + + $this->assertEquals($expectedWhenTheLpaCanBeUsed, $result); + } +} \ No newline at end of file diff --git a/service-api/app/test/AppTest/Entity/DateToStringSerializerTest.php b/service-api/app/test/AppTest/Entity/DateToStringSerializerTest.php new file mode 100644 index 0000000000..e534821396 --- /dev/null +++ b/service-api/app/test/AppTest/Entity/DateToStringSerializerTest.php @@ -0,0 +1,47 @@ +mockHydrator = $this->createMock(ObjectMapper::class); + $this->dateToStringSerializer = new DateToStringSerializer(); + } + + #[Test] + public function can_date_to_string_serialised(): void + { + $date = new DateTimeImmutable('22-12-1997'); + + $expecteDate = '1997-12-22T00:00:00+00:00'; + + $result = $this->dateToStringSerializer->serialize($date, $this->mockHydrator); + + $this->assertEquals($expecteDate, $result); + } + + #[Test] + public function cannot_convert_date_to_string(): void + { + $date = '22-12-1997'; + + $expecteDate = '22-12-1997'; + + $result = $this->dateToStringSerializer->serialize($date, $this->mockHydrator); + + $this->assertEquals($expecteDate, $result); + } +} \ No newline at end of file diff --git a/service-api/app/test/AppTest/Entity/ExtractAddressLine1FromLpaStoreTest.php b/service-api/app/test/AppTest/Entity/ExtractAddressLine1FromLpaStoreTest.php new file mode 100644 index 0000000000..0aaef13f17 --- /dev/null +++ b/service-api/app/test/AppTest/Entity/ExtractAddressLine1FromLpaStoreTest.php @@ -0,0 +1,51 @@ +mockHydrator = $this->createMock(ObjectMapper::class); + $this->extractAddressLine1FromLpaStore = new ExtractAddressLine1FromLpaStore(); + } + + #[Test] + public function can_extract_address_one_from_datastore(): void + { + $address = [ + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', + ]; + + $expectedAddressOne = '74 Cloob Close'; + + $result = $this->extractAddressLine1FromLpaStore->cast($address, $this->mockHydrator); + + $this->assertEquals($expectedAddressOne, $result); + } + + #[Test] + public function cannot_extract_address_one_from_datastore(): void + { + $address = [ + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', + ]; + + $result = $this->extractAddressLine1FromLpaStore->cast($address, $this->mockHydrator); + + $this->assertEquals(null, $result); + } +} \ No newline at end of file diff --git a/service-api/app/test/AppTest/Entity/ExtractCountryFromLpaStoreTest.php b/service-api/app/test/AppTest/Entity/ExtractCountryFromLpaStoreTest.php new file mode 100644 index 0000000000..1d1024778a --- /dev/null +++ b/service-api/app/test/AppTest/Entity/ExtractCountryFromLpaStoreTest.php @@ -0,0 +1,51 @@ +mockHydrator = $this->createMock(ObjectMapper::class); + $this->extractCountryFromLpaStore = new ExtractCountryFromLpaStore(); + } + + #[Test] + public function can_extract_country_from_datastore(): void + { + $address = [ + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', + ]; + + $expectedCountry = 'GB'; + + $result = $this->extractCountryFromLpaStore->cast($address, $this->mockHydrator); + + $this->assertEquals($expectedCountry, $result); + } + + #[Test] + public function cannot_extract_country_from_datastore(): void + { + $address = [ + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', + ]; + + $result = $this->extractCountryFromLpaStore->cast($address, $this->mockHydrator); + + $this->assertEquals(null, $result); + } +} \ No newline at end of file diff --git a/service-api/app/test/AppTest/Entity/ExtractTownFromLpaStoreTest.php b/service-api/app/test/AppTest/Entity/ExtractTownFromLpaStoreTest.php new file mode 100644 index 0000000000..1cdac1d177 --- /dev/null +++ b/service-api/app/test/AppTest/Entity/ExtractTownFromLpaStoreTest.php @@ -0,0 +1,51 @@ +mockHydrator = $this->createMock(ObjectMapper::class); + $this->extractTownFromLpaStore = new ExtractTownFromLpaStore(); + } + + #[Test] + public function can_extract_town_from_datastore(): void + { + $address = [ + 'line1' => '74 Cloob Close', + 'town' => 'Mahhhhhhhhhh', + 'country' => 'GB', + ]; + + $expectedTown = 'Mahhhhhhhhhh'; + + $result = $this->extractTownFromLpaStore->cast($address, $this->mockHydrator); + + $this->assertEquals($expectedTown, $result); + } + + #[Test] + public function cannot_extract_town_from_datastore(): void + { + $address = [ + 'line1' => '74 Cloob Close', + 'country' => 'GB', + ]; + + $result = $this->extractTownFromLpaStore->cast($address, $this->mockHydrator); + + $this->assertEquals(null, $result); + } +} \ No newline at end of file diff --git a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php index b3e2e5429e..5f30886c18 100644 --- a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php @@ -1154,419 +1154,4 @@ public function will_return_empty_lpa_array_when_status_invalid(): void $this->assertEmpty($result); } - - #[Test] - public function can_serialise_datastore_lpa_to_modernise_format(): void - { - $lpa = [ - 'uid' => 'M-789Q-P4DF-4UX3', - 'status' => 'registered', - 'registrationDate' => '2024-01-12', - 'updatedAt' => '2024-01-12', - 'lpaType' => 'personal-welfare', - 'channel' => 'online', - 'donor' => [ - 'uid' => 'eda719db-8880-4dda-8c5d-bb9ea12c236f', - 'firstNames' => 'Feeg', - 'lastName' => 'Bundlaaaa', - 'address' => [ - 'line1' => '74 Cloob Close', - 'town' => 'Mahhhhhhhhhh', - 'country' => 'GB', - ], - 'email' => 'nobody@not.a.real.domain', - 'dateOfBirth' => '1970-01-24', - 'contactLanguagePreference' => 'en', - 'identityCheck' => [ - 'checkedAt' => '2024-01-10', - 'type' => 'one-login', - ] - ], - 'attorneys'=> [ - [ - 'uid' => '9ac5cb7c-fc75-40c7-8e53-059f36dbbe3d', - 'firstNames' => 'Herman', - 'lastName' => 'Seakrest', - 'address' => [ - 'line1' => '81 NighOnTimeWeBuiltIt Street', - 'town' => 'Mahhhhhhhhhh', - 'country' => 'GB', - ], - 'status' => 'active', - 'channel' => 'paper', - 'signedAt' => '2024-01-10', - ], - ], - 'trustCorporations'=> [ - [ - 'uid'=> '1d95993a-ffbb-484c-b2fe-f4cca51801da', - 'name'=> 'Trust us Corp.', - 'companyNumber'=> '666123321', - 'address'=> [ - 'line1'=> '103 Line 1', - 'town'=> 'Town', - 'country'=> 'GB', - ], - 'status'=> 'active', - 'channel'=> 'paper', - 'signedAt'=> '2024-01-10', - ], - ], - 'certificateProvider'=> [ - 'uid' => '6808960d-12cf-47c5-a2bc-3177deb8599c', - 'firstNames' => 'Vone', - 'lastName' => 'Spust', - 'address' => [ - 'line1'=> '122111 Zonnington Way', - 'town' => 'Mahhhhhhhhhh', - 'country' => 'GB', - ], - 'channel' => 'online', - 'email' => 'a@example.com', - 'phone' => '070009000', - 'signedAt' => '2024-01-10', - 'identityCheck' => [ - 'checkedAt' => '2024-01-10', - 'type' => 'one-login', - ], - ], - 'lifeSustainingTreatmentOption'=> 'option-a', - 'signedAt'=> '2024-01-10', - 'howAttorneysMakeDecisions'=> 'jointly', - 'whenTheLpaCanBeUsed'=> 'when-capacity-lost', - 'applicationHasGuidance'=> false, - 'applicationHasRestrictions'=> false, - 'applicationType'=> null, - ]; - - $expectedLpa = [ - "applicationHasGuidance" => false, - "applicationHasRestrictions" => false, - "applicationType" => null, - "attorneyActDecisions" => "jointly", - "attorneys" => [ - [ - "name" => null, - "addressLine1" => "81 NighOnTimeWeBuiltIt Street", - "addressLine2" => null, - "addressLine3" => null, - "country" => "GB", - "county" => null, - "postcode" => null, - "town" => "Mahhhhhhhhhh", - "type" => null, - "dob" => null, - "email" => null, - "firstname" => null, - "firstnames" => "Herman", - "surname" => "Seakrest", - "otherNames" => null, - "systemStatus" => "active", - ], - ], - "caseSubtype" => "hw", - "channel" => "online", - "dispatchDate" => null, - "donor" => [ - "name" => null, - "addressLine1" => "74 Cloob Close", - "addressLine2" => null, - "addressLine3" => null, - "country" => "GB", - "county" => null, - "postcode" => null, - "town" => "Mahhhhhhhhhh", - "type" => null, - "dob" => "1970-01-24T00:00:00+00:00", - "email" => "nobody@not.a.real.domain", - "firstname" => null, - "firstnames" => "Feeg", - "surname" => "Bundlaaaa", - "otherNames" => null, - "systemStatus" => null, - ], - "hasSeveranceWarning" => null, - "invalidDate" => null, - "lifeSustainingTreatment" => "option-a", - "lpaDonorSignatureDate" => "2024-01-10T00:00:00+00:00", - "lpaIsCleansed" => null, - "onlineLpaId" => null, - "receiptDate" => null, - "registrationDate" => "2024-01-12T00:00:00+00:00", - "rejectedDate" => null, - "replacementAttorneys" => null, - "status" => "registered", - "statusDate" => null, - "trustCorporations" => [ - [ - "name" => "Trust us Corp.", - "addressLine1" => "103 Line 1", - "addressLine2" => null, - "addressLine3" => null, - "country" => "GB", - "county" => null, - "postcode" => null, - "town" => "Town", - "type" => null, - "dob" => null, - "email" => null, - "firstname" => null, - "firstnames" => null, - "surname" => null, - "otherNames" => null, - "systemStatus" => "active", - "companyName" => "Trust us Corp.", - ], - ], - "uId" => null, - "withdrawnDate" => null, - ]; - - $newLpa = ($this->lpaDataFormatter)($lpa); - - $jsonLpa = json_encode($newLpa); - $expectedJsonLpa = json_encode($expectedLpa); - print_r($jsonLpa); - $this->assertEquals($expectedJsonLpa, $jsonLpa); - } - - #[Test] - public function can_cast_single_donor(): void - { - $donor = [ - 'uId' => '700000000971', - 'firstNames' => 'Feeg', - 'surname' => 'Gilson', - 'lastName' => 'Bundlaaaa', - 'email' => 'nobody@not.a.real.domain', - 'middlenames' => 'Suzanne', - 'dateOfBirth' => '1970-01-24', - 'address' => [ - 'line1' => '74 Cloob Close', - 'town' => 'Mahhhhhhhhhh', - 'country' => 'GB', - ], - ]; - - $expectedDatastoreDonor = new LpaStoreDonor( - null, - '74 Cloob Close', - null, - null, - 'GB', - null, - null, - 'Mahhhhhhhhhh', - null, - new \DateTimeImmutable('1970-01-24 00:00:00.000000'), - 'nobody@not.a.real.domain', - null, - 'Feeg', - 'Bundlaaaa', - null, - null, - ); - - $castSingleDonor = new CastSingleDonor(); - - $mapper = new ObjectMapperUsingReflection( - new DefinitionProvider( - keyFormatter: new KeyFormatterWithoutConversion(), - ), - ); - - $result = $castSingleDonor->cast($donor, $mapper); - $this->assertEquals($expectedDatastoreDonor, $result); - } - - #[Test] - public function can_cast_case_subtype(): void - { - $caseSubType = 'personal-welfare'; - - $expectedCaseSubType = 'hw'; - - $castToSingleSubType = new CastToCaseSubtype(); - - $mockHydrator = $this->createMock(ObjectMapper::class); - - $result = $castToSingleSubType->cast($caseSubType, $mockHydrator); - - $this->assertEquals($expectedCaseSubType, $result); - } - - #[Test] - public function can_cast_life_sustaining_treatment(): void - { - $lifeSustainingTreatment = 'option-a'; - - $expectedLifeSustainingTreatment = 'option-a'; - - $castToLifeSustainingTreatment = new CastToLifeSustainingTreatment(); - - $mockHydrator = $this->createMock(ObjectMapper::class); - - $result = $castToLifeSustainingTreatment->cast($lifeSustainingTreatment, $mockHydrator); - - $this->assertEquals($expectedLifeSustainingTreatment, $result); - } - - #[Test] - public function can_when_lpa_can_be_used(): void - { - $whenTheLpaCanBeUsed = 'singular'; - - $expectedWhenTheLpaCanBeUsed = 'singular'; - - $castToWhenTheLpaCanBeUsed = new CastToWhenTheLpaCanBeUsed(); - - $mockHydrator = $this->createMock(ObjectMapper::class); - - $result = $castToWhenTheLpaCanBeUsed->cast($whenTheLpaCanBeUsed, $mockHydrator); - - $this->assertEquals($expectedWhenTheLpaCanBeUsed, $result); - } - - #[Test] - public function can_date_to_string_serialised(): void - { - $date = new \DateTimeImmutable('22-12-1997'); - - $expecteDate = '1997-12-22T00:00:00+00:00'; - - $castDateToStringSerialize = new DateToStringSerializer(); - - $mockHydrator = $this->createMock(ObjectMapper::class); - - $result = $castDateToStringSerialize->serialize($date, $mockHydrator); - - $this->assertEquals($expecteDate, $result); - } - - #[Test] - public function cannot_convert_date_to_string(): void - { - $date = '22-12-1997'; - - $expecteDate = '22-12-1997'; - - $castDateToStringSerialize = new DateToStringSerializer(); - - $mockHydrator = $this->createMock(ObjectMapper::class); - - $result = $castDateToStringSerialize->serialize($date, $mockHydrator); - - $this->assertEquals($expecteDate, $result); - } - - #[Test] - public function can_extract_town_from_datastore(): void - { - $address = [ - 'line1' => '74 Cloob Close', - 'town' => 'Mahhhhhhhhhh', - 'country' => 'GB', - ]; - - $expectedTown = 'Mahhhhhhhhhh'; - - $extractTownFromDataStore = new ExtractTownFromLpaStore(); - - $mockHydrator = $this->createMock(ObjectMapper::class); - - $result = $extractTownFromDataStore->cast($address, $mockHydrator); - - $this->assertEquals($expectedTown, $result); - } - - #[Test] - public function cannot_extract_town_from_datastore(): void - { - $address = [ - 'line1' => '74 Cloob Close', - 'country' => 'GB', - ]; - - $extractTownFromDataStore = new ExtractTownFromLpaStore(); - - $mockHydrator = $this->createMock(ObjectMapper::class); - - $result = $extractTownFromDataStore->cast($address, $mockHydrator); - - $this->assertEquals(null, $result); - } - - #[Test] - public function can_extract_country_from_datastore(): void - { - $address = [ - 'line1' => '74 Cloob Close', - 'town' => 'Mahhhhhhhhhh', - 'country' => 'GB', - ]; - - $expectedCountry = 'GB'; - - $extractCountryFromDataStore = new ExtractCountryFromLpaStore(); - - $mockHydrator = $this->createMock(ObjectMapper::class); - - $result = $extractCountryFromDataStore->cast($address, $mockHydrator); - - $this->assertEquals($expectedCountry, $result); - } - - #[Test] - public function cannot_extract_country_from_datastore(): void - { - $address = [ - 'line1' => '74 Cloob Close', - 'town' => 'Mahhhhhhhhhh', - ]; - - $extractCountryFromDataStore = new ExtractCountryFromLpaStore(); - - $mockHydrator = $this->createMock(ObjectMapper::class); - - $result = $extractCountryFromDataStore->cast($address, $mockHydrator); - - $this->assertEquals(null, $result); - } - - #[Test] - public function can_extract_address_one_from_datastore(): void - { - $address = [ - 'line1' => '74 Cloob Close', - 'town' => 'Mahhhhhhhhhh', - 'country' => 'GB', - ]; - - $expectedAddressOne = '74 Cloob Close'; - - $extractAddressOneFromDataStore = new ExtractAddressLine1FromLpaStore(); - - $mockHydrator = $this->createMock(ObjectMapper::class); - - $result = $extractAddressOneFromDataStore->cast($address, $mockHydrator); - - $this->assertEquals($expectedAddressOne, $result); - } - - #[Test] - public function cannot_extract_address_one_from_datastore(): void - { - $address = [ - 'town' => 'Mahhhhhhhhhh', - 'country' => 'GB', - ]; - - $extractAddressOneFromDataStore = new ExtractAddressLine1FromLpaStore(); - - $mockHydrator = $this->createMock(ObjectMapper::class); - - $result = $extractAddressOneFromDataStore->cast($address, $mockHydrator); - - $this->assertEquals(null, $result); - } } From 72be528f137a4af9c67a3ba9f0f262439c744d16 Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Wed, 4 Sep 2024 09:10:42 +0100 Subject: [PATCH 15/20] UML-3460 CanSerialiseLpaStoreToModerniseFormatTest.php test --- ...SerialiseLpaStoreToModerniseFormatTest.php | 188 +++++++++++------- 1 file changed, 112 insertions(+), 76 deletions(-) diff --git a/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php b/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php index 051d52b2e8..c2a3a4e9af 100644 --- a/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php +++ b/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php @@ -20,88 +20,124 @@ public function setUp(): void #[Test] public function can_serialise_datastore_lpa_to_modernise_format(): void { - $lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/test_lpa.json'), true); - $expectedLpa = [ - "applicationHasGuidance" => false, - "applicationHasRestrictions" => false, - "applicationType" => "Classic", - "attorneyActDecisions" => null, - "attorneys" => [ - [ - "name" => null, - "addressLine1" => null, - "addressLine2" => null, - "addressLine3" => null, - "country" => null, - "county" => null, - "postcode" => null, - "town" => null, - "type" => null, - "dob" => null, - "email" => "", - "firstname" => "jean", - "firstnames" => null, - "surname" => null, - "otherNames" => null, - "systemStatus" => null, + $lpa['trustCorporations'] = [ + [ + 'uid' => '1d95993a-ffbb-484c-b2fe-f4cca51801da', + 'name' => 'Trust us Corp.', + 'companyNumber' => '666123321', + 'address' => [ + 'line1' => '103 Line 1', + 'town' => 'Town', + 'country' => 'GB', + ], + 'status' => 'active', + 'channel' => 'paper', + 'signedAt' => '2024-01-10', + ], + ]; + + $expectedLpa = [ + 'applicationHasGuidance' => false, + 'applicationHasRestrictions' => false, + 'applicationType' => 'Classic', + 'attorneyActDecisions' => NULL, + 'attorneys' => [ + 0 => [ + 'name' => NULL, + 'addressLine1' => NULL, + 'addressLine2' => NULL, + 'addressLine3' => NULL, + 'country' => NULL, + 'county' => NULL, + 'postcode' => NULL, + 'town' => NULL, + 'type' => NULL, + 'dob' => NULL, + 'email' => '', + 'firstname' => 'jean', + 'firstnames' => NULL, + 'surname' => NULL, + 'otherNames' => NULL, + 'systemStatus' => NULL, ], - [ - "name" => null, - "addressLine1" => null, - "addressLine2" => null, - "addressLine3" => null, - "country" => null, - "county" => null, - "postcode" => null, - "town" => null, - "type" => null, - "dob" => null, - "email" => "XXXXX", - "firstname" => "Ann", - "firstnames" => null, - "surname" => null, - "otherNames" => null, - "systemStatus" => null, + 1 => [ + 'name' => NULL, + 'addressLine1' => NULL, + 'addressLine2' => NULL, + 'addressLine3' => NULL, + 'country' => NULL, + 'county' => NULL, + 'postcode' => NULL, + 'town' => NULL, + 'type' => NULL, + 'dob' => NULL, + 'email' => 'XXXXX', + 'firstname' => 'Ann', + 'firstnames' => NULL, + 'surname' => NULL, + 'otherNames' => NULL, + 'systemStatus' => NULL, ], ], - "caseSubtype" => null, - "channel" => null, - "dispatchDate" => null, - "donor" => [ - "name" => null, - "addressLine1" => null, - "addressLine2" => null, - "addressLine3" => null, - "country" => null, - "county" => null, - "postcode" => null, - "town" => null, - "type" => null, - "dob" => null, - "email" => "RachelSanderson@opgtest.com", - "firstname" => "Rachel", - "firstnames" => null, - "surname" => null, - "otherNames" => null, - "systemStatus" => null, + 'caseSubtype' => NULL, + 'channel' => NULL, + 'dispatchDate' => NULL, + 'donor' => [ + 'name' => NULL, + 'addressLine1' => NULL, + 'addressLine2' => NULL, + 'addressLine3' => NULL, + 'country' => NULL, + 'county' => NULL, + 'postcode' => NULL, + 'town' => NULL, + 'type' => NULL, + 'dob' => NULL, + 'email' => 'RachelSanderson@opgtest.com', + 'firstname' => 'Rachel', + 'firstnames' => NULL, + 'surname' => NULL, + 'otherNames' => NULL, + 'systemStatus' => NULL, + ], + 'hasSeveranceWarning' => NULL, + 'invalidDate' => NULL, + 'lifeSustainingTreatment' => NULL, + 'lpaDonorSignatureDate' => NULL, + 'lpaIsCleansed' => true, + 'onlineLpaId' => 'A33718377316', + 'receiptDate' => '2014-09-26T00:00:00+00:00', + 'registrationDate' => '2019-10-10T00:00:00+00:00', + 'rejectedDate' => NULL, + 'replacementAttorneys' => [ + ], + 'status' => 'Registered', + 'statusDate' => NULL, + 'trustCorporations' => [ + 0 => [ + 'name' => 'Trust us Corp.', + 'addressLine1' => '103 Line 1', + 'addressLine2' => NULL, + 'addressLine3' => NULL, + 'country' => 'GB', + 'county' => NULL, + 'postcode' => NULL, + 'town' => 'Town', + 'type' => NULL, + 'dob' => NULL, + 'email' => NULL, + 'firstname' => NULL, + 'firstnames' => NULL, + 'surname' => NULL, + 'otherNames' => NULL, + 'systemStatus' => 'active', + 'companyName' => 'Trust us Corp.', + ], ], - "hasSeveranceWarning" => null, - "invalidDate" => null, - "lifeSustainingTreatment" => null, - "lpaDonorSignatureDate" => null, - "lpaIsCleansed" => true, - "onlineLpaId" => "A33718377316", - "receiptDate" => "2014-09-26T00:00:00+00:00", - "registrationDate" => "2019-10-10T00:00:00+00:00", - "rejectedDate" => null, - "replacementAttorneys" => [], - "status" => "Registered", - "statusDate" => null, - "trustCorporations" => [], - "uId" => "700000000047", - "withdrawnDate" => null, + 'uId' => '700000000047', + 'withdrawnDate' => NULL, ]; $newLpa = ($this->lpaDataFormatter)($lpa); From 1999c0f6abe13f2ef4fdc3060f05f919b324bb14 Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Wed, 4 Sep 2024 10:08:40 +0100 Subject: [PATCH 16/20] UML-3460 fixed php lint errors --- ...SerialiseLpaStoreToModerniseFormatTest.php | 175 +++++++++--------- .../AppTest/Entity/CastSingleDonorTest.php | 2 +- .../AppTest/Entity/CastToCaseSubtypeTest.php | 2 +- .../CastToLifeSustainingTreatmentTest.php | 3 +- .../Entity/CastToWhenTheLpaCanBeUsedTest.php | 2 +- .../Entity/DateToStringSerializerTest.php | 2 +- .../ExtractAddressLine1FromLpaStoreTest.php | 2 +- .../Entity/ExtractCountryFromLpaStoreTest.php | 2 +- .../Entity/ExtractTownFromLpaStoreTest.php | 2 +- 9 files changed, 95 insertions(+), 97 deletions(-) diff --git a/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php b/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php index c2a3a4e9af..8b0caacaac 100644 --- a/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php +++ b/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php @@ -39,105 +39,104 @@ public function can_serialise_datastore_lpa_to_modernise_format(): void ]; $expectedLpa = [ - 'applicationHasGuidance' => false, + 'applicationHasGuidance' => false, 'applicationHasRestrictions' => false, - 'applicationType' => 'Classic', - 'attorneyActDecisions' => NULL, - 'attorneys' => [ + 'applicationType' => 'Classic', + 'attorneyActDecisions' => null, + 'attorneys' => [ 0 => [ - 'name' => NULL, - 'addressLine1' => NULL, - 'addressLine2' => NULL, - 'addressLine3' => NULL, - 'country' => NULL, - 'county' => NULL, - 'postcode' => NULL, - 'town' => NULL, - 'type' => NULL, - 'dob' => NULL, - 'email' => '', - 'firstname' => 'jean', - 'firstnames' => NULL, - 'surname' => NULL, - 'otherNames' => NULL, - 'systemStatus' => NULL, + 'name' => null, + 'addressLine1' => null, + 'addressLine2' => null, + 'addressLine3' => null, + 'country' => null, + 'county' => null, + 'postcode' => null, + 'town' => null, + 'type' => null, + 'dob' => null, + 'email' => '', + 'firstname' => 'jean', + 'firstnames' => null, + 'surname' => null, + 'otherNames' => null, + 'systemStatus' => null, ], 1 => [ - 'name' => NULL, - 'addressLine1' => NULL, - 'addressLine2' => NULL, - 'addressLine3' => NULL, - 'country' => NULL, - 'county' => NULL, - 'postcode' => NULL, - 'town' => NULL, - 'type' => NULL, - 'dob' => NULL, - 'email' => 'XXXXX', - 'firstname' => 'Ann', - 'firstnames' => NULL, - 'surname' => NULL, - 'otherNames' => NULL, - 'systemStatus' => NULL, + 'name' => null, + 'addressLine1' => null, + 'addressLine2' => null, + 'addressLine3' => null, + 'country' => null, + 'county' => null, + 'postcode' => null, + 'town' => null, + 'type' => null, + 'dob' => null, + 'email' => 'XXXXX', + 'firstname' => 'Ann', + 'firstnames' => null, + 'surname' => null, + 'otherNames' => null, + 'systemStatus' => null, ], ], - 'caseSubtype' => NULL, - 'channel' => NULL, - 'dispatchDate' => NULL, - 'donor' => [ - 'name' => NULL, - 'addressLine1' => NULL, - 'addressLine2' => NULL, - 'addressLine3' => NULL, - 'country' => NULL, - 'county' => NULL, - 'postcode' => NULL, - 'town' => NULL, - 'type' => NULL, - 'dob' => NULL, - 'email' => 'RachelSanderson@opgtest.com', - 'firstname' => 'Rachel', - 'firstnames' => NULL, - 'surname' => NULL, - 'otherNames' => NULL, - 'systemStatus' => NULL, + 'caseSubtype' => null, + 'channel' => null, + 'dispatchDate' => null, + 'donor' => [ + 'name' => null, + 'addressLine1' => null, + 'addressLine2' => null, + 'addressLine3' => null, + 'country' => null, + 'county' => null, + 'postcode' => null, + 'town' => null, + 'type' => null, + 'dob' => null, + 'email' => 'RachelSanderson@opgtest.com', + 'firstname' => 'Rachel', + 'firstnames' => null, + 'surname' => null, + 'otherNames' => null, + 'systemStatus' => null, ], - 'hasSeveranceWarning' => NULL, - 'invalidDate' => NULL, - 'lifeSustainingTreatment' => NULL, - 'lpaDonorSignatureDate' => NULL, - 'lpaIsCleansed' => true, - 'onlineLpaId' => 'A33718377316', - 'receiptDate' => '2014-09-26T00:00:00+00:00', - 'registrationDate' => '2019-10-10T00:00:00+00:00', - 'rejectedDate' => NULL, - 'replacementAttorneys' => [ - ], - 'status' => 'Registered', - 'statusDate' => NULL, - 'trustCorporations' => [ + 'hasSeveranceWarning' => null, + 'invalidDate' => null, + 'lifeSustainingTreatment' => null, + 'lpaDonorSignatureDate' => null, + 'lpaIsCleansed' => true, + 'onlineLpaId' => 'A33718377316', + 'receiptDate' => '2014-09-26T00:00:00+00:00', + 'registrationDate' => '2019-10-10T00:00:00+00:00', + 'rejectedDate' => null, + 'replacementAttorneys' => [], + 'status' => 'Registered', + 'statusDate' => null, + 'trustCorporations' => [ 0 => [ - 'name' => 'Trust us Corp.', + 'name' => 'Trust us Corp.', 'addressLine1' => '103 Line 1', - 'addressLine2' => NULL, - 'addressLine3' => NULL, - 'country' => 'GB', - 'county' => NULL, - 'postcode' => NULL, - 'town' => 'Town', - 'type' => NULL, - 'dob' => NULL, - 'email' => NULL, - 'firstname' => NULL, - 'firstnames' => NULL, - 'surname' => NULL, - 'otherNames' => NULL, + 'addressLine2' => null, + 'addressLine3' => null, + 'country' => 'GB', + 'county' => null, + 'postcode' => null, + 'town' => 'Town', + 'type' => null, + 'dob' => null, + 'email' => null, + 'firstname' => null, + 'firstnames' => null, + 'surname' => null, + 'otherNames' => null, 'systemStatus' => 'active', - 'companyName' => 'Trust us Corp.', + 'companyName' => 'Trust us Corp.', ], ], - 'uId' => '700000000047', - 'withdrawnDate' => NULL, + 'uId' => '700000000047', + 'withdrawnDate' => null, ]; $newLpa = ($this->lpaDataFormatter)($lpa); @@ -147,4 +146,4 @@ public function can_serialise_datastore_lpa_to_modernise_format(): void $this->assertEquals($expectedJsonLpa, $jsonLpa); } -} \ No newline at end of file +} diff --git a/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php b/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php index 1931617f8e..1c85933683 100644 --- a/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php +++ b/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php @@ -70,4 +70,4 @@ public function can_cast_single_donor(): void $result = $this->castSingleDonor->cast($donor, $mapper); $this->assertEquals($expectedDatastoreDonor, $result); } -} \ No newline at end of file +} diff --git a/service-api/app/test/AppTest/Entity/CastToCaseSubtypeTest.php b/service-api/app/test/AppTest/Entity/CastToCaseSubtypeTest.php index f97784396f..031c6a9616 100644 --- a/service-api/app/test/AppTest/Entity/CastToCaseSubtypeTest.php +++ b/service-api/app/test/AppTest/Entity/CastToCaseSubtypeTest.php @@ -31,4 +31,4 @@ public function can_cast_case_subtype(): void $this->assertEquals($expectedCaseSubType, $result); } -} \ No newline at end of file +} diff --git a/service-api/app/test/AppTest/Entity/CastToLifeSustainingTreatmentTest.php b/service-api/app/test/AppTest/Entity/CastToLifeSustainingTreatmentTest.php index 07431035b1..4114075052 100644 --- a/service-api/app/test/AppTest/Entity/CastToLifeSustainingTreatmentTest.php +++ b/service-api/app/test/AppTest/Entity/CastToLifeSustainingTreatmentTest.php @@ -31,5 +31,4 @@ public function can_cast_life_sustaining_treatment(): void $this->assertEquals($expectedLifeSustainingTreatment, $result); } - -} \ No newline at end of file +} diff --git a/service-api/app/test/AppTest/Entity/CastToWhenTheLpaCanBeUsedTest.php b/service-api/app/test/AppTest/Entity/CastToWhenTheLpaCanBeUsedTest.php index bdabc62e00..76d37b091c 100644 --- a/service-api/app/test/AppTest/Entity/CastToWhenTheLpaCanBeUsedTest.php +++ b/service-api/app/test/AppTest/Entity/CastToWhenTheLpaCanBeUsedTest.php @@ -31,4 +31,4 @@ public function can_when_lpa_can_be_used(): void $this->assertEquals($expectedWhenTheLpaCanBeUsed, $result); } -} \ No newline at end of file +} diff --git a/service-api/app/test/AppTest/Entity/DateToStringSerializerTest.php b/service-api/app/test/AppTest/Entity/DateToStringSerializerTest.php index e534821396..89630d1610 100644 --- a/service-api/app/test/AppTest/Entity/DateToStringSerializerTest.php +++ b/service-api/app/test/AppTest/Entity/DateToStringSerializerTest.php @@ -44,4 +44,4 @@ public function cannot_convert_date_to_string(): void $this->assertEquals($expecteDate, $result); } -} \ No newline at end of file +} diff --git a/service-api/app/test/AppTest/Entity/ExtractAddressLine1FromLpaStoreTest.php b/service-api/app/test/AppTest/Entity/ExtractAddressLine1FromLpaStoreTest.php index 0aaef13f17..97c7b5522f 100644 --- a/service-api/app/test/AppTest/Entity/ExtractAddressLine1FromLpaStoreTest.php +++ b/service-api/app/test/AppTest/Entity/ExtractAddressLine1FromLpaStoreTest.php @@ -48,4 +48,4 @@ public function cannot_extract_address_one_from_datastore(): void $this->assertEquals(null, $result); } -} \ No newline at end of file +} diff --git a/service-api/app/test/AppTest/Entity/ExtractCountryFromLpaStoreTest.php b/service-api/app/test/AppTest/Entity/ExtractCountryFromLpaStoreTest.php index 1d1024778a..ceca89b227 100644 --- a/service-api/app/test/AppTest/Entity/ExtractCountryFromLpaStoreTest.php +++ b/service-api/app/test/AppTest/Entity/ExtractCountryFromLpaStoreTest.php @@ -48,4 +48,4 @@ public function cannot_extract_country_from_datastore(): void $this->assertEquals(null, $result); } -} \ No newline at end of file +} diff --git a/service-api/app/test/AppTest/Entity/ExtractTownFromLpaStoreTest.php b/service-api/app/test/AppTest/Entity/ExtractTownFromLpaStoreTest.php index 1cdac1d177..f9f7d4bcae 100644 --- a/service-api/app/test/AppTest/Entity/ExtractTownFromLpaStoreTest.php +++ b/service-api/app/test/AppTest/Entity/ExtractTownFromLpaStoreTest.php @@ -48,4 +48,4 @@ public function cannot_extract_town_from_datastore(): void $this->assertEquals(null, $result); } -} \ No newline at end of file +} From f6404d16147b11219581ed6755efda28274b4c75 Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Thu, 5 Sep 2024 09:54:58 +0100 Subject: [PATCH 17/20] UML-3460 fixed dob not serializing, using lpa store example json for tests, and removed unused imports --- .../Entity/Casters/DateToStringSerializer.php | 21 ---- .../src/App/src/Entity/LpaStore/LpaStore.php | 1 + .../src/Entity/LpaStore/LpaStoreAttorney.php | 5 +- .../App/src/Entity/LpaStore/LpaStoreDonor.php | 3 + .../LpaStore/LpaStoreTrustCorporations.php | 4 + service-api/app/src/App/src/Entity/Person.php | 1 + .../App/src/Service/Lpa/LpaDataFormatter.php | 19 --- ...SerialiseLpaStoreToModerniseFormatTest.php | 108 ++++++------------ .../Entity/DateToStringSerializerTest.php | 47 -------- .../AppTest/Service/Lpa/LpaServiceTest.php | 20 ---- service-api/app/test/fixtures/4UX3.json | 78 +++++++++++++ 11 files changed, 129 insertions(+), 178 deletions(-) delete mode 100644 service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php delete mode 100644 service-api/app/test/AppTest/Entity/DateToStringSerializerTest.php create mode 100644 service-api/app/test/fixtures/4UX3.json diff --git a/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php b/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php deleted file mode 100644 index e739bfd4d8..0000000000 --- a/service-api/app/src/App/src/Entity/Casters/DateToStringSerializer.php +++ /dev/null @@ -1,21 +0,0 @@ -format(DateTimeInterface::ATOM); - } - - return $value; - } -} diff --git a/service-api/app/src/App/src/Entity/LpaStore/LpaStore.php b/service-api/app/src/App/src/Entity/LpaStore/LpaStore.php index ec42193c60..11f5f95a7e 100644 --- a/service-api/app/src/App/src/Entity/LpaStore/LpaStore.php +++ b/service-api/app/src/App/src/Entity/LpaStore/LpaStore.php @@ -51,6 +51,7 @@ public function __construct( ?DateTimeImmutable $statusDate, #[CastListToType(LpaStoreTrustCorporations::class)] ?array $trustCorporations, + #[MapFrom('uid')] ?string $uId, ?DateTimeImmutable $withdrawnDate, ) { diff --git a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php index bdb90c386c..a82bafcbb3 100644 --- a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php +++ b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php @@ -8,12 +8,14 @@ use App\Entity\Casters\ExtractCountryFromLpaStore; use App\Entity\Casters\ExtractTownFromLpaStore; use App\Entity\Person; -use EventSauce\ObjectHydrator\MapFrom; use DateTimeImmutable; +use EventSauce\ObjectHydrator\MapFrom; class LpaStoreAttorney extends Person { public function __construct( + #[MapFrom('uid')] + ?string $uId, ?string $name, #[MapFrom('address')] #[ExtractAddressLine1FromLpaStore] @@ -43,6 +45,7 @@ public function __construct( ?string $systemStatus, ) { parent::__construct( + $uId, $name, $addressLine1, $addressLine2, diff --git a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreDonor.php b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreDonor.php index 476059f03d..297b4202cd 100644 --- a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreDonor.php +++ b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreDonor.php @@ -14,6 +14,8 @@ class LpaStoreDonor extends Person { public function __construct( + #[MapFrom('uid')] + ?string $uId, ?string $name, #[MapFrom('address')] #[ExtractAddressLine1FromLpaStore] @@ -42,6 +44,7 @@ public function __construct( ?string $systemStatus, ) { parent::__construct( + $uId, $name, $addressLine1, $addressLine2, diff --git a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php index f9fc799d77..0beba5d660 100644 --- a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php +++ b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php @@ -16,6 +16,8 @@ class LpaStoreTrustCorporations extends Person public function __construct( #[MapFrom('name')] public readonly ?string $companyName, + #[MapFrom('uid')] + ?string $uId, ?string $name, #[MapFrom('address')] #[ExtractAddressLine1FromLpaStore] @@ -31,6 +33,7 @@ public function __construct( #[ExtractTownFromLpaStore] ?string $town, ?string $type, + #[MapFrom('dateOfBirth')] ?DateTimeImmutable $dob, ?string $email, ?string $firstname, @@ -41,6 +44,7 @@ public function __construct( ?string $systemStatus, ) { parent::__construct( + $uId, $name, $addressLine1, $addressLine2, diff --git a/service-api/app/src/App/src/Entity/Person.php b/service-api/app/src/App/src/Entity/Person.php index e8d67179c4..3a3c6f8ea0 100644 --- a/service-api/app/src/App/src/Entity/Person.php +++ b/service-api/app/src/App/src/Entity/Person.php @@ -9,6 +9,7 @@ class Person { public function __construct( + public readonly ?string $uId, public readonly ?string $name, public readonly ?string $addressLine1, public readonly ?string $addressLine2, diff --git a/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php b/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php index 9ef9b9720a..29f63b9451 100644 --- a/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php +++ b/service-api/app/src/App/src/Service/Lpa/LpaDataFormatter.php @@ -4,15 +4,11 @@ namespace App\Service\Lpa; -use App\Entity\Casters\DateToStringSerializer; use App\Entity\LpaStore\LpaStore; -use DateTimeInterface; -use EventSauce\ObjectHydrator\DefaultSerializerRepository; use EventSauce\ObjectHydrator\DefinitionProvider; use EventSauce\ObjectHydrator\KeyFormatterWithoutConversion; use EventSauce\ObjectHydrator\ObjectMapperUsingReflection; use EventSauce\ObjectHydrator\UnableToHydrateObject; -use DateTimeImmutable; use EventSauce\ObjectHydrator\UnableToSerializeObject; class LpaDataFormatter @@ -27,24 +23,9 @@ public function __construct() */ public function __invoke(array $lpa) { - $defaultSerializerRepository = new DefaultSerializerRepository([ - DateTimeImmutable::class => [ - DateToStringSerializer::class, - ], - DateTimeInterface::class => [ - DateToStringSerializer::class, - ], - ]); - $defaultSerializerRepository->registerDefaultSerializer( - DateTimeImmutable::class, - DateToStringSerializer::class, - [] - ); - $mapper = new ObjectMapperUsingReflection( new DefinitionProvider( keyFormatter: new KeyFormatterWithoutConversion(), - defaultSerializerRepository: $defaultSerializerRepository ), ); diff --git a/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php b/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php index 8b0caacaac..24568603da 100644 --- a/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php +++ b/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php @@ -20,103 +20,72 @@ public function setUp(): void #[Test] public function can_serialise_datastore_lpa_to_modernise_format(): void { - $lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/test_lpa.json'), true); - - $lpa['trustCorporations'] = [ - [ - 'uid' => '1d95993a-ffbb-484c-b2fe-f4cca51801da', - 'name' => 'Trust us Corp.', - 'companyNumber' => '666123321', - 'address' => [ - 'line1' => '103 Line 1', - 'town' => 'Town', - 'country' => 'GB', - ], - 'status' => 'active', - 'channel' => 'paper', - 'signedAt' => '2024-01-10', - ], - ]; + $lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/4UX3.json'), true); $expectedLpa = [ - 'applicationHasGuidance' => false, - 'applicationHasRestrictions' => false, - 'applicationType' => 'Classic', - 'attorneyActDecisions' => null, + 'applicationHasGuidance' => null, + 'applicationHasRestrictions' => null, + 'applicationType' => null, + 'attorneyActDecisions' => 'jointly', 'attorneys' => [ - 0 => [ - 'name' => null, - 'addressLine1' => null, - 'addressLine2' => null, - 'addressLine3' => null, - 'country' => null, - 'county' => null, - 'postcode' => null, - 'town' => null, - 'type' => null, - 'dob' => null, - 'email' => '', - 'firstname' => 'jean', - 'firstnames' => null, - 'surname' => null, - 'otherNames' => null, - 'systemStatus' => null, - ], - 1 => [ + [ + 'uId' => '9ac5cb7c-fc75-40c7-8e53-059f36dbbe3d', 'name' => null, - 'addressLine1' => null, + 'addressLine1' => '81 NighOnTimeWeBuiltIt Street', 'addressLine2' => null, 'addressLine3' => null, - 'country' => null, + 'country' => 'GB', 'county' => null, 'postcode' => null, - 'town' => null, + 'town' => 'Mahhhhhhhhhh', 'type' => null, - 'dob' => null, - 'email' => 'XXXXX', - 'firstname' => 'Ann', - 'firstnames' => null, - 'surname' => null, + 'dob' => '1982-07-24 00:00:00.000000+0000', + 'email' => null, + 'firstname' => null, + 'firstnames' => 'Herman', + 'surname' => 'Seakrest', 'otherNames' => null, - 'systemStatus' => null, + 'systemStatus' => 'active', ], ], - 'caseSubtype' => null, - 'channel' => null, + 'caseSubtype' => 'hw', + 'channel' => 'online', 'dispatchDate' => null, 'donor' => [ + 'uId' => 'eda719db-8880-4dda-8c5d-bb9ea12c236f', 'name' => null, - 'addressLine1' => null, + 'addressLine1' => '74 Cloob Close', 'addressLine2' => null, 'addressLine3' => null, - 'country' => null, + 'country' => 'GB', 'county' => null, 'postcode' => null, - 'town' => null, + 'town' => 'Mahhhhhhhhhh', 'type' => null, - 'dob' => null, - 'email' => 'RachelSanderson@opgtest.com', - 'firstname' => 'Rachel', - 'firstnames' => null, - 'surname' => null, + 'dob' => '1970-01-24 00:00:00.000000+0000', + 'email' => 'nobody@not.a.real.domain', + 'firstname' => null, + 'firstnames' => 'Feeg', + 'surname' => 'Bundlaaaa', 'otherNames' => null, 'systemStatus' => null, ], 'hasSeveranceWarning' => null, 'invalidDate' => null, - 'lifeSustainingTreatment' => null, - 'lpaDonorSignatureDate' => null, - 'lpaIsCleansed' => true, - 'onlineLpaId' => 'A33718377316', - 'receiptDate' => '2014-09-26T00:00:00+00:00', - 'registrationDate' => '2019-10-10T00:00:00+00:00', + 'lifeSustainingTreatment' => 'option-a', + 'lpaDonorSignatureDate' => '2024-01-10 23:00:00.000000+0000', + 'lpaIsCleansed' => null, + 'onlineLpaId' => null, + 'receiptDate' => null, + 'registrationDate' => '2024-01-12 00:00:00.000000+0000', 'rejectedDate' => null, - 'replacementAttorneys' => [], - 'status' => 'Registered', + 'replacementAttorneys' => null, + 'status' => 'registered', 'statusDate' => null, 'trustCorporations' => [ - 0 => [ + [ 'name' => 'Trust us Corp.', + 'uId' => '1d95993a-ffbb-484c-b2fe-f4cca51801da', 'addressLine1' => '103 Line 1', 'addressLine2' => null, 'addressLine3' => null, @@ -132,10 +101,9 @@ public function can_serialise_datastore_lpa_to_modernise_format(): void 'surname' => null, 'otherNames' => null, 'systemStatus' => 'active', - 'companyName' => 'Trust us Corp.', ], ], - 'uId' => '700000000047', + 'uId' => 'M-789Q-P4DF-4UX3', 'withdrawnDate' => null, ]; diff --git a/service-api/app/test/AppTest/Entity/DateToStringSerializerTest.php b/service-api/app/test/AppTest/Entity/DateToStringSerializerTest.php deleted file mode 100644 index 89630d1610..0000000000 --- a/service-api/app/test/AppTest/Entity/DateToStringSerializerTest.php +++ /dev/null @@ -1,47 +0,0 @@ -mockHydrator = $this->createMock(ObjectMapper::class); - $this->dateToStringSerializer = new DateToStringSerializer(); - } - - #[Test] - public function can_date_to_string_serialised(): void - { - $date = new DateTimeImmutable('22-12-1997'); - - $expecteDate = '1997-12-22T00:00:00+00:00'; - - $result = $this->dateToStringSerializer->serialize($date, $this->mockHydrator); - - $this->assertEquals($expecteDate, $result); - } - - #[Test] - public function cannot_convert_date_to_string(): void - { - $date = '22-12-1997'; - - $expecteDate = '22-12-1997'; - - $result = $this->dateToStringSerializer->serialize($date, $this->mockHydrator); - - $this->assertEquals($expecteDate, $result); - } -} diff --git a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php index 5f30886c18..8768610c9d 100644 --- a/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php +++ b/service-api/app/test/AppTest/Service/Lpa/LpaServiceTest.php @@ -4,21 +4,6 @@ namespace AppTest\Service\Lpa; -use App\Entity\Casters\{ - CastSingleDonor, - CastToCaseSubtype, - CastToLifeSustainingTreatment, - CastToWhenTheLpaCanBeUsed, - DateToStringSerializer, - ExtractAddressLine1FromLpaStore, - ExtractCountryFromLpaStore, - ExtractTownFromLpaStore, -}; -use App\Entity\LpaStore\LpaStoreDonor; -use EventSauce\ObjectHydrator\DefinitionProvider; -use EventSauce\ObjectHydrator\KeyFormatterWithoutConversion; -use EventSauce\ObjectHydrator\ObjectMapper; -use EventSauce\ObjectHydrator\ObjectMapperUsingReflection; use App\DataAccess\{Repository\InstructionsAndPreferencesImagesInterface, Repository\LpasInterface, Repository\UserLpaActorMapInterface, @@ -29,7 +14,6 @@ use App\Service\Lpa\{GetAttorneyStatus, GetTrustCorporationStatus, IsValidLpa, - LpaDataFormatter, LpaService, ResolveActor}; use DateInterval; @@ -58,8 +42,6 @@ class LpaServiceTest extends TestCase private GetTrustCorporationStatus|ObjectProphecy $getTrustCorporationStatusProphecy; private FeatureEnabled|ObjectProphecy $featureEnabledProphecy; private LoggerInterface|ObjectProphecy $loggerProphecy; - private LpaDataFormatter $lpaDataFormatter; - private ObjectMapper|ObjectProphecy $hydrator; public function setUp(): void { @@ -75,8 +57,6 @@ public function setUp(): void $this->getTrustCorporationStatusProphecy = $this->prophesize(GetTrustCorporationStatus::class); $this->featureEnabledProphecy = $this->prophesize(FeatureEnabled::class); $this->loggerProphecy = $this->prophesize(LoggerInterface::class); - $this->hydrator = $this->prophesize(ObjectMapper::class); - $this->lpaDataFormatter = new LpaDataFormatter(); } private function getLpaService(): LpaService diff --git a/service-api/app/test/fixtures/4UX3.json b/service-api/app/test/fixtures/4UX3.json new file mode 100644 index 0000000000..f1d5e0397b --- /dev/null +++ b/service-api/app/test/fixtures/4UX3.json @@ -0,0 +1,78 @@ +{ + "uid": "M-789Q-P4DF-4UX3", + "status": "registered", + "registrationDate": "2024-01-12", + "updatedAt": "2024-01-12T23:00:00Z", + "lpaType": "personal-welfare", + "channel": "online", + "donor": { + "uid": "eda719db-8880-4dda-8c5d-bb9ea12c236f", + "firstNames": "Feeg", + "lastName": "Bundlaaaa", + "address": { + "line1": "74 Cloob Close", + "town": "Mahhhhhhhhhh", + "country": "GB" + }, + "dateOfBirth": "1970-01-24", + "email": "nobody@not.a.real.domain", + "contactLanguagePreference": "en", + "identityCheck": { + "checkedAt": "2024-01-10T23:00:00Z", + "type": "one-login" + } + }, + "attorneys": [ + { + "uid": "9ac5cb7c-fc75-40c7-8e53-059f36dbbe3d", + "firstNames": "Herman", + "lastName": "Seakrest", + "address": { + "line1": "81 NighOnTimeWeBuiltIt Street", + "town": "Mahhhhhhhhhh", + "country": "GB" + }, + "dateOfBirth": "1982-07-24", + "status": "active", + "channel": "paper", + "signedAt": "2024-01-10T23:00:00Z" + } + ], + "trustCorporations": [ + { + "uid": "1d95993a-ffbb-484c-b2fe-f4cca51801da", + "name": "Trust us Corp.", + "companyNumber": "666123321", + "address": { + "line1": "103 Line 1", + "town": "Town", + "country": "GB" + }, + "status": "active", + "channel": "paper", + "signedAt": "2024-01-10T23:00:00Z" + } + ], + "certificateProvider": { + "uid": "6808960d-12cf-47c5-a2bc-3177deb8599c", + "firstNames": "Vone", + "lastName": "Spust", + "address": { + "line1": "122111 Zonnington Way", + "town": "Mahhhhhhhhhh", + "country": "GB" + }, + "channel": "online", + "email": "a@example.com", + "phone": "070009000", + "signedAt": "2024-01-10T23:00:00Z", + "identityCheck": { + "checkedAt": "2024-01-10T23:00:00Z", + "type": "one-login" + } + }, + "lifeSustainingTreatmentOption": "option-a", + "signedAt": "2024-01-10T23:00:00Z", + "howAttorneysMakeDecisions": "jointly", + "whenTheLpaCanBeUsed": "when-capacity-lost" +} From f178773abc1183c2e853a0a33c597a27544b1e8e Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Thu, 5 Sep 2024 10:11:34 +0100 Subject: [PATCH 18/20] UML-3460 fixed test - CastSingleDonorTest.php --- service-api/app/test/AppTest/Entity/CastSingleDonorTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php b/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php index 1c85933683..23839f00f4 100644 --- a/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php +++ b/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php @@ -28,7 +28,7 @@ public function setUp(): void public function can_cast_single_donor(): void { $donor = [ - 'uId' => '700000000971', + 'uid' => 'eda719db-8880-4dda-8c5d-bb9ea12c236f', 'firstNames' => 'Feeg', 'surname' => 'Gilson', 'lastName' => 'Bundlaaaa', @@ -43,6 +43,7 @@ public function can_cast_single_donor(): void ]; $expectedDatastoreDonor = new LpaStoreDonor( + 'eda719db-8880-4dda-8c5d-bb9ea12c236f', null, '74 Cloob Close', null, From c5d6cc8d432564170171dff5a14e8b20a6edc76e Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Tue, 10 Sep 2024 14:09:29 +0100 Subject: [PATCH 19/20] UML-3460 updated properties to alphabetic --- .../src/Entity/LpaStore/LpaStoreAttorney.php | 32 ++++++++-------- .../App/src/Entity/LpaStore/LpaStoreDonor.php | 32 ++++++++-------- .../LpaStore/LpaStoreTrustCorporations.php | 37 ++++++++++--------- service-api/app/src/App/src/Entity/Person.php | 12 +++--- ...SerialiseLpaStoreToModerniseFormatTest.php | 34 ++++++++--------- .../AppTest/Entity/CastSingleDonorTest.php | 10 ++--- 6 files changed, 79 insertions(+), 78 deletions(-) diff --git a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php index a82bafcbb3..8687cc697f 100644 --- a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php +++ b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreAttorney.php @@ -14,9 +14,6 @@ class LpaStoreAttorney extends Person { public function __construct( - #[MapFrom('uid')] - ?string $uId, - ?string $name, #[MapFrom('address')] #[ExtractAddressLine1FromLpaStore] ?string $addressLine1, @@ -26,11 +23,6 @@ public function __construct( #[ExtractCountryFromLpaStore] ?string $country, ?string $county, - ?string $postcode, - #[MapFrom('address')] - #[ExtractTownFromLpaStore] - ?string $town, - ?string $type, #[MapFrom('dateOfBirth')] ?DateTimeImmutable $dob, ?string $email, @@ -38,30 +30,38 @@ public function __construct( ?string $firstname, #[MapFrom('firstNames')] ?string $firstnames, + ?string $name, + ?string $otherNames, + ?string $postcode, #[MapFrom('lastName')] ?string $surname, - ?string $otherNames, #[MapFrom('status')] ?string $systemStatus, + #[MapFrom('address')] + #[ExtractTownFromLpaStore] + ?string $town, + ?string $type, + #[MapFrom('uid')] + ?string $uId, ) { parent::__construct( - $uId, - $name, $addressLine1, $addressLine2, $addressLine3, $country, $county, - $postcode, - $town, - $type, $dob, $email, $firstname, $firstnames, - $surname, + $name, $otherNames, - $systemStatus + $postcode, + $surname, + $systemStatus, + $town, + $type, + $uId, ); } } diff --git a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreDonor.php b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreDonor.php index 297b4202cd..f5d37be95d 100644 --- a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreDonor.php +++ b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreDonor.php @@ -14,9 +14,6 @@ class LpaStoreDonor extends Person { public function __construct( - #[MapFrom('uid')] - ?string $uId, - ?string $name, #[MapFrom('address')] #[ExtractAddressLine1FromLpaStore] ?string $addressLine1, @@ -26,41 +23,44 @@ public function __construct( #[ExtractCountryFromLpaStore] ?string $country, ?string $county, - ?string $postcode, - #[MapFrom('address')] - #[ExtractTownFromLpaStore] - ?string $town, - ?string $type, #[MapFrom('dateOfBirth')] ?DateTimeImmutable $dob, ?string $email, ?string $firstname, #[MapFrom('firstNames')] ?string $firstnames, + ?string $name, + ?string $otherNames, + ?string $postcode, #[MapFrom('lastName')] ?string $surname, - ?string $otherNames, #[MapFrom('status')] ?string $systemStatus, + #[MapFrom('address')] + #[ExtractTownFromLpaStore] + ?string $town, + ?string $type, + #[MapFrom('uid')] + ?string $uId, ) { parent::__construct( - $uId, - $name, $addressLine1, $addressLine2, $addressLine3, $country, $county, - $postcode, - $town, - $type, $dob, $email, $firstname, $firstnames, - $surname, + $name, $otherNames, - $systemStatus + $postcode, + $surname, + $systemStatus, + $town, + $type, + $uId, ); } } diff --git a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php index 0beba5d660..0b3c9a9172 100644 --- a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php +++ b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php @@ -14,53 +14,54 @@ class LpaStoreTrustCorporations extends Person { public function __construct( - #[MapFrom('name')] - public readonly ?string $companyName, - #[MapFrom('uid')] - ?string $uId, - ?string $name, + #[MapFrom('address')] #[ExtractAddressLine1FromLpaStore] ?string $addressLine1, ?string $addressLine2, ?string $addressLine3, + #[MapFrom('name')] + public readonly ?string $companyName, #[MapFrom('address')] #[ExtractCountryFromLpaStore] ?string $country, ?string $county, - ?string $postcode, - #[MapFrom('address')] - #[ExtractTownFromLpaStore] - ?string $town, - ?string $type, #[MapFrom('dateOfBirth')] ?DateTimeImmutable $dob, ?string $email, ?string $firstname, ?string $firstnames, - ?string $surname, + ?string $name, ?string $otherNames, + ?string $postcode, + ?string $surname, #[MapFrom('status')] ?string $systemStatus, + #[MapFrom('address')] + #[ExtractTownFromLpaStore] + ?string $town, + ?string $type, + #[MapFrom('uid')] + ?string $uId, ) { parent::__construct( - $uId, - $name, $addressLine1, $addressLine2, $addressLine3, $country, $county, - $postcode, - $town, - $type, $dob, $email, $firstname, $firstnames, - $surname, + $name, $otherNames, - $systemStatus + $postcode, + $surname, + $systemStatus, + $town, + $type, + $uId, ); } } diff --git a/service-api/app/src/App/src/Entity/Person.php b/service-api/app/src/App/src/Entity/Person.php index 3a3c6f8ea0..47b9fb4182 100644 --- a/service-api/app/src/App/src/Entity/Person.php +++ b/service-api/app/src/App/src/Entity/Person.php @@ -9,23 +9,23 @@ class Person { public function __construct( - public readonly ?string $uId, - public readonly ?string $name, public readonly ?string $addressLine1, public readonly ?string $addressLine2, public readonly ?string $addressLine3, public readonly ?string $country, public readonly ?string $county, - public readonly ?string $postcode, - public readonly ?string $town, - public readonly ?string $type, public readonly ?DateTimeImmutable $dob, public readonly ?string $email, public readonly ?string $firstname, public readonly ?string $firstnames, - public readonly ?string $surname, + public readonly ?string $name, public readonly ?string $otherNames, + public readonly ?string $postcode, + public readonly ?string $surname, public readonly ?string $systemStatus, + public readonly ?string $town, + public readonly ?string $type, + public readonly ?string $uId, ) { } } diff --git a/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php b/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php index 24568603da..31c9500c8e 100644 --- a/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php +++ b/service-api/app/test/AppTest/Entity/CanSerialiseLpaStoreToModerniseFormatTest.php @@ -29,46 +29,46 @@ public function can_serialise_datastore_lpa_to_modernise_format(): void 'attorneyActDecisions' => 'jointly', 'attorneys' => [ [ - 'uId' => '9ac5cb7c-fc75-40c7-8e53-059f36dbbe3d', - 'name' => null, 'addressLine1' => '81 NighOnTimeWeBuiltIt Street', 'addressLine2' => null, 'addressLine3' => null, 'country' => 'GB', 'county' => null, - 'postcode' => null, - 'town' => 'Mahhhhhhhhhh', - 'type' => null, 'dob' => '1982-07-24 00:00:00.000000+0000', 'email' => null, 'firstname' => null, 'firstnames' => 'Herman', - 'surname' => 'Seakrest', + 'name' => null, 'otherNames' => null, + 'postcode' => null, + 'surname' => 'Seakrest', 'systemStatus' => 'active', + 'town' => 'Mahhhhhhhhhh', + 'type' => null, + 'uId' => '9ac5cb7c-fc75-40c7-8e53-059f36dbbe3d', ], ], 'caseSubtype' => 'hw', 'channel' => 'online', 'dispatchDate' => null, 'donor' => [ - 'uId' => 'eda719db-8880-4dda-8c5d-bb9ea12c236f', - 'name' => null, 'addressLine1' => '74 Cloob Close', 'addressLine2' => null, 'addressLine3' => null, 'country' => 'GB', 'county' => null, - 'postcode' => null, - 'town' => 'Mahhhhhhhhhh', - 'type' => null, 'dob' => '1970-01-24 00:00:00.000000+0000', 'email' => 'nobody@not.a.real.domain', 'firstname' => null, 'firstnames' => 'Feeg', - 'surname' => 'Bundlaaaa', + 'name' => null, 'otherNames' => null, + 'postcode' => null, + 'surname' => 'Bundlaaaa', 'systemStatus' => null, + 'town' => 'Mahhhhhhhhhh', + 'type' => null, + 'uId' => 'eda719db-8880-4dda-8c5d-bb9ea12c236f', ], 'hasSeveranceWarning' => null, 'invalidDate' => null, @@ -85,22 +85,22 @@ public function can_serialise_datastore_lpa_to_modernise_format(): void 'trustCorporations' => [ [ 'name' => 'Trust us Corp.', - 'uId' => '1d95993a-ffbb-484c-b2fe-f4cca51801da', 'addressLine1' => '103 Line 1', 'addressLine2' => null, 'addressLine3' => null, 'country' => 'GB', 'county' => null, - 'postcode' => null, - 'town' => 'Town', - 'type' => null, 'dob' => null, 'email' => null, 'firstname' => null, 'firstnames' => null, - 'surname' => null, 'otherNames' => null, + 'postcode' => null, + 'surname' => null, 'systemStatus' => 'active', + 'town' => 'Town', + 'type' => null, + 'uId' => '1d95993a-ffbb-484c-b2fe-f4cca51801da', ], ], 'uId' => 'M-789Q-P4DF-4UX3', diff --git a/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php b/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php index 23839f00f4..572a94bdea 100644 --- a/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php +++ b/service-api/app/test/AppTest/Entity/CastSingleDonorTest.php @@ -43,23 +43,23 @@ public function can_cast_single_donor(): void ]; $expectedDatastoreDonor = new LpaStoreDonor( - 'eda719db-8880-4dda-8c5d-bb9ea12c236f', - null, '74 Cloob Close', null, null, 'GB', null, - null, - 'Mahhhhhhhhhh', - null, new DateTimeImmutable('1970-01-24 00:00:00.000000'), 'nobody@not.a.real.domain', null, 'Feeg', + null, + null, + null, 'Bundlaaaa', null, + 'Mahhhhhhhhhh', null, + 'eda719db-8880-4dda-8c5d-bb9ea12c236f', ); $mapper = new ObjectMapperUsingReflection( From 3dfdc32984208d6a05ba3c16dacca0ed1319b6d0 Mon Sep 17 00:00:00 2001 From: Allen Annom Date: Tue, 10 Sep 2024 14:51:10 +0100 Subject: [PATCH 20/20] UML-3460 lint error --- .../src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php | 1 - 1 file changed, 1 deletion(-) diff --git a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php index 0b3c9a9172..6d077092c7 100644 --- a/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php +++ b/service-api/app/src/App/src/Entity/LpaStore/LpaStoreTrustCorporations.php @@ -14,7 +14,6 @@ class LpaStoreTrustCorporations extends Person { public function __construct( - #[MapFrom('address')] #[ExtractAddressLine1FromLpaStore] ?string $addressLine1,