Phase 2: Kalender, Anfrage, Vorreservierung & Sonderangebote
- 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>
This commit is contained in:
1 parent
2e9a391b37
commit
08b6582fa1
79 files changed
+6213
-76
No files matched your search
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Actions\ConfirmBooking;
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Actions\ExpireReservations;
|
||||
use App\Availability\AvailabilityChecker;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Mail\BookingConfirmed;
|
||||
use App\Mail\NewReservation;
|
||||
use App\Mail\ReservationExpired;
|
||||
use App\Mail\ReservationReceived;
|
||||
use App\Models\BlockedPeriod;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Property;
|
||||
use App\Pricing\StayRequest;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ReservationWorkflowTest 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();
|
||||
Mail::fake();
|
||||
}
|
||||
|
||||
public function test_active_reservations_and_blocked_periods_occupy_the_calendar_but_allow_changeover(): void
|
||||
{
|
||||
Booking::factory()->for($this->property)->reserved(now()->addHour())->create(['arrival' => '2026-11-10', 'departure' => '2026-11-14']);
|
||||
BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-11-20', 'ends_on' => '2026-11-22']);
|
||||
$availability = new AvailabilityChecker;
|
||||
|
||||
$this->assertFalse($availability->isAvailable($this->property, $this->date('2026-11-12'), $this->date('2026-11-16')));
|
||||
$this->assertFalse($availability->isAvailable($this->property, $this->date('2026-11-18'), $this->date('2026-11-21')));
|
||||
$this->assertTrue($availability->isAvailable($this->property, $this->date('2026-11-14'), $this->date('2026-11-16')), 'arrival on departure day');
|
||||
$this->assertTrue($availability->isAvailable($this->property, $this->date('2026-11-07'), $this->date('2026-11-10')), 'departure on arrival day');
|
||||
$this->assertSame(['2026-11-10', '2026-11-11', '2026-11-12', '2026-11-13', '2026-11-20', '2026-11-21'], array_keys(
|
||||
$availability->occupiedNights($this->property, $this->date('2026-11-01'), $this->date('2026-12-01')),
|
||||
));
|
||||
}
|
||||
|
||||
public function test_reservation_with_elapsed_hold_no_longer_occupies_the_calendar(): void
|
||||
{
|
||||
Booking::factory()->for($this->property)->reserved(now()->subMinute())->create(['arrival' => '2026-11-10', 'departure' => '2026-11-14']);
|
||||
|
||||
$this->assertTrue((new AvailabilityChecker)->isAvailable($this->property, $this->date('2026-11-10'), $this->date('2026-11-14')));
|
||||
}
|
||||
|
||||
public function test_request_creates_a_held_reservation_and_sends_quote_and_notification(): void
|
||||
{
|
||||
$booking = $this->reserve('2026-11-07', '2026-11-10');
|
||||
|
||||
$this->assertSame(BookingStatus::Reserved, $booking->status);
|
||||
$this->assertSame('2026-10-24 10:00', $booking->hold_expires_at->format('Y-m-d H:i'));
|
||||
$this->assertSame(3 * 6500 + 10800, $booking->total);
|
||||
$this->assertSame('2026-'.str_pad((string) $booking->id, 4, '0', STR_PAD_LEFT), $booking->reference);
|
||||
$this->assertSame('anna@example.com', $booking->guest->email);
|
||||
Mail::assertSent(ReservationReceived::class, fn (ReservationReceived $mail): bool => $mail->hasTo('anna@example.com'));
|
||||
Mail::assertSent(NewReservation::class, fn (NewReservation $mail): bool => $mail->hasTo(config('fewo.notification_email')));
|
||||
}
|
||||
|
||||
public function test_request_for_occupied_dates_is_rejected(): void
|
||||
{
|
||||
$this->reserve('2026-11-07', '2026-11-10');
|
||||
|
||||
$this->expectException(ReservationException::class);
|
||||
|
||||
$this->reserve('2026-11-09', '2026-11-12');
|
||||
}
|
||||
|
||||
public function test_returning_guest_is_recognised_by_email(): void
|
||||
{
|
||||
$first = $this->reserve('2026-11-07', '2026-11-10');
|
||||
$second = $this->reserve('2026-11-20', '2026-11-23', 'ANNA@example.com');
|
||||
|
||||
$this->assertTrue($first->guest->is($second->guest));
|
||||
}
|
||||
|
||||
public function test_expired_holds_are_marked_and_the_landlord_is_notified(): void
|
||||
{
|
||||
$booking = $this->reserve('2026-11-07', '2026-11-10');
|
||||
|
||||
$this->travel(47)->hours();
|
||||
$this->assertSame(0, (new ExpireReservations)->handle());
|
||||
|
||||
$this->travel(2)->hours();
|
||||
$this->assertSame(1, (new ExpireReservations)->handle());
|
||||
|
||||
$this->assertSame(BookingStatus::Expired, $booking->fresh()->status);
|
||||
Mail::assertSent(ReservationExpired::class);
|
||||
}
|
||||
|
||||
public function test_confirmation_makes_the_booking_binding_and_informs_the_guest(): void
|
||||
{
|
||||
$booking = $this->reserve('2026-11-07', '2026-11-10');
|
||||
|
||||
app(ConfirmBooking::class)->handle($booking);
|
||||
|
||||
$booking->refresh();
|
||||
$this->assertSame(BookingStatus::Confirmed, $booking->status);
|
||||
$this->assertNull($booking->hold_expires_at);
|
||||
$this->assertNotNull($booking->confirmed_at);
|
||||
Mail::assertSent(BookingConfirmed::class, fn (BookingConfirmed $mail): bool => $mail->hasTo('anna@example.com'));
|
||||
}
|
||||
|
||||
public function test_expired_reservation_cannot_be_confirmed_once_the_dates_are_taken(): void
|
||||
{
|
||||
$expired = $this->reserve('2026-11-07', '2026-11-10');
|
||||
$this->travel(3)->days();
|
||||
(new ExpireReservations)->handle();
|
||||
$this->reserve('2026-11-08', '2026-11-12', 'other@example.com');
|
||||
|
||||
$this->expectException(ReservationException::class);
|
||||
|
||||
app(ConfirmBooking::class)->handle($expired->fresh());
|
||||
}
|
||||
|
||||
public function test_mails_render(): void
|
||||
{
|
||||
$booking = $this->reserve('2026-11-07', '2026-11-10');
|
||||
|
||||
$this->assertStringContainsString('vorgemerkt', (new ReservationReceived($booking))->render());
|
||||
$this->assertStringContainsString($booking->reference, (new NewReservation($booking))->render());
|
||||
$this->assertStringContainsString('bestätigen', (new BookingConfirmed($booking))->render());
|
||||
}
|
||||
|
||||
private function reserve(string $arrival, string $departure, string $email = 'anna@example.com'): Booking
|
||||
{
|
||||
return app(CreateReservation::class)->handle(
|
||||
$this->property,
|
||||
new StayRequest($this->date($arrival), $this->date($departure), 2),
|
||||
['first_name' => 'Anna', 'last_name' => 'Muster', 'email' => $email],
|
||||
);
|
||||
}
|
||||
|
||||
private function date(string $date): CarbonImmutable
|
||||
{
|
||||
return CarbonImmutable::parse($date);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user