fix: ensure mutability is accounted for when restoring drafts
addresses #869cdzmkq
This commit is contained in:
@@ -84,6 +84,7 @@ class BookingEditDraftServiceMutabilityTest extends TestCase
|
||||
$this->assertSame([], $participant->rentals);
|
||||
$this->assertNull($participant->skiPass);
|
||||
$this->assertNull($participant->rentalInsurance);
|
||||
$this->assertTrue($this->service->hadImmutableSkips());
|
||||
}
|
||||
|
||||
public function testDraftAppliesAdditionalServicesWhenMutable(): void
|
||||
@@ -122,8 +123,11 @@ class BookingEditDraftServiceMutabilityTest extends TestCase
|
||||
$this->assertSame(99, $participant->additionalServices[0]->id);
|
||||
$this->assertCount(1, $participant->courses);
|
||||
$this->assertSame(99, $participant->courses[0]->id);
|
||||
$this->assertNotNull($participant->skiPass);
|
||||
$this->assertSame(99, $participant->skiPass->id);
|
||||
$this->assertInstanceOf(Service::class, $participant->skiPass);
|
||||
$skiPass = $participant->skiPass;
|
||||
$this->assertNotNull($skiPass);
|
||||
$this->assertSame(99, $skiPass?->id);
|
||||
$this->assertFalse($this->service->hadImmutableSkips());
|
||||
}
|
||||
|
||||
// --- Transportation Mutability ---
|
||||
@@ -167,6 +171,7 @@ class BookingEditDraftServiceMutabilityTest extends TestCase
|
||||
$this->assertSame($originalOutbound, $participant->transportationOutbound);
|
||||
$this->assertSame($originalInbound, $participant->transportationInbound);
|
||||
$this->assertFalse($participant->parking);
|
||||
$this->assertTrue($this->service->hadImmutableSkips());
|
||||
}
|
||||
|
||||
public function testDraftAppliesTransportationWhenMutable(): void
|
||||
@@ -237,6 +242,7 @@ class BookingEditDraftServiceMutabilityTest extends TestCase
|
||||
$this->assertSame($originalPickup, $participant->pickup);
|
||||
$this->assertNull($participant->dropOff);
|
||||
$this->assertFalse($participant->differentDropOff);
|
||||
$this->assertTrue($this->service->hadImmutableSkips());
|
||||
}
|
||||
|
||||
public function testDraftAppliesPickupsWhenMutable(): void
|
||||
@@ -347,11 +353,12 @@ class BookingEditDraftServiceMutabilityTest extends TestCase
|
||||
|
||||
// Pickups: mutable → draft applied
|
||||
$this->assertSame($draftPickup, $participant->pickup);
|
||||
$this->assertTrue($this->service->hadImmutableSkips());
|
||||
}
|
||||
|
||||
// --- Personal data is always applied regardless of mutability ---
|
||||
// --- Personal data draft restore respects edit mutability rules ---
|
||||
|
||||
public function testDraftAlwaysAppliesPersonalDataRegardlessOfMutability(): void
|
||||
public function testDraftSkipsPersonalDataForFirstParticipantInNonInternalAgency(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$participant->firstName = 'Original';
|
||||
@@ -376,7 +383,74 @@ class BookingEditDraftServiceMutabilityTest extends TestCase
|
||||
|
||||
$this->service->applyDraftToDto($draft, $dto, $travel);
|
||||
|
||||
$this->assertSame('Updated', $participant->firstName);
|
||||
$this->assertSame('Original', $participant->firstName);
|
||||
$this->assertTrue($this->service->hadImmutableSkips());
|
||||
}
|
||||
|
||||
public function testDraftAppliesPersonalDataForMutableNonFirstParticipant(): void
|
||||
{
|
||||
$firstParticipant = new ParticipantDto();
|
||||
$firstParticipant->firstName = 'Applicant';
|
||||
|
||||
$mutableParticipant = new ParticipantDto();
|
||||
$mutableParticipant->firstName = 'Original';
|
||||
$mutableParticipant->mutable = true;
|
||||
|
||||
$travel = $this->createTravel();
|
||||
$dto = $this->createBookingDto($travel, [$firstParticipant, $mutableParticipant]);
|
||||
|
||||
$draft = $this->createDraft([
|
||||
'participants' => [
|
||||
1 => [
|
||||
'personalData' => [
|
||||
'firstName' => 'Updated',
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->service->applyDraftToDto($draft, $dto, $travel);
|
||||
|
||||
$this->assertSame('Updated', $mutableParticipant->firstName);
|
||||
$this->assertFalse($this->service->hadImmutableSkips());
|
||||
}
|
||||
|
||||
public function testDraftDoesNotFlagImmutableSkipWhenImmutableServiceStateMatchesDraft(): void
|
||||
{
|
||||
$originalService = $this->createService(10, 'Original');
|
||||
$participant = new ParticipantDto();
|
||||
$participant->additionalServices = [$originalService];
|
||||
$participant->courses = [];
|
||||
$participant->board = [];
|
||||
$participant->rentals = [];
|
||||
$participant->skiPass = null;
|
||||
$participant->rentalInsurance = null;
|
||||
|
||||
$travel = $this->createTravel(
|
||||
additionalServicesMutable: false,
|
||||
additionalServices: [10 => $originalService],
|
||||
);
|
||||
|
||||
$dto = $this->createBookingDto($travel, [$participant]);
|
||||
|
||||
$draft = $this->createDraft([
|
||||
'participants' => [
|
||||
0 => [
|
||||
'services' => [
|
||||
'additionalServices' => [10],
|
||||
'courses' => [],
|
||||
'board' => [],
|
||||
'rentals' => [],
|
||||
'skiPass' => null,
|
||||
'rentalInsurance' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->service->applyDraftToDto($draft, $dto, $travel);
|
||||
|
||||
$this->assertFalse($this->service->hadImmutableSkips());
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
|
||||
Reference in New Issue
Block a user