Skip to content

Commit

Permalink
[Fix] Hydrating snapshots for document download (#11540)
Browse files Browse the repository at this point in the history
* improve localized enum assertion

* add empty string regression test

(cherry picked from commit e166554)
  • Loading branch information
esizer authored and brindasasi committed Sep 18, 2024
1 parent 3cafeb6 commit eb5b553
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/app/Traits/HydratesSnapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ abstract public static function hydrateSnapshot(mixed $snapshot): Model|array;

public static function isFieldLocalizedEnum(mixed $snapshot, mixed $snapshotField): bool
{
if (! isset($snapshot[$snapshotField]) || is_string($snapshot[$snapshotField])) {
return false;
}

// validator for a single localized enum
$singleEnumValidator = Validator::make($snapshot, [
$snapshotField.'.value' => 'required|string',
Expand Down
13 changes: 13 additions & 0 deletions api/tests/Feature/SnapshotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ public function testLocalizingLegacyEnums()
),
],
],
// Empty string details
// NOTE: Regression test for empty strings treated as localized enums
'experiences' => [
[
'details' => '',
],
],
],
]);

Expand All @@ -235,6 +242,12 @@ public function testLocalizingLegacyEnums()
'label' => OperationalRequirement::localizedString(OperationalRequirement::ON_CALL->name),
],
],
// Empty string details
'experiences' => [
[
'details' => '',
],
],
], $snapshot);
}
}

0 comments on commit eb5b553

Please sign in to comment.