U-D/U-E/O5: Prozess-Tester im eigenen Prozess (standardmäßig gesperrt, 15 Negativtests, statischer Wächter), Szenarien und Bericht, Kanalereignisse (API-Eingang ohne Umbau von iCal/Mail), Abschluss nach finanzieller Klärung, Löschfrist 30 Tage

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-04 15:34:40 +01:00
1 parent c255783cec
commit 0689c0a591
68 files changed
+3350 -35

No files matched your search

@@ -0,0 +1,49 @@
<?php
namespace App\Process\Tester\Scenarios;
use App\Enums\IntakeKind;
use App\Process\Tester\SandboxContext;
use Illuminate\Mail\Events\MessageSending;
use Illuminate\Support\Facades\Event;
use Symfony\Component\Mailer\Exception\TransportException;
/**
* S12: the mail server fails when the request comes in – the case must be kept and show a defined state (the real
* error type of the transport, no crash). The failure is simulated where every mail passes (MessageSending), without a
* transport of its own.
*/
final class CommunicationFailure extends Scenario
{
public static function key(): string
{
return 'mail_failure';
}
public static function label(): string
{
return 'Mailversand fällt aus';
}
public static function description(): string
{
return 'Beim Eingang der Anfrage ist der Mailserver nicht erreichbar. Der Vorgang bleibt erhalten und zeigt, was von Hand zu tun ist.';
}
public static function intakes(): array
{
return [IntakeKind::Inquiry];
}
public function events(array $inputs): array
{
return [
new ScenarioEvent('Mailserver fällt aus', function (SandboxContext $context): void {
Event::listen(MessageSending::class, function (): void {
throw new TransportException('Verbindung zum Mailserver fehlgeschlagen (simuliert).');
});
}),
new ScenarioEvent('Gast fragt mit allen Angaben an', fn (SandboxContext $context) => $context->request(['street' => 'Teststraße 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'])),
];
}
}
@@ -0,0 +1,57 @@
<?php
namespace App\Process\Tester\Scenarios;
use App\Actions\AcceptOffer;
use App\Actions\SendOffer;
use App\Enums\BookingStatus;
use App\Enums\IntakeKind;
use App\Process\Tester\SandboxContext;
/**
* S01/S06/S11: a complete request – offer (automatic or by the landlord), acceptance, binding booking, arrival, after
* departure (review request, closing; a switched-off step is shown as skipped).
*/
final class CompleteRequest extends Scenario
{
public static function key(): string
{
return 'complete_request';
}
public static function label(): string
{
return 'Vollständige Anfrage bis zur Buchung';
}
public static function description(): string
{
return 'Ein Gast fragt mit allen Angaben an, erhält das Angebot und nimmt es an; danach Anreise und Abreise.';
}
public static function intakes(): array
{
return [IntakeKind::Inquiry];
}
public function events(array $inputs): array
{
return [
new ScenarioEvent('Gast fragt mit allen Angaben an', fn (SandboxContext $context) => $context->request(['street' => 'Teststraße 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'])),
new ScenarioEvent('Sie senden das Angebot (falls es nicht automatisch ging)', function (SandboxContext $context): void {
$booking = $context->booking->fresh();
if ($booking->status === BookingStatus::Reserved && $booking->offer_version === 0 && $booking->process()->preReservation()) {
app(SendOffer::class)->handle($booking);
}
}),
new ScenarioEvent('Gast nimmt das Angebot an', function (SandboxContext $context): void {
$booking = $context->booking->fresh();
if ($booking->status === BookingStatus::OfferSent) {
app(AcceptOffer::class)->handle($booking, $booking->offer_version);
}
}),
new ScenarioEvent('Zwei Tage vor der Anreise', fn (SandboxContext $context) => $context->travelTo($context->arrival()->subDays(2)->setTime(9, 0))),
new ScenarioEvent('Drei Tage nach der Abreise', fn (SandboxContext $context) => $context->travelTo($context->departure()->addDays(3)->setTime(9, 0))),
];
}
}
@@ -0,0 +1,57 @@
<?php
namespace App\Process\Tester\Scenarios;
use App\Actions\ContributeCaseFacts;
use App\Enums\FactSource;
use App\Enums\IntakeKind;
use App\Process\Tester\SandboxContext;
/**
* S02/S03/S04/S05: a request without address – clarification hold and data request run side by side, the hold
* expires, the guest answers later (by link or by e-mail), the offer follows; finally the offer's deadline passes.
*/
final class MissingAddress extends Scenario
{
public static function key(): string
{
return 'missing_address';
}
public static function label(): string
{
return 'Fehlende Anschrift, späte Antwort';
}
public static function description(): string
{
return 'Die Anfrage kommt ohne Anschrift: Rückfrage beim Gast und Klärungsreservierung laufen nebeneinander, die Reservierung läuft ab, der Gast antwortet später.';
}
public static function intakes(): array
{
return [IntakeKind::Inquiry];
}
public static function inputs(): array
{
return [
...parent::inputs(),
'answer_after_hours' => ['label' => 'Antwort des Gastes nach (Stunden)', 'default' => 26, 'type' => 'int'],
'answer_by' => ['label' => 'Antwort über', 'default' => 'link', 'type' => 'select', 'options' => ['link' => 'Link im Formular', 'email' => 'E-Mail (ausgewertete Angaben)']],
];
}
public function events(array $inputs): array
{
return [
new ScenarioEvent('Gast fragt ohne Anschrift an', fn (SandboxContext $context) => $context->request([])),
new ScenarioEvent('Zwei Stunden vergehen (Klärungsfrist)', fn (SandboxContext $context) => $context->travel(125)),
new ScenarioEvent('Gast antwortet mit seiner Anschrift', function (SandboxContext $context) use ($inputs): void {
$context->travel(max(0, (int) ($inputs['answer_after_hours'] ?? 26) * 60 - 125));
app(ContributeCaseFacts::class)->handle($context->booking->fresh(), ['guest.street' => 'Teststraße 1', 'guest.postal_code' => '18225', 'guest.city' => 'Kühlungsborn', 'guest.country' => 'DE'], ($inputs['answer_by'] ?? 'link') === 'email' ? FactSource::Email : FactSource::GuestLink);
}),
new ScenarioEvent('Die Angebotsfrist vergeht ohne Annahme', fn (SandboxContext $context) => $context->travel(73 * 60)),
];
}
}
@@ -0,0 +1,85 @@
<?php
namespace App\Process\Tester\Scenarios;
use App\Actions\ContributeCaseFacts;
use App\Actions\ProcessPortalMail;
use App\Actions\RecordPortalAmounts;
use App\Channels\Mail\PortalMail;
use App\Enums\FactSource;
use App\Enums\IntakeKind;
use App\Models\Booking;
use App\Process\Tester\SandboxContext;
use Carbon\CarbonImmutable;
/**
* S07/S08/S13: a booking binding at the portal arrives by e-mail through the same entry as the mailbox (twice:
* duplicate), guest details and the portal's amounts follow; optionally the portal reports a cancellation; then the
* stay and after departure.
*/
final class PortalBooking extends Scenario
{
public static function key(): string
{
return 'portal_booking';
}
public static function label(): string
{
return 'Feste Buchung über das Portal';
}
public static function description(): string
{
return 'Die Buchungsmail des Portals kommt (zweimal) an, Gastdaten und Portalbeträge folgen; auf Wunsch meldet das Portal eine Stornierung.';
}
public static function intakes(): array
{
return [IntakeKind::Booking];
}
public static function inputs(): array
{
return [
...parent::inputs(),
'portal_total' => ['label' => 'Gesamtpreis laut Portal (€)', 'default' => 980, 'type' => 'int'],
'cancellation' => ['label' => 'Portal meldet eine Stornierung', 'default' => false, 'type' => 'bool'],
];
}
public function events(array $inputs): array
{
$total = max(1, (int) ($inputs['portal_total'] ?? 980)) * 100;
$events = [
new ScenarioEvent('Buchungsmail des Portals kommt an', fn (SandboxContext $context) => $this->sendPortalMail($context, 'Neue Buchung: '.$context->property->name, $this->text($context))),
new ScenarioEvent('Dieselbe Buchungsmail kommt noch einmal', fn (SandboxContext $context) => $this->sendPortalMail($context, 'Neue Buchung: '.$context->property->name, $this->text($context))),
new ScenarioEvent('Gastdaten laut Portal', fn (SandboxContext $context) => app(ContributeCaseFacts::class)->handle($context->booking->fresh(), ['guest.first_name' => 'Testgast', 'guest.last_name' => 'Portal', 'guest.email' => 'portalgast@tester.invalid', 'booking.guests' => (string) $context->guests()], FactSource::PortalMail)),
new ScenarioEvent('Portal meldet Preis, Gastzahlung und angekündigte Auszahlung', fn (SandboxContext $context) => app(RecordPortalAmounts::class)->handle($context->booking->fresh(), $total, [['kind' => 'payout_announced', 'amount' => (int) round($total * 0.9)]], [['amount' => (int) round($total * 0.4), 'paid_on' => now()->toDateString()]], $context->channel->name)),
];
if ((bool) ($inputs['cancellation'] ?? false)) {
$events[] = new ScenarioEvent('Portal meldet eine Stornierung', fn (SandboxContext $context) => $this->sendPortalMail($context, 'Buchung storniert: '.$this->reference($context), 'Die Buchung vom '.$context->arrival()->format('d.m.Y').' bis '.$context->departure()->format('d.m.Y').' wurde storniert. Buchungsnummer: '.$this->reference($context)));
}
$events[] = new ScenarioEvent('Drei Tage nach der Abreise', fn (SandboxContext $context) => $context->travelTo($context->departure()->addDays(3)->setTime(9, 0)));
return $events;
}
private function reference(SandboxContext $context): string
{
return 'TEST-'.$context->arrival()->format('md');
}
private function text(SandboxContext $context): string
{
return "Gast: Testgast Portal\nAnreise: ".$context->arrival()->format('d.m.Y')."\nAbreise: ".$context->departure()->format('d.m.Y')."\nBuchungsnummer: ".$this->reference($context);
}
private function sendPortalMail(SandboxContext $context, string $subject, string $text): void
{
$senders = array_values(array_filter(array_map('trim', explode(',', (string) ($context->channel->setting('email_senders') ?? '')))));
$sender = 'buchung@'.($senders[0] ?? 'portal.invalid');
app(ProcessPortalMail::class)->handle(new PortalMail('<'.md5($subject).'@tester.invalid>', $sender, $subject, $text, CarbonImmutable::now()));
$context->booking = Booking::query()->latest('id')->first() ?? $context->booking;
}
}
@@ -0,0 +1,47 @@
<?php
namespace App\Process\Tester\Scenarios;
use App\Actions\ContributeCaseFacts;
use App\Actions\TakeOverPortalInquiry;
use App\Enums\FactSource;
use App\Enums\IntakeKind;
use App\Process\Tester\SandboxContext;
/**
* A2: a request of the portal – taken over like the portal's request mail, contact details from the portal, the
* address from the guest; then our own offer or information as the chosen model says.
*/
final class PortalInquiry extends Scenario
{
public static function key(): string
{
return 'portal_inquiry';
}
public static function label(): string
{
return 'Anfrage über das Portal';
}
public static function description(): string
{
return 'Das Portal leitet eine Anfrage weiter; Kontaktdaten kommen vom Portal, die Anschrift vom Gast.';
}
public static function intakes(): array
{
return [IntakeKind::Inquiry];
}
public function events(array $inputs): array
{
return [
new ScenarioEvent('Portal leitet eine Anfrage weiter', function (SandboxContext $context): void {
$context->booking = app(TakeOverPortalInquiry::class)->handle($context->channel, $context->arrival(), $context->departure(), 'ANF-'.$context->arrival()->format('md'));
}),
new ScenarioEvent('Kontaktdaten laut Portal', fn (SandboxContext $context) => app(ContributeCaseFacts::class)->handle($context->booking->fresh(), ['guest.first_name' => 'Testgast', 'guest.last_name' => 'Anfrage', 'guest.email' => 'anfrage@tester.invalid', 'booking.guests' => (string) $context->guests()], FactSource::PortalMail)),
new ScenarioEvent('Gast ergänzt seine Anschrift', fn (SandboxContext $context) => app(ContributeCaseFacts::class)->handle($context->booking->fresh(), ['guest.street' => 'Teststraße 1', 'guest.postal_code' => '18225', 'guest.city' => 'Kühlungsborn', 'guest.country' => 'DE'], FactSource::GuestLink)),
];
}
}
@@ -0,0 +1,64 @@
<?php
namespace App\Process\Tester\Scenarios;
use App\Actions\SendOffer;
use App\Enums\BookingStatus;
use App\Enums\IntakeKind;
use App\Models\Booking;
use App\Models\Guest;
use App\Process\Tester\SandboxContext;
/**
* S09/S10: a returning guest (a synthetic former stay in the run's own data) asks again – with the loyalty variant the
* status check comes first and the discount line enters the price before it is fixed. Architecture proof; the rules
* are test assumptions.
*/
final class ReturningGuest extends Scenario
{
public static function key(): string
{
return 'returning_guest';
}
public static function label(): string
{
return 'Stammgast fragt an (Architekturnachweis)';
}
public static function description(): string
{
return 'Ein Gast mit einem früheren Aufenthalt fragt erneut an. Mit der Variante „Stammgastrabatt“ wird der Status geprüft und der Rabatt vor der Preisfestlegung eingerechnet.';
}
public static function intakes(): array
{
return [IntakeKind::Inquiry];
}
public static function inputs(): array
{
return [...parent::inputs(), 'returning' => ['label' => 'Gast war schon einmal da', 'default' => true, 'type' => 'bool']];
}
public function events(array $inputs): array
{
return [
new ScenarioEvent('Früherer Aufenthalt (nur in den Testdaten)', function (SandboxContext $context) use ($inputs): void {
if (! (bool) ($inputs['returning'] ?? true)) {
return;
}
$guest = Guest::query()->create(['tenant_id' => $context->property->tenant_id, 'first_name' => 'Testgast', 'last_name' => 'Sandbox', 'email' => 'gast@tester.invalid']);
Booking::query()->create(['tenant_id' => $context->property->tenant_id, 'property_id' => $context->property->id, 'guest_id' => $guest->id, 'status' => BookingStatus::Completed, 'intake' => 'inquiry',
'arrival' => now()->subYear()->toDateString(), 'departure' => now()->subYear()->addDays(7)->toDateString(), 'guests' => 2, 'total' => 80000, 'deposit' => 20000, 'completed_at' => now()->subYear()->addDays(8)]);
}),
new ScenarioEvent('Gast fragt mit allen Angaben an', fn (SandboxContext $context) => $context->request(['street' => 'Teststraße 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'])),
new ScenarioEvent('Sie senden das Angebot (falls es nicht automatisch ging)', function (SandboxContext $context): void {
$booking = $context->booking->fresh();
if ($booking->status === BookingStatus::Reserved && $booking->offer_version === 0 && $booking->process()->preReservation()) {
app(SendOffer::class)->handle($booking);
}
}),
];
}
}
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace App\Process\Tester\Scenarios;
use App\Enums\IntakeKind;
/**
* A predefined tester scenario (decision E9): a fixed sequence of events through the same entry points as the real
* application; the landlord may change its inputs (dates, guests, missing details, returning guest, kind of failure),
* never the sequence.
*/
abstract class Scenario
{
abstract public static function key(): string;
abstract public static function label(): string;
abstract public static function description(): string;
/** @return list<IntakeKind> */
abstract public static function intakes(): array;
/**
* Inputs the landlord may change, with their defaults.
*
* @return array<string, array{label: string, default: string|int|bool, type: 'date'|'int'|'bool'|'select', options?: array<string, string>}>
*/
public static function inputs(): array
{
return [
'arrival' => ['label' => 'Anreise', 'default' => '+21 days', 'type' => 'date'],
'nights' => ['label' => 'Nächte', 'default' => 4, 'type' => 'int'],
'guests' => ['label' => 'Personen', 'default' => 2, 'type' => 'int'],
];
}
/**
* @param array<string, mixed> $inputs
* @return list<ScenarioEvent>
*/
abstract public function events(array $inputs): array;
}
@@ -0,0 +1,17 @@
<?php
namespace App\Process\Tester\Scenarios;
use App\Process\Tester\SandboxContext;
use Closure;
/**
* One event of a scenario: what happens (in plain words) and how – through the entry point the real application uses.
*/
final readonly class ScenarioEvent
{
/**
* @param Closure(SandboxContext): void $run
*/
public function __construct(public string $label, public Closure $run) {}
}