mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-26 08:35:00 +00:00
Add personId
serialization to PersonJsonNormalizer
- Inject `PersonIdRenderingInterface` into `PersonJsonNormalizer` for generating `personId`. - Update `PersonJsonNormalizer` to include `personId` in serialized output. - Extend TypeScript definitions to support `personId` property. - Enhance unit tests to cover `personId` serialization.
This commit is contained in:
@@ -50,6 +50,10 @@ export interface Person {
|
|||||||
civility: Civility | null;
|
civility: Civility | null;
|
||||||
current_household_id: number;
|
current_household_id: number;
|
||||||
current_residential_addresses: Address[];
|
current_residential_addresses: Address[];
|
||||||
|
/**
|
||||||
|
* The person id as configured by the user
|
||||||
|
*/
|
||||||
|
personId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PersonIdentifierWrite {
|
export interface PersonIdentifierWrite {
|
||||||
|
@@ -35,6 +35,7 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf
|
|||||||
private readonly CenterResolverManagerInterface $centerResolverManager,
|
private readonly CenterResolverManagerInterface $centerResolverManager,
|
||||||
private readonly ResidentialAddressRepository $residentialAddressRepository,
|
private readonly ResidentialAddressRepository $residentialAddressRepository,
|
||||||
private readonly PhoneNumberHelperInterface $phoneNumberHelper,
|
private readonly PhoneNumberHelperInterface $phoneNumberHelper,
|
||||||
|
private readonly \Chill\PersonBundle\PersonIdentifier\Rendering\PersonIdRenderingInterface $personIdRendering,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,6 +68,7 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf
|
|||||||
'email' => $person->getEmail(),
|
'email' => $person->getEmail(),
|
||||||
'gender' => $this->normalizer->normalize($person->getGender(), $format, $context),
|
'gender' => $this->normalizer->normalize($person->getGender(), $format, $context),
|
||||||
'civility' => $this->normalizer->normalize($person->getCivility(), $format, $context),
|
'civility' => $this->normalizer->normalize($person->getCivility(), $format, $context),
|
||||||
|
'personId' => $this->personIdRendering->renderPersonId($person),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (\in_array('minimal', $groups, true) && 1 === \count($groups)) {
|
if (\in_array('minimal', $groups, true) && 1 === \count($groups)) {
|
||||||
|
@@ -19,6 +19,7 @@ use Chill\PersonBundle\Entity\Person;
|
|||||||
use Chill\PersonBundle\Entity\PersonAltName;
|
use Chill\PersonBundle\Entity\PersonAltName;
|
||||||
use Chill\PersonBundle\Repository\ResidentialAddressRepository;
|
use Chill\PersonBundle\Repository\ResidentialAddressRepository;
|
||||||
use Chill\PersonBundle\Serializer\Normalizer\PersonJsonNormalizer;
|
use Chill\PersonBundle\Serializer\Normalizer\PersonJsonNormalizer;
|
||||||
|
use Chill\PersonBundle\PersonIdentifier\Rendering\PersonIdRenderingInterface;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\Argument;
|
use Prophecy\Argument;
|
||||||
@@ -68,11 +69,13 @@ final class PersonJsonNormalizerTest extends TestCase
|
|||||||
'email',
|
'email',
|
||||||
'gender',
|
'gender',
|
||||||
'civility',
|
'civility',
|
||||||
|
'personId',
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($expectedKeys as $key) {
|
foreach ($expectedKeys as $key) {
|
||||||
self::assertArrayHasKey($key, $data, sprintf('Key %s should be present', $key));
|
self::assertArrayHasKey($key, $data, sprintf('Key %s should be present', $key));
|
||||||
}
|
}
|
||||||
|
self::assertSame('PERSON-ID-RENDER', $data['personId']);
|
||||||
|
|
||||||
// Ensure extended keys are not present in minimal mode
|
// Ensure extended keys are not present in minimal mode
|
||||||
foreach (['centers', 'altNames', 'current_household_id', 'current_residential_addresses'] as $key) {
|
foreach (['centers', 'altNames', 'current_household_id', 'current_residential_addresses'] as $key) {
|
||||||
@@ -97,7 +100,7 @@ final class PersonJsonNormalizerTest extends TestCase
|
|||||||
|
|
||||||
// Base keys
|
// Base keys
|
||||||
$baseKeys = [
|
$baseKeys = [
|
||||||
'type', 'id', 'text', 'textAge', 'firstName', 'lastName', 'current_household_address', 'birthdate', 'deathdate', 'age', 'phonenumber', 'mobilenumber', 'email', 'gender', 'civility',
|
'type', 'id', 'text', 'textAge', 'firstName', 'lastName', 'current_household_address', 'birthdate', 'deathdate', 'age', 'phonenumber', 'mobilenumber', 'email', 'gender', 'civility', 'personId',
|
||||||
];
|
];
|
||||||
foreach ($baseKeys as $key) {
|
foreach ($baseKeys as $key) {
|
||||||
self::assertArrayHasKey($key, $data, sprintf('Key %s should be present', $key));
|
self::assertArrayHasKey($key, $data, sprintf('Key %s should be present', $key));
|
||||||
@@ -129,11 +132,15 @@ final class PersonJsonNormalizerTest extends TestCase
|
|||||||
|
|
||||||
$phoneHelper = $this->prophesize(PhoneNumberHelperInterface::class);
|
$phoneHelper = $this->prophesize(PhoneNumberHelperInterface::class);
|
||||||
|
|
||||||
|
$personIdRendering = $this->prophesize(PersonIdRenderingInterface::class);
|
||||||
|
$personIdRendering->renderPersonId(Argument::type(Person::class))->willReturn('PERSON-ID-RENDER');
|
||||||
|
|
||||||
$normalizer = new PersonJsonNormalizer(
|
$normalizer = new PersonJsonNormalizer(
|
||||||
$render->reveal(),
|
$render->reveal(),
|
||||||
$centerResolver->reveal(),
|
$centerResolver->reveal(),
|
||||||
$raRepo->reveal(),
|
$raRepo->reveal(),
|
||||||
$phoneHelper->reveal(),
|
$phoneHelper->reveal(),
|
||||||
|
$personIdRendering->reveal(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Inner normalizer that echoes values or simple conversions
|
// Inner normalizer that echoes values or simple conversions
|
||||||
|
Reference in New Issue
Block a user