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)]); } public function test_manual_mode_sends_the_receipt_and_no_offer(): void { $booking = $this->request(); $this->assertSame(BookingStatus::Reserved, $booking->status); $this->assertTrue($booking->isHoldActive()); Mail::assertSent(ReservationReceived::class, 1); Mail::assertSent(NewReservation::class, fn (NewReservation $mail): bool => ! $mail->offerSent && $mail->blockers === []); Mail::assertNotSent(OfferMade::class); } public function test_automatic_mode_sends_the_offer_instead_of_the_receipt(): void { $this->automatic(); $booking = $this->request(); $this->assertSame(BookingStatus::OfferSent, $booking->status); $this->assertSame(1, $booking->offer_version); $this->assertNotNull($booking->offer_hash); Mail::assertSent(OfferMade::class, 1); Mail::assertNotSent(ReservationReceived::class); Mail::assertSent(NewReservation::class, fn (NewReservation $mail): bool => $mail->offerSent); } public function test_automatic_offer_can_be_accepted_end_to_end(): void { $this->automatic(); $booking = $this->request(); $this->assertTrue(app(AcceptOffer::class)->handle($booking->fresh(), 1)); $this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status); } public function test_without_pre_reservation_a_request_blocks_nothing(): void { Settings::tenant()->update(['process_defaults' => ['pre_reservation' => false]]); $first = $this->request(); $second = $this->request('other@example.org'); $this->assertNull($first->hold_expires_at); $this->assertFalse($first->isHoldActive()); $this->assertSame(0, Booking::query()->occupying()->count()); $this->assertSame(BookingStatus::Reserved, $second->status); Mail::assertSent(ReservationReceived::class, fn (ReservationReceived $mail): bool => str_contains($mail->render(), 'nicht reserviert') && ! str_contains($mail->render(), 'vorgemerkt')); } public function test_automatic_mode_without_pre_reservation_falls_back_to_manual_and_says_why(): void { Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic', 'pre_reservation' => false]]); $booking = $this->request(); $this->assertSame(BookingStatus::Reserved, $booking->status); $this->assertStringContainsString('vorreservierung', mb_strtolower($booking->internal_notes)); Mail::assertNotSent(OfferMade::class); Mail::assertSent(ReservationReceived::class, 1); Mail::assertSent(NewReservation::class, fn (NewReservation $mail): bool => $mail->blockers !== []); } public function test_instant_booking_portal_holds_the_offer_back_until_it_fetched_our_feed(): void { $this->automatic(); $channel = $this->channel(['name' => 'Sofort-Portal', 'booking_model' => 'portal_booking']); $booking = $this->request(); $this->assertSame(BookingStatus::Reserved, $booking->status); $this->assertStringContainsString('Sofort-Portal', $booking->internal_notes); Mail::assertNotSent(OfferMade::class); $this->travel(10)->minutes(); $this->feedFetch($channel); $this->artisan('bookings:auto-offers')->assertSuccessful(); $this->assertSame(BookingStatus::OfferSent, $booking->fresh()->status); Mail::assertSent(OfferMade::class, 1); } public function test_feed_fetch_before_the_block_or_failed_fetch_or_other_channel_is_no_proof(): void { $this->automatic(); $channel = $this->channel(['booking_model' => 'portal_booking']); $other = $this->channel(['name' => 'Anderes Portal', 'booking_model' => 'inquiry']); $this->feedFetch($channel, at: now()->subMinutes(5)); $booking = $this->request(); $this->travel(5)->minutes(); $this->feedFetch($channel, status: 503); $this->feedFetch($other); $this->artisan('bookings:auto-offers')->assertSuccessful(); $this->assertSame(BookingStatus::Reserved, $booking->fresh()->status); } public function test_portal_without_instant_booking_needs_no_proof(): void { $this->automatic(); $this->channel(['booking_model' => 'inquiry']); $this->assertSame(BookingStatus::OfferSent, $this->request()->status); } public function test_stale_calendar_import_blocks_the_automatic_offer(): void { $this->automatic(); $this->channel(['booking_model' => 'inquiry', 'last_success_at' => now()->subHours(3), 'import_enabled' => true]); $booking = $this->request(); $this->assertSame(BookingStatus::Reserved, $booking->status); $this->assertStringContainsString('nicht aktuell', $booking->internal_notes); } public function test_unattributable_feed_request_is_not_recorded_as_proof(): void { $this->get('/kalender/falsches-token.ics')->assertNotFound(); $this->assertSame(0, ChannelExportRequest::query()->count()); } public function test_acceptance_is_refused_while_a_portal_calendar_is_stale(): void { $offer = app(SendOffer::class)->handle(Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create(['arrival' => '2026-11-07', 'departure' => '2026-11-10', 'guests' => 2])); $this->channel(['booking_model' => 'inquiry', 'last_success_at' => now()->subHours(3)]); try { app(AcceptOffer::class)->handle($offer->fresh(), 1); $this->fail('Acceptance needs a recent calendar.'); } catch (ReservationException $exception) { $this->assertSame(ReservationException::calendarUnverified()->getMessage(), $exception->getMessage()); } $this->assertSame(BookingStatus::OfferSent, $offer->fresh()->status); $this->assertNull($offer->fresh()->acceptance); } public function test_live_operation_needs_released_contract_texts_for_automatic_offers(): void { $this->automatic(); Settings::tenant()->update(['operating_mode' => Settings::MODE_LIVE]); $sample = $this->request(); $this->assertSame(BookingStatus::Reserved, $sample->status); $this->assertStringContainsString('freigegeben', $sample->internal_notes); Content::save(['contract.terms' => '
Echte Bedingungen
', 'stay.cancellation' => 'Echtes Storno
']); Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051']); $this->assertSame(BookingStatus::OfferSent, $this->request('real@example.org', '2026-12-01', '2026-12-05')->status); } private function automatic(): void { Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic']]); } private function request(string $email = 'gast@example.org', string $arrival = '2026-11-07', string $departure = '2026-11-10'): Booking { return app(CreateReservation::class)->handle( $this->property->fresh(), new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2), ['first_name' => 'Gast', 'last_name' => 'Test', 'email' => $email], )->fresh(['guest', 'property']); } /** * @param array