Skip to content

Commit

Permalink
Merge pull request #1887 from cultuurnet/III-6396/Description-should-…
Browse files Browse the repository at this point in the history
…not-be-empty

III-6396 BUGFIX description should not be empty
  • Loading branch information
grubolsch authored Nov 15, 2024
2 parents c5fa6f5 + 41520ae commit aa6e7c0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/BackwardsCompatiblePayloadSerializerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use CultuurNet\UDB3\Event\Events\BookingInfoUpdated as EventBookingInfoUpdated;
use CultuurNet\UDB3\Event\Events\ContactPointUpdated as EventContactPointUpdated;
use CultuurNet\UDB3\Event\Events\DescriptionTranslated;
use CultuurNet\UDB3\Event\Events\DescriptionUpdated as EventDescriptionUpdated;
use CultuurNet\UDB3\Event\Events\EventDeleted;
use CultuurNet\UDB3\Event\Events\EventImportedFromUDB2;
use CultuurNet\UDB3\Event\Events\LabelAdded;
Expand All @@ -27,6 +26,7 @@
use CultuurNet\UDB3\Model\ValueObject\Identity\UUID;
use CultuurNet\UDB3\Place\Events\BookingInfoUpdated as PlaceBookingInfoUpdated;
use CultuurNet\UDB3\Place\Events\ContactPointUpdated as PlaceContactPointUpdated;
use CultuurNet\UDB3\Event\Events\DescriptionUpdated as EventDescriptionUpdated;
use CultuurNet\UDB3\Place\Events\DescriptionUpdated as PlaceDescriptionUpdated;
use CultuurNet\UDB3\Place\Events\OrganizerDeleted as PlaceOrganizerDeleted;
use CultuurNet\UDB3\Place\Events\OrganizerUpdated as PlaceOrganizerUpdated;
Expand Down Expand Up @@ -330,7 +330,6 @@ function (array $serializedObject) {
EventTypicalAgeRangeUpdated::class,
EventOrganizerUpdated::class,
EventOrganizerDeleted::class,
EventDescriptionUpdated::class,
EventDeleted::class,
];

Expand All @@ -351,7 +350,6 @@ function (array $serializedObject) {
PlaceOrganizerDeleted::class,
PlaceTypicalAgeRangeDeleted::class,
PlaceTypicalAgeRangeUpdated::class,
PlaceDescriptionUpdated::class,
PlaceDeleted::class,
];

Expand Down Expand Up @@ -420,6 +418,25 @@ function (array $serializedObject) use ($contactPointUpdatedEvent) {
);
}

$updateDescriptionEvents = [
EventDescriptionUpdated::class,
PlaceDescriptionUpdated::class,
];

foreach ($updateDescriptionEvents as $descriptionUpdatedEvent) {
$payloadManipulatingSerializer->manipulateEventsOfClass(
$descriptionUpdatedEvent,
function (array $serializedObject) use ($descriptionUpdatedEvent) {
$serializedObject = self::fillDescriptions($serializedObject);

if ($descriptionUpdatedEvent === EventDescriptionUpdated::class) {
return self::replaceEventIdWithItemId($serializedObject);
}
return self::replacePlaceIdWithItemId($serializedObject);
}
);
}

/**
* Roles
*/
Expand Down Expand Up @@ -535,4 +552,12 @@ private static function addDefaultMainLanguage(array $serializedObject): array

return $serializedObject;
}

private static function fillDescriptions(array $serializedObject): array
{
if (empty(trim($serializedObject['payload']['description']))) {
$serializedObject['payload']['description'] = '---';
}
return $serializedObject;
}
}
59 changes: 59 additions & 0 deletions tests/BackwardsCompatiblePayloadSerializerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
use CultuurNet\UDB3\Model\ValueObject\Contact\TelephoneNumber;
use CultuurNet\UDB3\Model\ValueObject\Contact\TelephoneNumbers;
use CultuurNet\UDB3\Model\ValueObject\Identity\UUID;
use CultuurNet\UDB3\Model\ValueObject\Text\Description;
use CultuurNet\UDB3\Model\ValueObject\Web\EmailAddress;
use CultuurNet\UDB3\Model\ValueObject\Web\EmailAddresses;
use CultuurNet\UDB3\Model\ValueObject\Web\Url;
use CultuurNet\UDB3\Model\ValueObject\Web\Urls;
use CultuurNet\UDB3\Offer\Events\AbstractDescriptionUpdated;
use CultuurNet\UDB3\Offer\Events\AbstractLabelEvent;
use CultuurNet\UDB3\Organizer\Events\OrganizerCreatedWithUniqueWebsite;
use CultuurNet\UDB3\Place\Events\PlaceCreated;
Expand All @@ -42,6 +44,8 @@
use Money\Money;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use CultuurNet\UDB3\Event\Events\DescriptionUpdated as EventDescriptionUpdated;
use CultuurNet\UDB3\Place\Events\DescriptionUpdated as PlaceDescriptionUpdated;

class BackwardsCompatiblePayloadSerializerFactoryTest extends TestCase
{
Expand Down Expand Up @@ -760,4 +764,59 @@ private function assertOrganizerLabelEventFixed(string $sampleFile): void
$this->assertEquals('2dotstwice', $labelEvent->getLabelName());
$this->assertFalse($labelEvent->isLabelVisible());
}

/**
* @test
* @dataProvider emptyDescriptionsDataProvider
*/
public function it_fills_empty_descriptions(AbstractDescriptionUpdated $expectedEvent, string $serialized): void
{
$decoded = Json::decodeAssociatively($serialized);

$event = $this->serializer->deserialize($decoded);
$this->assertInstanceOf(AbstractDescriptionUpdated::class, $event);

$this->assertEquals($expectedEvent->getDescription(), $event->getDescription());
}

public static function emptyDescriptionsDataProvider(): array
{
return [
'Fill empty event description' => [
new EventDescriptionUpdated(
'9c6145c5-4a53-4c36-b51b-3ccef8a1507c',
new Description('---')
),
'{"class":"CultuurNet\\\\UDB3\\\\Event\\\\Events\\\\DescriptionUpdated","payload":{"item_id":"9c6145c5-4a53-4c36-b51b-3ccef8a1507c","description":""}}',
],
'Do not fill event with existing description' => [
new EventDescriptionUpdated(
'9c6145c5-4a53-4c36-b51b-3ccef8a1507c',
new Description('Lorum ipsum')
),
'{"class":"CultuurNet\\\\UDB3\\\\Event\\\\Events\\\\DescriptionUpdated","payload":{"item_id":"9c6145c5-4a53-4c36-b51b-3ccef8a1507c","description":"Lorum ipsum"}}',
],
'Fill empty place description' => [
new PlaceDescriptionUpdated(
'9c6145c5-4a53-4c36-b51b-3ccef8a1507c',
new Description('---')
),
'{"class":"CultuurNet\\\\UDB3\\\\Place\\\\Events\\\\DescriptionUpdated","payload":{"item_id":"9c6145c5-4a53-4c36-b51b-3ccef8a1507c","description":""}}',
],
'Do not fill place with existing description' => [
new PlaceDescriptionUpdated(
'9c6145c5-4a53-4c36-b51b-3ccef8a1507c',
new Description('Lorum ipsum')
),
'{"class":"CultuurNet\\\\UDB3\\\\Place\\\\Events\\\\DescriptionUpdated","payload":{"item_id":"9c6145c5-4a53-4c36-b51b-3ccef8a1507c","description":"Lorum ipsum"}}',
],
'Take into account spaces in the description' => [
new PlaceDescriptionUpdated(
'9c6145c5-4a53-4c36-b51b-3ccef8a1507c',
new Description('---')
),
'{"class":"CultuurNet\\\\UDB3\\\\Place\\\\Events\\\\DescriptionUpdated","payload":{"item_id":"9c6145c5-4a53-4c36-b51b-3ccef8a1507c","description":" "}}',
],
];
}
}

0 comments on commit aa6e7c0

Please sign in to comment.