Files
fewo-stommer/tests/Feature/BookingAdminTest.php
T
LarsandClaude Opus 5.5 3a728c3255 Vorgangskern und geführte Vorgangsbearbeitung (Pakete 1 und 2, Prozessarchitektur v0.10)
- Buchung ist der einheitliche Vorgang: Eingangsart, Vorgangsart A1–A6, eingefrorenes
  Abwicklungsprofil, gespeicherter Verlauf (booking_events); Gast, Personen und Beträge
  dürfen unbekannt sein, Platzhalter-Gäste werden migriert und nicht mehr angelegt
- Einstellungen in Ebenen: Vermieterstandard (So arbeite ich), Abweichung der Wohnung
  (Experte), Abweichung je Portal und Eingangsart; ersetzt booking_model als Steuergröße
- Ein Weg für extern verbindliche Buchungen (TakeOverExternalBooking) statt
  RecordPortalBooking und "Akte anlegen"; Portalpreis als belegte Gesamtposition
- Startseite "Zu erledigen", neue Vorgangsseite mit nächstem Schritt, Automatik-Schalter,
  "Beenden" mit Storno statt Statusumschaltung; Status von Hand nur im Expertenmodus
- Migration übernimmt bisheriges Verhalten unverändert (abweichende Wohnungswerte bleiben
  als Abweichung), Bericht: php artisan process:settings-report

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 16:25:46 +01:00

190 lines
7.7 KiB
PHP

<?php
namespace Tests\Feature;
use App\Enums\BookingStatus;
use App\Enums\OfferKind;
use App\Filament\Resources\Bookings\BookingResource;
use App\Filament\Resources\Bookings\Pages\CreateBooking;
use App\Filament\Resources\Bookings\Pages\ListBookings;
use App\Filament\Resources\Bookings\Pages\ViewBooking;
use App\Filament\Resources\Guests\GuestResource;
use App\Filament\Resources\Properties\Pages\EditProperty;
use App\Filament\Resources\Properties\RelationManagers\BlockedPeriodsRelationManager;
use App\Filament\Resources\Properties\RelationManagers\SpecialOffersRelationManager;
use App\Mail\BookingConfirmed;
use App\Mail\BookingDeclined;
use App\Models\Booking;
use App\Models\Property;
use App\Models\User;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Filament\Actions\CreateAction;
use Filament\Actions\Testing\TestAction;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Mail;
use Livewire\Livewire;
use Tests\TestCase;
class BookingAdminTest extends TestCase
{
use RefreshDatabase;
private Property $property;
protected function setUp(): void
{
parent::setUp();
$this->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('end', ['reason' => 'Zeitraum passt nicht', '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('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());
}
}