fix: always fill-in empty participants names when submitting to api

This commit is contained in:
Björn Fromme
2026-02-20 09:48:22 +01:00
parent 21356f00d5
commit 45cfc459aa
2 changed files with 137 additions and 13 deletions
@@ -564,6 +564,132 @@ class BookingDataProcessorTest extends TestCase
$this->assertEquals('', $canceledParticipant->name);
}
public function testConfirmedParticipantEmptyNamesFilledForAgencyBooking(): void
{
$formData = $this->createFormDataWithConfirmedParticipantEmptyNames();
$this->processor->createUpdateRequestPayload($formData);
// Confirmed participant (index 1) with empty names should have default names filled
$participant = $formData->booking->participants[1];
$this->assertEquals('Teilnehmer:in 2', $participant->firstName);
$this->assertEquals('Teilnehmer:in 2', $participant->name);
// Active participant (index 0) should retain original names from form
$activeParticipant = $formData->booking->participants[0];
$this->assertEquals('Participant0', $activeParticipant->firstName);
$this->assertEquals('LastName', $activeParticipant->name);
}
public function testConfirmedParticipantPartialEmptyNameFilledForAgencyBooking(): void
{
$formData = $this->createFormDataWithConfirmedParticipantPartialEmptyName();
$this->processor->createUpdateRequestPayload($formData);
// Participant with lastName but empty firstName should get default firstName only
$participant = $formData->booking->participants[1];
$this->assertEquals('Teilnehmer:in 2', $participant->firstName);
$this->assertEquals('Schnekenburger', $participant->name);
}
private function createFormDataWithConfirmedParticipantEmptyNames(): BookingDto
{
$bookingDto = new BookingDto($this->createMockTravel(), 1);
$bookingDto->booking = $this->createMockBookingWithEmptyNameParticipant('F', '', '');
$bookingDto->agencyCode = '0004';
$bookingDto->participants = [
$this->createMockParticipantDto(0, 'F'),
$this->createMockParticipantDtoWithEmptyNames(1, 'F'),
];
return $bookingDto;
}
private function createFormDataWithConfirmedParticipantPartialEmptyName(): BookingDto
{
$bookingDto = new BookingDto($this->createMockTravel(), 1);
$bookingDto->booking = $this->createMockBookingWithEmptyNameParticipant('F', '', 'Schnekenburger');
$bookingDto->agencyCode = '0004';
$bookingDto->participants = [
$this->createMockParticipantDto(0, 'F'),
$this->createMockParticipantDtoWithPartialName(1, 'F', '', 'Schnekenburger'),
];
return $bookingDto;
}
private function createMockBookingWithEmptyNameParticipant(
string $status,
string $firstName,
string $lastName,
): Booking {
$booking = new Booking();
$booking->id = 123;
$booking->status = 'ACTIVE';
$booking->agencyId = 999;
$booking->dateId = 1;
$booking->hotelId = 1;
$booking->paymentId = '1';
$booking->paymentLabel = 'Credit Card';
$booking->paymentType = 'CC';
$booking->additionalServices = [];
$booking->transportationServices = [];
$booking->pickups = [];
$booking->dropOffs = [];
$emptyNameParticipant = new PersonalData();
$emptyNameParticipant->firstName = $firstName;
$emptyNameParticipant->name = $lastName;
$emptyNameParticipant->dateOfBirth = new \DateTimeImmutable('1990-01-01');
$emptyNameParticipant->gender = 'M';
$emptyNameParticipant->nationality = 'DE';
$emptyNameParticipant->address = new Address();
$emptyNameParticipant->communication = new Communication();
$booking->participants = [
$this->createMockPersonalData('Participant0'),
$emptyNameParticipant,
];
$booking->participantsStatus = ['F', $status];
$booking->applicant = $this->createMockPersonalData('Applicant');
$booking->bankAccount = null;
$booking->rooms = [];
return $booking;
}
private function createMockParticipantDtoWithPartialName(
int $index,
string $status,
string $firstName,
string $lastName,
): ParticipantDto {
$participant = new ParticipantDto();
$participant->index = $index;
$participant->status = $status;
$participant->firstName = $firstName;
$participant->lastName = $lastName;
$participant->dateOfBirth = new \DateTimeImmutable('1990-01-01');
$participant->gender = 'M';
$participant->nationality = 'DE';
$participant->height = '175';
$participant->weight = '70';
$participant->shoeSize = '40';
$participant->email = null;
$participant->mobile = null;
$participant->courses = [];
$participant->additionalServices = [];
$participant->skiPass = null;
$participant->board = [];
$participant->rentals = [];
$participant->transportationOutbound = $this->createMockService(1);
$participant->transportationInbound = $this->createMockService(2);
$participant->pickup = null;
return $participant;
}
private function createFormDataWithCanceledParticipantEmptyNames(): BookingDto
{
$bookingDto = new BookingDto($this->createMockTravel(), 1);