travelTo(CarbonImmutable::parse('2026-10-22 10:00')); $this->seed([PropertySeeder::class, SiteSeeder::class]); $this->property = Property::sole(); Storage::fake('local'); $this->withoutVite(); } public function test_next_step_follows_the_state_of_the_booking(): void { $request = Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create(['arrival' => '2026-11-07', 'departure' => '2026-11-10']); $this->assertSame('sendOffer', CaseActivities::next($request)?->action); Mail::fake(); $offer = app(SendOffer::class)->handle($request); $this->assertNull(CaseActivities::next($offer)); $this->assertStringContainsString('Angebot liegt beim Gast', CaseActivities::situation($offer)); $confirmed = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => '2026-12-01', 'departure' => '2026-12-05', 'deposit_due_on' => '2026-10-25', 'balance_due_on' => '2026-11-20', 'total' => 100000, 'deposit' => 30000]); $this->assertSame('sendDocuments', CaseActivities::next($confirmed)?->action); $this->travelTo(CarbonImmutable::parse('2026-12-02 12:00')); $confirmed->update(['status' => BookingStatus::Paid, 'total' => 0, 'deposit' => 0]); $this->assertStringContainsString('Gast ist vor Ort', CaseActivities::situation($confirmed->fresh())); $this->assertSame(ActivityState::Waiting, collect(CaseActivities::for($confirmed->fresh()))->firstWhere('key', 'stay')->state); } public function test_portal_booking_is_recognised_without_payment_steps_and_asks_to_send_the_contract(): void { $portal = Channel::factory()->for($this->property)->create(['name' => 'FeWo-direkt', 'booking_model' => 'portal_booking', 'process_overrides' => ['booking' => ['payments' => 'portal']]]); $booking = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'import_channel_id' => $portal->id, 'source' => 'portal', 'arrival' => '2026-12-01', 'departure' => '2026-12-05']); $this->assertSame(CaseType::A4, $booking->caseType()); $this->assertStringContainsString('Gebucht über FeWo-direkt', CaseActivities::situation($booking)); $this->assertSame('sendDocuments', CaseActivities::next($booking)?->action); $keys = array_map(fn ($activity) => $activity->key, CaseActivities::for($booking)); $this->assertContains('payment', $keys); $this->assertNotContains('deposit', $keys); } public function test_every_booking_mail_lands_in_the_communication_log_with_its_audience(): void { $booking = Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create(['arrival' => '2026-11-07', 'departure' => '2026-11-10']); app(SendOffer::class)->handle($booking); $this->assertSame(['test'], BookingMessage::query()->pluck('audience')->unique()->all()); Settings::tenant()->update(['operating_mode' => Settings::MODE_LIVE]); Settings::applyMailRouting(); BookingMessage::query()->delete(); $other = Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create(['arrival' => '2026-12-01', 'departure' => '2026-12-04']); app(SendOffer::class)->handle($other); $message = BookingMessage::query()->where('booking_id', $other->id)->sole(); $this->assertSame('guest', $message->audience); $this->assertStringContainsString('Angebot', $message->subject); } public function test_cancellation_by_the_landlord_informs_guest_and_landlord_and_leaves_a_cost_task(): void { $booking = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => '2026-12-01', 'departure' => '2026-12-05']); BookingTask::query()->create(['booking_id' => $booking->id, 'kind' => BookingTaskKind::CancellationRequest, 'status' => BookingTaskStatus::Open]); Mail::fake(); $this->assertTrue(app(CancelBooking::class)->handle($booking, notifyGuest: true)); $this->assertSame(BookingStatus::Cancelled, $booking->fresh()->status); Mail::assertSent(BookingCancelled::class, fn (BookingCancelled $mail): bool => $mail->cancelled); Mail::assertSent(CancellationRequested::class, 1); $this->assertSame(BookingTaskStatus::Done, BookingTask::query()->where('kind', BookingTaskKind::CancellationRequest)->sole()->status); $this->assertSame(BookingTaskStatus::Open, BookingTask::query()->where('kind', BookingTaskKind::CancellationFee)->sole()->status); $this->assertSame(0, Booking::query()->occupying()->count()); } public function test_cancellation_without_guest_mail_and_the_admin_action_offer_both_choices(): void { $booking = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => '2026-12-01', 'departure' => '2026-12-05']); Mail::fake(); $this->actingAs(User::factory()->create()); Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()]) ->callAction('end', ['initiated_by' => 'landlord', 'reason' => 'Wasserschaden', 'notify' => false, 'costs_task' => false]) ->assertNotified('Buchung storniert'); Mail::assertNotSent(BookingCancelled::class); Mail::assertSent(CancellationRequested::class, 1); $this->assertSame(0, BookingTask::query()->where('kind', BookingTaskKind::CancellationFee)->count()); } public function test_cancelled_bookings_leave_the_main_list_but_stay_in_the_archive_filter(): void { $active = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => '2026-12-01', 'departure' => '2026-12-05']); $cancelled = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Cancelled, 'arrival' => '2026-12-10', 'departure' => '2026-12-12']); $this->actingAs(User::factory()->create()); Livewire::test(ListBookings::class) ->assertSee($active->reference) ->assertDontSee($cancelled->reference) ->filterTable('show_closed', true) ->assertSee($cancelled->reference); } public function test_the_booking_page_shows_process_contract_tasks_and_mail_log(): void { Mail::fake(); $booking = app(SendOffer::class)->handle(Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create(['arrival' => '2026-11-07', 'departure' => '2026-11-10'])); $this->actingAs(User::factory()->create()); Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()]) ->assertSee('Angebot liegt beim Gast') ->assertSee('Gast nimmt das Angebot an') ->assertSee('Angebot Version 1'); Livewire::test(MessagesRelationManager::class, ['ownerRecord' => $booking, 'pageClass' => ViewBooking::class])->assertSuccessful(); } }