travelTo(CarbonImmutable::parse('2026-10-22 10:00')); $this->seed([PropertySeeder::class, SiteSeeder::class]); $this->property = Property::sole(); Mail::fake(); Storage::fake('local'); $this->withoutVite(); } public function test_release_link_opens_a_page_and_only_the_button_releases_the_dates(): void { $booking = Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create(['arrival' => '2026-11-07', 'departure' => '2026-11-10']); $link = SelfServiceLinks::release($booking); $this->get($link)->assertOk()->assertSee('Zeitraum freigeben'); $this->assertSame(BookingStatus::Reserved, $booking->fresh()->status); $action = $this->formAction($link, 'freigeben/bestaetigen'); $this->submit($action)->assertOk()->assertSee('wieder freigegeben'); $this->submit($action)->assertOk(); $this->assertSame(BookingStatus::Declined, $booking->fresh()->status); $this->assertSame(0, Booking::query()->occupying()->count()); } public function test_release_never_touches_a_binding_booking_and_needs_a_valid_signature(): void { $booking = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => '2026-11-07', 'departure' => '2026-11-10']); $this->get(SelfServiceLinks::release($booking).'x')->assertForbidden(); $this->post(SelfServiceLinks::release($booking))->assertStatus(405); $this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status); } public function test_reservation_mail_contains_the_release_link_only_while_the_dates_are_held(): void { $booking = Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create(); $this->assertStringContainsString('/freigeben', (new ReservationReceived($booking))->render()); $booking->update(['hold_expires_at' => null]); $this->assertStringNotContainsString('/freigeben', (new ReservationReceived($booking->fresh()))->render()); } public function test_confirmation_contains_the_cancellation_link(): 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])); app(AcceptOffer::class)->handle($offer->fresh(), 1); Mail::assertSent(BookingConfirmed::class, fn (BookingConfirmed $mail): bool => str_contains($mail->render(), '/storno')); } public function test_request_mode_only_creates_a_task_and_keeps_the_booking(): void { $booking = $this->confirmed(); $link = SelfServiceLinks::cancel($booking); $this->get($link)->assertOk()->assertSee('Stornierung anfragen'); $action = $this->formAction($link, 'storno/bestaetigen'); $this->submit($action, ['message' => 'Krank'])->assertOk()->assertSee('Stornierungswunsch erhalten'); $this->submit($action)->assertOk()->assertSee('liegt uns bereits vor'); $this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status); $task = BookingTask::query()->where('kind', BookingTaskKind::CancellationRequest)->sole(); $this->assertSame('Krank', $task->note); Mail::assertSent(CancellationRequested::class, 1); Mail::assertSent(BookingCancelled::class, fn (BookingCancelled $mail): bool => ! $mail->cancelled); } public function test_instant_mode_cancels_at_once_and_still_leaves_a_task_for_the_costs(): void { $this->property->update(['cancellation_mode' => CancellationMode::Instant]); $booking = $this->confirmed(); $link = SelfServiceLinks::cancel($booking); $this->submit($this->formAction($link, 'storno/bestaetigen'))->assertOk()->assertSee('storniert'); $this->assertSame(BookingStatus::Cancelled, $booking->fresh()->status); $this->assertSame(0, Booking::query()->occupying()->count()); $this->assertStringContainsString('Stornokosten', BookingTask::query()->sole()->note); Mail::assertSent(BookingCancelled::class, fn (BookingCancelled $mail): bool => $mail->cancelled); } public function test_free_cancellation_window_switches_between_instant_and_request(): void { $this->property->update(['cancellation_mode' => CancellationMode::InstantWhenFree, 'free_cancellation_days' => 14]); $far = $this->confirmed('2026-12-20', '2026-12-24'); $near = $this->confirmed('2026-11-01', '2026-11-04'); $this->post($this->formAction(SelfServiceLinks::cancel($far), 'storno/bestaetigen')); $this->post($this->formAction(SelfServiceLinks::cancel($near), 'storno/bestaetigen')); $this->assertSame(BookingStatus::Cancelled, $far->fresh()->status); $this->assertSame(BookingStatus::Confirmed, $near->fresh()->status); } public function test_payment_tasks_follow_the_channel_policy(): void { $own = $this->confirmed(); $reservationPortal = Channel::factory()->for($this->property)->create(['booking_model' => 'portal_booking', 'process_overrides' => ['booking' => ['payments' => 'portal']]]); $inquiryPortal = Channel::factory()->for($this->property)->create(['booking_model' => 'inquiry', 'process_overrides' => ['inquiry' => ['payments' => 'landlord']]]); $portalReservation = $this->confirmed('2026-12-10', '2026-12-14', ['import_channel_id' => $reservationPortal->id, 'source' => 'portal']); $portalInquiry = $this->confirmed('2026-12-16', '2026-12-18', ['import_channel_id' => $inquiryPortal->id, 'source' => 'portal']); $this->travelTo(CarbonImmutable::parse('2026-11-30 09:00')); (new SendBookingReminders)->handle(); $withTasks = BookingTask::query()->pluck('booking_id')->unique()->all(); $this->assertContains($own->id, $withTasks); $this->assertContains($portalInquiry->id, $withTasks); $this->assertNotContains($portalReservation->id, $withTasks); Mail::assertNotSent(PaymentReminder::class); } /** * @param array $attributes */ private function confirmed(string $arrival = '2026-12-01', string $departure = '2026-12-05', array $attributes = []): Booking { return Booking::factory()->for($this->property)->create([ 'status' => BookingStatus::Confirmed, 'arrival' => $arrival, 'departure' => $departure, 'deposit_due_on' => '2026-10-25', 'balance_due_on' => '2026-11-20', 'total' => 100000, 'deposit' => 30000, ...$attributes, ]); } /** * Posts the form and opens the page it redirects to (the redirect carries the result message in the session). * * @param array $data */ private function submit(string $action, array $data = []): TestResponse { return $this->get($this->post($action, $data)->headers->get('Location')); } private function formAction(string $pageUrl, string $action): string { preg_match('~action="([^"]*/'.preg_quote($action, '~').'[^"]*)"~', $this->get($pageUrl)->getContent(), $match); $this->assertNotEmpty($match, "form for {$action} not found"); return html_entity_decode($match[1]); } }