travelTo(CarbonImmutable::parse('2026-10-22 10:00')); $this->seed(PropertySeeder::class); $this->property = Property::sole(); $this->actingAs(User::factory()->create()); Mail::fake(); } public function test_booking_pages_render(): void { $booking = Booking::factory()->for($this->property)->reserved()->create(); $this->get(BookingResource::getUrl('index'))->assertOk()->assertSee($booking->reference); $this->get(BookingResource::getUrl('view', ['record' => $booking]))->assertOk()->assertSee($booking->guest->email); $this->get(GuestResource::getUrl('index'))->assertOk()->assertSee($booking->guest->email); Livewire::test(ListBookings::class)->assertCanSeeTableRecords([$booking]); } public function test_landlord_confirms_a_reservation(): void { $booking = Booking::factory()->for($this->property)->reserved()->create(); Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()]) ->callAction('confirm', ['notify' => true]) ->assertNotified('Buchung bestätigt'); $this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status); Mail::assertSent(BookingConfirmed::class); } public function test_landlord_declines_without_notifying_the_guest(): void { $booking = Booking::factory()->for($this->property)->reserved()->create(); Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()]) ->callAction('decline', ['notify' => false]); $this->assertSame(BookingStatus::Declined, $booking->fresh()->status); Mail::assertNotSent(BookingDeclined::class); } public function test_hold_can_be_extended(): void { $booking = Booking::factory()->for($this->property)->reserved(now()->addHours(2))->create(); Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()]) ->callAction('extendHold', ['hours' => 24]); $this->assertSame('2026-10-23 12:00', $booking->fresh()->hold_expires_at->format('Y-m-d H:i')); } public function test_phone_booking_is_entered_and_confirmed_with_calculated_price(): void { Livewire::test(CreateBooking::class) ->fillForm([ 'property_id' => $this->property->id, 'guests' => 2, 'arrival' => '2026-11-07', 'departure' => '2026-11-10', 'first_name' => 'Peter', 'last_name' => 'Telefon', 'email' => 'peter@example.com', 'confirm_immediately' => true, 'send_mails' => false, ]) ->call('create') ->assertHasNoFormErrors(); $booking = Booking::sole(); $this->assertSame([BookingStatus::Confirmed, 'manual', 3 * 6500 + 10800], [$booking->status, $booking->source, $booking->total]); Mail::assertNothingSent(); } public function test_phone_booking_for_occupied_dates_is_refused(): void { Booking::factory()->for($this->property)->create(['arrival' => '2026-11-08', 'departure' => '2026-11-12']); Livewire::test(CreateBooking::class) ->fillForm([ 'property_id' => $this->property->id, 'guests' => 2, 'arrival' => '2026-11-07', 'departure' => '2026-11-10', 'first_name' => 'Peter', 'last_name' => 'Telefon', 'email' => 'peter@example.com', ]) ->call('create') ->assertNotified('Buchung nicht möglich'); $this->assertSame(1, Booking::count()); } public function test_special_offer_with_euro_value_is_stored_in_cents(): void { Livewire::test(SpecialOffersRelationManager::class, ['ownerRecord' => $this->property, 'pageClass' => EditProperty::class]) ->callAction(TestAction::make(CreateAction::class)->table(), [ 'name' => 'Special Weekend', 'discount_type' => 'nightly_rate', 'discount_value' => '59.50', 'arrival_weekdays' => [5], 'season_names' => ['Winter'], ]) ->assertHasNoFormErrors(); $offer = $this->property->specialOffers()->sole(); $this->assertSame([5950, ['5'], ['Winter']], [$offer->discount_value, array_map('strval', $offer->arrival_weekdays), $offer->season_names]); } public function test_fixed_dates_package_and_gap_filler_are_created(): void { $manager = Livewire::test(SpecialOffersRelationManager::class, ['ownerRecord' => $this->property, 'pageClass' => EditProperty::class]); $manager->callAction(TestAction::make(CreateAction::class)->table(), [ 'kind' => 'fixed_dates', 'name' => 'Ostsee-Woche', 'discount_type' => 'fixed_stay_price', 'discount_value' => '499.00', 'stay_from' => '2026-11-07', 'stay_until' => '2026-11-14', 'is_featured' => true, 'priority' => 5, ])->assertHasNoFormErrors(); $manager->callAction(TestAction::make(CreateAction::class)->table(), [ 'kind' => 'gap_filler', 'name' => 'Kurzfristige Lücke', 'discount_type' => 'percent', 'discount_value' => 20, 'max_gap_nights' => 4, 'waives_min_stay' => true, ])->assertHasNoFormErrors(); $package = $this->property->specialOffers()->where('name', 'Ostsee-Woche')->sole(); $gap = $this->property->specialOffers()->where('name', 'Kurzfristige Lücke')->sole(); $this->assertSame([OfferKind::FixedDates, 49900, '2026-11-07', '2026-11-14', true, 5], [$package->kind, $package->discount_value, $package->stay_from->toDateString(), $package->stay_until->toDateString(), $package->is_featured, $package->priority]); $this->assertSame([OfferKind::GapFiller, 4, true], [$gap->kind, $gap->max_gap_nights, $gap->waives_min_stay]); } public function test_blocked_period_is_created(): void { Livewire::test(BlockedPeriodsRelationManager::class, ['ownerRecord' => $this->property, 'pageClass' => EditProperty::class]) ->callAction(TestAction::make(CreateAction::class)->table(), [ 'starts_on' => '2026-12-01', 'ends_on' => '2026-12-05', 'reason' => 'Eigennutzung', ]) ->assertHasNoFormErrors(); $this->assertSame(1, $this->property->blockedPeriods()->count()); } }