Skip to content

Commit

Permalink
Revert map_floors key for level LL [MA-157]
Browse files Browse the repository at this point in the history
  • Loading branch information
zachgarwood committed Feb 21, 2024
1 parent 78e90b0 commit ef0f680
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/Models/Transformers/FloorTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class FloorTransformer extends TransformerAbstract
public function transform(TwillModelContract $floor)
{
$floorPlan = $floor->fileObject('floor_plan');
// For backward compatibility, the key for level LL must be 'map_floor0'.
$mapFloor = $floor->level == 'LL' ? '0' : $floor->level;
return [
"map_floor$floor->level" => [
"map_floor$mapFloor" => [
'label' => $floor->level,
'floor_plan' => $floorPlan ? secure_url('storage/uploads/' . $floorPlan?->uuid) : null,
'anchor_pixel_1' => Floor::ANCHOR_PIXELS[0],
Expand Down
10 changes: 9 additions & 1 deletion tests/Feature/FloorSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ public function test_serialize(): void
$this->assertArrayHasKey('map_floors', $serialized);
foreach ($serialized['map_floors'] as $id => $floor) {
$this->assertStringStartsWith('map_floor', $id);
$this->assertStringEndsWith($floor['label'], $id);
if ($floor['label'] == 'LL') {
$this->assertStringEndsWith(
'0',
$id,
'For backward compatibility, the key for level LL must end in "0"'
);
} else {
$this->assertStringEndsWith($floor['label'], $id);
}
$this->assertArrayHasKey('label', $floor);
$this->assertArrayHasKey('floor_plan', $floor);
$this->assertArrayHasKey('anchor_pixel_1', $floor);
Expand Down

0 comments on commit ef0f680

Please sign in to comment.