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:
2025-09-25 15:00:11 +02:00
parent d42a1296c4
commit bfbde078b7
3 changed files with 14 additions and 1 deletions

View File

@@ -50,6 +50,10 @@ export interface Person {
civility: Civility | null;
current_household_id: number;
current_residential_addresses: Address[];
/**
* The person id as configured by the user
*/
personId: string;
}
export interface PersonIdentifierWrite {

View File

@@ -35,6 +35,7 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf
private readonly CenterResolverManagerInterface $centerResolverManager,
private readonly ResidentialAddressRepository $residentialAddressRepository,
private readonly PhoneNumberHelperInterface $phoneNumberHelper,
private readonly \Chill\PersonBundle\PersonIdentifier\Rendering\PersonIdRenderingInterface $personIdRendering,
) {}
/**
@@ -67,6 +68,7 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf
'email' => $person->getEmail(),
'gender' => $this->normalizer->normalize($person->getGender(), $format, $context),
'civility' => $this->normalizer->normalize($person->getCivility(), $format, $context),
'personId' => $this->personIdRendering->renderPersonId($person),
];
if (\in_array('minimal', $groups, true) && 1 === \count($groups)) {

View File

@@ -19,6 +19,7 @@ use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\PersonAltName;
use Chill\PersonBundle\Repository\ResidentialAddressRepository;
use Chill\PersonBundle\Serializer\Normalizer\PersonJsonNormalizer;
use Chill\PersonBundle\PersonIdentifier\Rendering\PersonIdRenderingInterface;
use Doctrine\Common\Collections\ArrayCollection;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
@@ -68,11 +69,13 @@ final class PersonJsonNormalizerTest extends TestCase
'email',
'gender',
'civility',
'personId',
];
foreach ($expectedKeys as $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
foreach (['centers', 'altNames', 'current_household_id', 'current_residential_addresses'] as $key) {
@@ -97,7 +100,7 @@ final class PersonJsonNormalizerTest extends TestCase
// Base keys
$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) {
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);
$personIdRendering = $this->prophesize(PersonIdRenderingInterface::class);
$personIdRendering->renderPersonId(Argument::type(Person::class))->willReturn('PERSON-ID-RENDER');
$normalizer = new PersonJsonNormalizer(
$render->reveal(),
$centerResolver->reveal(),
$raRepo->reveal(),
$phoneHelper->reveal(),
$personIdRendering->reveal(),
);
// Inner normalizer that echoes values or simple conversions