v0.11 U3: Klärungsreservierung für unvollständige Anfragen

- bookings.hold_purpose (offer wie bisher / clarification).
- RequestHold: vollständige Anfrage → Angebots-Hold unverändert;
  unvollständig, aber Wohnung, Zeitraum, verwendbare E-Mail und freier
  Zeitraum → nur Klärungsreservierung (15 min automatisch / 180 min
  Freigabe oder manuell, 0 = keine); sonst nichts (B1). Auch für
  Portalanfragen ohne Gastdaten.
- ExpireReservations beendet nur Angebots-Holds; ein abgelaufener
  Klärungsblock gibt nur den Kalender frei, der Vorgang bleibt offen.
- Vervollständigen erzeugt keinen Hold; erst SendOffer setzt den
  unveränderten Angebots-Hold. AutoOffer prüft danach nur die Verfügbarkeit.
- Booking::clarificationState() liefert den tatsächlichen Sperrstatus.
- Architekturtest: nur die bestehenden Reservierungsschritte schreiben Holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-03 13:13:24 +01:00
1 parent ccac78a6c9
commit 37f48defcc
9 files changed
+264 -5

No files matched your search

+178
View File
@@ -0,0 +1,178 @@
<?php
namespace Tests\Feature;
use App\Actions\ContributeCaseFacts;
use App\Actions\CreateReservation;
use App\Actions\ExpireReservations;
use App\Actions\SendOffer;
use App\Actions\TakeOverExternalBooking;
use App\Enums\BookingStatus;
use App\Enums\FactSource;
use App\Exceptions\ReservationException;
use App\Models\Booking;
use App\Models\Channel;
use App\Models\Property;
use App\Pricing\StayRequest;
use App\Support\Content;
use App\Support\Settings;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Database\Seeders\SiteSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
/**
* v0.11 package U3: the optional clarification hold of an incomplete request (E-033, G1a, B1, M11 reservation part,
* M12 protection of binding bookings). The offer hold stays exactly as it was.
*/
class ClarificationHoldTest extends TestCase
{
use RefreshDatabase;
private const ADDRESS = ['street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'];
private Property $property;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
$this->seed([PropertySeeder::class, SiteSeeder::class]);
$this->property = Property::sole();
Mail::fake();
Storage::fake('local');
Http::fake(['*' => Http::response('', 500)]);
Content::save(['contract.terms' => '<p>Echte Bedingungen</p>', 'stay.cancellation' => '<p>Echtes Storno</p>']);
Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051']);
}
public function test_a_complete_request_keeps_the_offer_hold_as_before(): void
{
$booking = $this->request(self::ADDRESS);
$this->assertSame(Booking::HOLD_OFFER, $booking->hold_purpose);
$this->assertTrue($booking->hold_expires_at->equalTo(now()->addHours(48)));
}
public function test_an_incomplete_request_gets_only_the_clarification_hold_of_its_mode(): void
{
$manual = $this->request();
$this->assertSame(Booking::HOLD_CLARIFICATION, $manual->hold_purpose);
$this->assertTrue($manual->hold_expires_at->equalTo(now()->addMinutes(180)), 'release or manual request: 180 minutes');
$this->assertSame('active', $manual->clarificationState()['state']);
Settings::tenant()->update(['process_defaults' => ['data_request_mode' => 'automatic']]);
$automatic = $this->request(email: 'zwei@example.org', arrival: '2026-11-20', departure: '2026-11-23');
$this->assertTrue($automatic->hold_expires_at->equalTo(now()->addMinutes(15)), 'automatic request: 15 minutes');
}
public function test_zero_means_no_clarification_hold_and_the_dates_stay_free(): void
{
Settings::tenant()->update(['process_defaults' => ['clarification_hold_manual_minutes' => 0]]);
$booking = $this->request();
$this->assertNull($booking->hold_expires_at);
$this->assertSame('none', $booking->clarificationState()['state']);
$this->assertSame(BookingStatus::Reserved, $booking->status);
$this->request(email: 'andere@example.org');
$this->assertSame(2, Booking::query()->count(), 'no hold: the same dates can still be requested');
}
public function test_a_request_without_usable_email_is_not_held(): void
{
$booking = app(CreateReservation::class)->handle($this->property->fresh(), new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Paul', 'last_name' => 'Telefon', 'email' => ''], source: 'phone', sendMails: false);
$this->assertNull($booking->hold_expires_at);
}
public function test_an_expired_clarification_hold_leaves_the_request_open_and_the_offer_needs_free_dates(): void
{
$booking = $this->request();
$this->travel(181)->minutes();
app(ExpireReservations::class)->handle();
$booking->refresh();
$this->assertSame(BookingStatus::Reserved, $booking->status, 'the case stays open');
$this->assertSame('expired', $booking->clarificationState()['state']);
$this->assertFalse(Booking::query()->occupying()->whereKey($booking->id)->exists(), 'the calendar is free again');
app(ContributeCaseFacts::class)->handle($booking, collect(self::ADDRESS)->mapWithKeys(fn (string $value, string $key): array => ['guest.'.$key => $value])->all(), FactSource::GuestLink, ['reference' => 'link-1']);
$this->assertFalse($booking->fresh()->isHoldActive(), 'completing the details creates no offer hold by itself');
$this->assertSame(Booking::HOLD_CLARIFICATION, $booking->fresh()->hold_purpose);
$competitor = $this->request(self::ADDRESS, email: 'schneller@example.org');
$this->assertSame(Booking::HOLD_OFFER, $competitor->hold_purpose);
$this->expectException(ReservationException::class);
app(SendOffer::class)->handle($booking->fresh());
}
public function test_the_offer_turns_the_clarification_hold_into_the_unchanged_offer_hold(): void
{
$booking = $this->request();
app(ContributeCaseFacts::class)->handle($booking, collect(self::ADDRESS)->mapWithKeys(fn (string $value, string $key): array => ['guest.'.$key => $value])->all(), FactSource::GuestLink, ['reference' => 'link-1']);
$offer = app(SendOffer::class)->handle($booking->fresh());
$this->assertSame(Booking::HOLD_OFFER, $offer->hold_purpose);
$this->assertTrue($offer->hold_expires_at->equalTo(now()->addHours(48)));
}
public function test_a_binding_portal_booking_never_gets_a_clarification_hold(): void
{
$portal = Channel::factory()->for($this->property)->create(['name' => 'FeWo-direkt', 'booking_model' => 'portal_booking']);
$booking = app(TakeOverExternalBooking::class)->handle($this->property, $portal, CarbonImmutable::parse('2026-12-05'), CarbonImmutable::parse('2026-12-08'), ['portal_reference' => 'HA-7']);
$this->assertSame(BookingStatus::Confirmed, $booking->status);
$this->assertNotSame(Booking::HOLD_CLARIFICATION, $booking->hold_purpose);
$this->assertSame('none', $booking->clarificationState()['state']);
}
/**
* Holds are set only by the existing reservation and offer steps (plus the intake decision of v0.11). Nothing of
* the communication handler – data requests, answers, reminders, extraction – may extend or set one (CH-16/17).
*/
public function test_only_the_existing_reservation_steps_write_a_hold(): void
{
$allowed = [
'Actions/ConfirmBooking.php', 'Actions/CreateReservation.php', 'Actions/DecideBookingWish.php', 'Actions/DeclineBooking.php',
'Actions/RejectOffer.php', 'Actions/ReleaseReservation.php', 'Actions/SendInformation.php', 'Actions/SendOffer.php',
'Actions/SetBookingStatus.php', 'Actions/TakeOverExternalBooking.php', 'Actions/TakeOverPortalInquiry.php',
'Documents/DocumentComposer.php', 'Filament/Resources/Bookings/Pages/ViewBooking.php', 'Models/Booking.php', 'Process/RequestHold.php',
];
$writers = [];
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(app_path(), \FilesystemIterator::SKIP_DOTS));
foreach ($files as $file) {
$source = file_get_contents($file->getPathname());
if (preg_match("/'hold_expires_at' =>|hold_expires_at = |RequestHold::for/", $source)) {
$writers[] = str_replace('\\', '/', substr($file->getPathname(), strlen(app_path()) + 1));
}
}
sort($writers);
sort($allowed);
$this->assertSame($allowed, $writers);
}
/**
* @param array<string, string> $address
*/
private function request(array $address = [], string $email = 'gesa@example.org', string $arrival = '2026-11-07', string $departure = '2026-11-10'): Booking
{
return app(CreateReservation::class)->handle(
$this->property->fresh(),
new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2),
['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => $email, ...$address],
sendMails: false,
)->fresh();
}
}
+1 -1
View File
@@ -143,7 +143,7 @@ private function reserve(string $arrival, string $departure, string $email = 'an
return app(CreateReservation::class)->handle(
$this->property,
new StayRequest($this->date($arrival), $this->date($departure), 2),
['first_name' => 'Anna', 'last_name' => 'Muster', 'email' => $email],
['first_name' => 'Anna', 'last_name' => 'Muster', 'email' => $email, 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'],
);
}