travelTo(CarbonImmutable::parse('2026-10-22 10:00')); Storage::fake('local'); Mail::fake(); $this->seed(PropertySeeder::class); $this->property = Property::sole(); } public function test_confirmation_fixes_due_dates_and_sends_the_contract(): void { $booking = $this->confirmed('2026-12-01', '2026-12-05'); $this->assertSame('2026-10-29', $booking->deposit_due_on->toDateString()); $this->assertFalse($booking->requiresFullPayment()); Storage::disk('local')->assertExists($booking->contract_path); $this->assertStringStartsWith('%PDF', Storage::disk('local')->get($booking->contract_path)); Mail::assertSent(BookingConfirmed::class, fn (BookingConfirmed $mail): bool => count($mail->attachments()) === 1); } public function test_short_term_booking_requires_full_payment(): void { $booking = $this->confirmed('2026-11-07', '2026-11-10'); $this->assertTrue($booking->requiresFullPayment()); $this->assertStringContainsString('Gesamtbetrag', (new BookingConfirmed($booking))->render()); } public function test_payments_move_the_booking_through_its_statuses(): void { $booking = $this->confirmed('2026-12-01', '2026-12-05'); $record = new RecordPayment; $record->handle($booking, $booking->deposit, today()); $this->assertSame(BookingStatus::DepositPaid, $booking->fresh()->status); $record->handle($booking->fresh(), $booking->total - $booking->deposit, today()); $this->assertSame(BookingStatus::Paid, $booking->fresh()->status); $this->assertSame(0, $booking->fresh()->openAmount()); $record->handle($booking->fresh(), -5000, today(), note: 'Erstattung'); $this->assertSame(BookingStatus::DepositPaid, $booking->fresh()->status); } public function test_reminders_are_sent_once_at_the_right_time(): void { $booking = $this->confirmed('2026-12-01', '2026-12-05'); $reminders = new SendBookingReminders; $this->travelTo(CarbonImmutable::parse('2026-10-30 09:00')); $this->assertSame(1, $reminders->handle()['deposit_overdue']); $this->assertSame(0, $reminders->handle()['deposit_overdue']); Mail::assertSent(PaymentReminder::class, fn (PaymentReminder $mail): bool => $mail->kind === PaymentReminder::DEPOSIT_OVERDUE && $mail->hasBcc(config('fewo.notification_email'))); (new RecordPayment)->handle($booking, $booking->deposit, today()); $this->travelTo(CarbonImmutable::parse('2026-10-26 09:00')); $this->assertSame(0, $reminders->handle()['balance_request'], 'balance is due on 03.11.; request 7 days before'); $this->travelTo(CarbonImmutable::parse('2026-10-27 09:00')); $this->assertSame(1, $reminders->handle()['balance_request']); $this->travelTo(CarbonImmutable::parse('2026-11-04 09:00')); $this->assertSame(1, $reminders->handle()['balance_overdue']); $this->travelTo(CarbonImmutable::parse('2026-11-24 09:00')); $this->assertSame(1, $reminders->handle()['arrival_info']); Mail::assertSent(ArrivalInformation::class); (new RecordPayment)->handle($booking->fresh(), $booking->fresh()->openAmount(), today()); $this->travelTo(CarbonImmutable::parse('2026-12-06 09:00')); $this->assertSame(1, $reminders->handle()['completed']); $this->assertSame(BookingStatus::Completed, $booking->fresh()->status); } public function test_payment_is_recorded_and_contract_downloaded_in_the_admin(): void { $this->actingAs(User::factory()->create()); $booking = $this->confirmed('2026-12-01', '2026-12-05'); Livewire::test(PaymentsRelationManager::class, ['ownerRecord' => $booking, 'pageClass' => ViewBooking::class]) ->callAction(TestAction::make('record')->table(), [ 'amount' => number_format($booking->deposit / 100, 2, '.', ''), 'paid_on' => '2026-10-25', 'method' => 'transfer', ]) ->assertHasNoFormErrors(); $this->assertSame(BookingStatus::DepositPaid, $booking->fresh()->status); Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()]) ->callAction('contract') ->assertFileDownloaded("Mietvertrag-{$booking->reference}.pdf"); } private function confirmed(string $arrival, string $departure): Booking { $booking = app(CreateReservation::class)->handle( $this->property, new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2), ['first_name' => 'Anna', 'last_name' => 'Muster', 'email' => 'anna@example.com', 'city' => 'Köln'], ); app(ConfirmBooking::class)->handle($booking); return $booking->fresh(); } }