'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE']; private Property $property; protected function setUp(): void { parent::setUp(); $this->travelTo(CarbonImmutable::parse('2026-10-22 10:00')); $this->seed([PropertySeeder::class, SiteSeeder::class]); $this->property = Property::sole(); Mail::fake(); Storage::fake('local'); Http::fake(['*' => Http::response('', 500)]); Content::save(['contract.terms' => '
Echte Bedingungen
', 'stay.cancellation' => 'Echtes Storno
']); Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051']); } /** M01 */ public function test_a_request_without_address_gets_no_offer_neither_automatically_nor_by_hand(): void { Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic']]); $booking = $this->request(sendMails: true); $this->assertSame(0, $booking->fresh()->offer_version); $this->assertSame(['guest.street', 'guest.postal_code', 'guest.city', 'guest.country'], CaseRequirements::missing($booking)); try { app(SendOffer::class)->handle($booking->fresh(), ['acknowledged' => true]); $this->fail('An offer without address must not go out.'); } catch (ReservationException $exception) { $this->assertStringContainsString('Straße und Hausnummer, PLZ, Ort, Land', $exception->getMessage()); } $this->assertSame(BookingStatus::Reserved, $booking->fresh()->status); } public function test_with_the_full_address_the_offer_goes_out_automatically(): void { Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic']]); $booking = $this->request(address: self::ADDRESS, sendMails: true); $this->assertSame(BookingStatus::OfferSent, $booking->fresh()->status); } /** B3: the information "unter Vorbehalt" stays possible, the binding confirmation of the wish does not. */ public function test_an_information_needs_no_address_but_the_binding_confirmation_of_the_wish_does(): void { Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic', 'pre_reservation' => false]]); DocumentReleases::set(DocumentKind::Information, true, 'Test'); $booking = $this->request(sendMails: true)->fresh(); $this->assertSame(1, $booking->information_version, 'the information went out without address'); $outcome = app(SubmitBookingWish::class)->handle($booking, 1); $this->assertSame(SubmitBookingWish::PENDING, $outcome); $this->assertStringContainsString('fehlen noch Angaben', implode(' ', $booking->fresh()->wish['findings'])); $this->expectException(ReservationException::class); app(DecideBookingWish::class)->confirm($booking->fresh()); } public function test_the_wish_is_confirmed_once_the_address_is_there(): void { Settings::tenant()->update(['process_defaults' => ['pre_reservation' => false]]); $booking = $this->request(); app(SendInformation::class)->handle($booking->fresh(), ['acknowledged' => true]); app(SubmitBookingWish::class)->handle($booking->fresh(), 1); app(ContributeCaseFacts::class)->handle($booking->fresh(), $this->prefixed(self::ADDRESS), FactSource::Landlord); app(DecideBookingWish::class)->confirm($booking->fresh()); $this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status); } /** B4 */ public function test_an_empty_country_is_missing_and_never_assumed(): void { $booking = $this->request(address: [...self::ADDRESS, 'country' => null]); $this->assertSame(['guest.country'], CaseRequirements::missing($booking)); $this->assertNull($booking->guest->fresh()->country); } public function test_missing_values_are_taken_over_equal_ones_confirmed_and_different_ones_put_to_the_landlord(): void { $booking = $this->request(address: ['street' => 'Strandweg 1']); $result = app(ContributeCaseFacts::class)->handle($booking, ['guest.street' => 'Am Deich 7', 'guest.postal_code' => '18225', 'guest.city' => 'Kühlungsborn', 'guest.first_name' => 'gesa', 'guest.phone' => 'kein Telefon?'], FactSource::Email, ['reference' => 'mail-1']); $guest = $booking->guest->fresh(); $this->assertSame('Strandweg 1', $guest->street, 'the guest record is not written over'); $this->assertSame('18225', $guest->postal_code); $this->assertSame(['guest.postal_code', 'guest.city', 'guest.phone'], $result->fields(CaseFact::APPLIED)); $this->assertSame(['guest.first_name'], $result->fields(CaseFact::CONFIRMED)); $this->assertSame(['guest.street'], $result->fields(CaseFact::CONFLICT)); $task = BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::FactConflict)->sole(); $this->assertStringContainsString('Am Deich 7', $task->note); $this->assertStringContainsString('Strandweg 1', $task->note); $landlord = app(ContributeCaseFacts::class)->handle($booking->fresh(), ['guest.street' => 'Am Deich 7'], FactSource::Landlord); $this->assertSame(['guest.street'], $landlord->fields(CaseFact::APPLIED)); $this->assertSame('Am Deich 7', $booking->guest->fresh()->street); $this->assertSame('Strandweg 1', CaseFact::query()->where('source', FactSource::Landlord)->sole()->previous_value); } /** M03 */ public function test_the_same_contribution_twice_is_recorded_once(): void { $booking = $this->request(); app(ContributeCaseFacts::class)->handle($booking, ['guest.phone' => '038293 1234'], FactSource::GuestLink, ['reference' => 'link-v1']); $again = app(ContributeCaseFacts::class)->handle($booking->fresh(), ['guest.phone' => '038293 1234'], FactSource::GuestLink, ['reference' => 'link-v1']); $this->assertTrue($again->isEmpty()); $this->assertSame(1, CaseFact::query()->where('field', 'guest.phone')->count()); $this->assertSame(2, $booking->events()->where('type', 'facts')->count(), 'the form and the first link contribution, not the repeated one'); } /** M06 core: a binding booking gets administrative details, a change of the stay is only a request. */ public function test_a_binding_booking_takes_administrative_details_but_a_new_date_is_only_a_change_request(): void { $booking = $this->portalBooking(guest: ['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'erika@example.org']); $result = app(ContributeCaseFacts::class)->handle($booking, ['guest.phone' => '0171 555', 'booking.departure' => '2026-12-12', 'booking.guests' => '3'], FactSource::Email, ['reference' => 'mail-2']); $booking->refresh(); $this->assertSame(BookingStatus::Confirmed, $booking->status); $this->assertSame('2026-12-08', $booking->departure->toDateString(), 'nothing about the booking changed'); $this->assertNull($booking->guests); $this->assertSame('0171 555', $booking->guest->phone); $this->assertSame(['booking.departure', 'booking.guests'], $result->fields(CaseFact::CHANGE_REQUEST)); $this->assertSame(2, BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::ChangeRequest)->count()); $portal = app(ContributeCaseFacts::class)->handle($booking, ['booking.guests' => '3'], FactSource::PortalMail, ['reference' => 'portal-1']); $this->assertSame(['booking.guests'], $portal->fields(CaseFact::APPLIED), 'the portal itself may complete an unknown number of guests'); } public function test_a_case_without_guest_gets_one_from_a_name_but_never_joins_a_known_address_silently(): void { Guest::factory()->create(['email' => 'bekannt@example.org']); $booking = $this->portalBooking(); $known = app(ContributeCaseFacts::class)->handle($booking, ['guest.first_name' => 'Kai', 'guest.last_name' => 'Kurz', 'guest.email' => 'bekannt@example.org'], FactSource::Email, ['reference' => 'mail-3']); $this->assertNull($booking->fresh()->guest_id); $this->assertSame(['guest.first_name', 'guest.last_name', 'guest.email'], $known->fields(CaseFact::CONFLICT)); app(ContributeCaseFacts::class)->handle($booking->fresh(), ['guest.first_name' => 'Kai', 'guest.last_name' => 'Kurz', 'guest.email' => 'kai@example.org'], FactSource::PortalMail, ['reference' => 'mail-4']); $this->assertSame('kai@example.org', $booking->fresh()->guest->email); } /** S6: once the details are complete the existing process carries on by itself. */ public function test_completing_the_address_continues_an_automatic_case(): void { Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic']]); $booking = $this->request(sendMails: true); $this->assertSame(0, $booking->fresh()->offer_version); app(ContributeCaseFacts::class)->handle($booking->fresh(), $this->prefixed(self::ADDRESS), FactSource::GuestLink, ['reference' => 'link-v1']); $this->assertSame(BookingStatus::OfferSent, $booking->fresh()->status); } /** A step of the progress list shows where each detail came from and lets the landlord correct it. */ public function test_the_progress_list_shows_the_source_of_each_detail_and_the_landlord_corrects_it(): void { $this->actingAs(User::factory()->create()); $booking = $this->request(); app(ContributeCaseFacts::class)->handle($booking, ['guest.street' => 'Lindenallee 12'], FactSource::Extraction, ['reference' => 'message:1', 'evidence' => ['guest.street' => 'unsere Anschrift: Lindenallee 12'], 'confidence' => ['guest.street' => 0.9]]); Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()]) ->assertSeeHtml('mountAction('activityDetails', { key: 'contact' })') ->mountAction(TestAction::make('activityDetails')->arguments(['key' => 'contact'])) ->assertActionMounted('activityDetails') ->assertMountedActionModalSee(['Angaben und ihre Herkunft', 'Lindenallee 12', 'aus einer Nachricht erkannt (KI)', 'Sicherheit 90 %', 'unsere Anschrift: Lindenallee 12', 'Anfrageformular der Webseite']); Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()]) ->callAction(TestAction::make('provideContact')->arguments([]), ['guest' => ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', 'street' => 'Lindenallee 21'], 'process' => ProvideGuestContact::MANUAL, 'guest_confirmed' => false]); $this->assertSame('Lindenallee 21', $booking->guest->fresh()->street); $row = collect(ActivityDetails::facts($booking->fresh()))->firstWhere('field', 'guest.street'); $this->assertSame(['Lindenallee 21', 'von Ihnen eingetragen'], [$row['value'], $row['source']]); $this->assertSame('Lindenallee 12', CaseFact::query()->where('field', 'guest.street')->where('source', FactSource::Landlord)->sole()->previous_value, 'the corrected value stays in the evidence'); } /** * @param array