- Gäste, Buchungen (Status-Workflow), Sperrzeiten, Sonderangebote - Vorreservierung mit Haltezeit je Wohnung; abgelaufene Holds geben den Kalender sofort frei, Cron setzt Status und benachrichtigt - Sonderangebote/Sonderkonditionen: %, € pro Aufenthalt, Sonderpreis/Nacht, Gratis-Nächte; Bedingungen u. a. Saison, Vorlauf, Wochentag, Nächte, Aktionscode; bestes Einzel- vs. kombinierte Angebote - Öffentliche Seite /buchen: Belegungskalender, Live-Preis, Anfrageformular (Honeypot, Rate-Limit) - E-Mails: Angebot an Gast, Benachrichtigung Vermieter, Bestätigung, Absage, Ablauf - Filament: Anfragen & Buchungen (bestätigen, ablehnen, verlängern, stornieren, Telefonbuchung), Gäste, Sperrzeiten, Sonderangebote - Deutsche Validierungstexte Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
159 lines
6.1 KiB
PHP
159 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Enums\BookingStatus;
|
|
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('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_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());
|
|
}
|
|
}
|