U-A: process:check/impact/fingerprint, Modulmatrix, Modul-Vertragstest, O4-Aussetzung der Außenwirkungen (I-002), Bewertungsbitte je Kanal abschaltbar

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-04 14:53:08 +01:00
1 parent 7e22e12cac
commit d695566a7a
9 files changed
+466 -3

No files matched your search

+6 -1
View File
@@ -6,6 +6,8 @@
use App\Enums\Responsibility;
use App\Mail\ReviewRequest;
use App\Models\Booking;
use App\Process\OutwardSuspension;
use App\Process\ProcessPlan;
use Illuminate\Support\Facades\Mail;
/**
@@ -27,7 +29,10 @@ public function handle(): int
->whereHas('guest', fn ($query) => $query->whereNull('anonymized_at')->whereNotNull('email')->where('email', '!=', ''))
->with('guest')
->get()
->filter(fn (Booking $booking): bool => $booking->process()->guestMessages() === Responsibility::Landlord);
->filter(fn (Booking $booking): bool => $booking->process()->guestMessages() === Responsibility::Landlord
// The step can be switched off per channel (Kanal › Ablauf); an open portal report holds it back (O4).
&& ProcessPlan::of($booking)->enabled('review.request')
&& OutwardSuspension::reason($booking) === null);
foreach ($bookings as $booking) {
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new ReviewRequest($booking));
+4 -1
View File
@@ -9,6 +9,7 @@
use App\Mail\ArrivalInformation;
use App\Models\Booking;
use App\Models\BookingTask;
use App\Process\OutwardSuspension;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Mail;
@@ -63,7 +64,9 @@ public function handle(): array
->whereDate('arrival', '>=', $today)
->whereDate('arrival', '<=', $today->copy()->addDays(self::ARRIVAL_INFO_MAX_DAYS_BEFORE)))
->filter(fn (Booking $booking): bool => $booking->process()->guestMessages() === Responsibility::Landlord
&& $booking->arrival->lessThanOrEqualTo($today->copy()->addDays($booking->process()->arrivalInfoDaysBefore())));
&& $booking->arrival->lessThanOrEqualTo($today->copy()->addDays($booking->process()->arrivalInfoDaysBefore()))
// Decision O4: an open portal report of a cancellation or change holds the message back until clarified.
&& OutwardSuspension::reason($booking) === null);
foreach ($arrivals as $booking) {
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new ArrivalInformation($booking));
$booking->update(['arrival_info_sent_at' => now()]);
+104
View File
@@ -0,0 +1,104 @@
<?php
namespace App\Console\Commands;
use App\Enums\BookingStatus;
use App\Models\Booking;
use App\Process\ProcessCatalogue;
use App\Process\ProcessPlan;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
/**
* Checks the process catalogue (docs/Prozessarchitektur/Architektur/05 §2.2) and, with --cases, that every frozen plan
* of every case (open or finished, every landlord) can still be read: model versions and module versions registered or
* declared compatible (requirement T3). With --matrix it writes MODULMATRIX.md.
*/
#[Signature('process:check {--cases : also check the frozen plans of all cases} {--matrix : write docs/Prozessarchitektur/Architektur/MODULMATRIX.md}')]
#[Description('Check the process catalogue (modules, models, dependencies, tester-only parts) and the frozen plans of the cases')]
class ProcessCheck extends Command
{
public function handle(ProcessCatalogue $catalogue): int
{
$problems = $catalogue->problems();
if ($this->option('cases')) {
$problems = [...$problems, ...$this->cases($catalogue)];
}
if ($this->option('matrix')) {
$path = base_path('docs/Prozessarchitektur/Architektur/MODULMATRIX.md');
file_put_contents($path, $this->matrix($catalogue));
$this->info('Modulmatrix geschrieben: '.$path);
}
foreach ($problems as $problem) {
$this->error($problem);
}
if ($problems === []) {
$this->info(count($catalogue->modules()).' Module, '.count($catalogue->modelVersions()).' Modelle: ohne Befund.');
}
return $problems === [] ? self::SUCCESS : self::FAILURE;
}
/**
* @return list<string>
*/
private function cases(ProcessCatalogue $catalogue): array
{
$problems = [];
Booking::withoutGlobalScopes()->select(['id', 'reference', 'profile', 'status'])->whereNotNull('profile')->lazyById()->each(function (Booking $booking) use ($catalogue, &$problems): void {
$plan = (array) (($booking->profile ?? [])['plan'] ?? []);
if ($plan === []) {
return;
}
$frozen = ProcessPlan::fromArray($plan);
if (! $catalogue->hasModel($frozen->model)) {
$problems[] = "Vorgang {$booking->reference}: Modell {$frozen->model} ist nicht mehr registriert.";
} elseif (! $catalogue->hasModel($frozen->model, $frozen->modelVersion)) {
$problems[] = "Vorgang {$booking->reference}: Modellversion {$frozen->reference()} fehlt im Register (T3: Versionen nicht entfernen, solange Vorgänge sie tragen).";
}
foreach ($frozen->modules as $key => $version) {
if (! $catalogue->serves($key, $version) && ! in_array($booking->status, [BookingStatus::Cancelled, BookingStatus::Declined, BookingStatus::Expired, BookingStatus::Completed], true)) {
$problems[] = "Offener Vorgang {$booking->reference}: Modul {$key}@{$version} wird nicht mehr bedient.";
}
}
});
return $problems;
}
private function matrix(ProcessCatalogue $catalogue): string
{
$models = $catalogue->models();
$lines = [
'# Modulmatrix (erzeugt)',
'',
'Erzeugt von `php artisan process:check --matrix` aus `config/process.php` – nicht von Hand ändern. Spalten: Modelle (Standardablauf; `V` = nur in einer Variante).',
'',
'| Modul | Version | Phase | Aktivierung | Verfügbarkeit | hart abhängig von | '.implode(' | ', array_keys($models)).' | Testgruppe |',
'|'.str_repeat('---|', 7 + count($models)),
];
foreach ($catalogue->modules() as $key => $class) {
$definition = $class::definition();
$cells = array_map(function ($model) use ($key): string {
if (in_array($key, $model->modules('standard'), true)) {
return '●';
}
foreach ($model->variants() as $variant) {
if (in_array($key, $model->modules($variant->key), true)) {
return 'V';
}
}
return '';
}, $models);
$hard = implode(', ', array_map(fn ($dependency): string => $dependency->module, array_filter($definition->requires, fn ($dependency): bool => $dependency->hard)));
$lines[] = "| `{$key}` | {$class::version()} | {$definition->phase} | {$definition->toggle} | {$definition->availability} | {$hard} | ".implode(' | ', $cells)." | `module:{$key}` |";
}
return implode("\n", $lines)."\n";
}
}
@@ -0,0 +1,34 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* Checksums of what an update must never change by itself (docs/Prozessarchitektur/Architektur/06 U-F, step 6):
* the cases with their contract data and frozen profile, the channels' process configuration and the calendar blocks.
* Run before and after a deployment and compare. Only reads; prints no personal data.
*/
#[Signature('process:fingerprint')]
#[Description('Print checksums of cases, channel configurations and calendar blocks (compare before/after a deployment)')]
class ProcessFingerprint extends Command
{
public function handle(): int
{
$hash = fn ($query): string => md5($query->get()->map(fn (object $row): string => (string) json_encode($row))->implode("\n"));
$this->line((string) json_encode([
'bookings' => DB::table('bookings')->count(),
'channels' => DB::table('channels')->count(),
'blocked_periods' => DB::table('blocked_periods')->count(),
'h_bookings' => $hash(DB::table('bookings')->orderBy('id')->select('id', 'status', 'profile', 'total', 'quote', 'offer_terms', 'acceptance', 'arrival', 'departure', 'hold_expires_at', 'deposit_due_on', 'balance_due_on')),
'h_overrides' => $hash(DB::table('channels')->orderBy('id')->select('id', 'process_overrides', 'booking_model', 'case_intake')),
'h_blocks' => $hash(DB::table('blocked_periods')->orderBy('id')->select('id', 'starts_on', 'ends_on', 'source', 'channel_id', 'linked_booking_id', 'deleted_at')),
], JSON_PRETTY_PRINT));
return self::SUCCESS;
}
}
+62
View File
@@ -0,0 +1,62 @@
<?php
namespace App\Console\Commands;
use App\Models\Channel;
use App\Process\Modules\ContributesToPrice;
use App\Process\Modules\RunsAutomatically;
use App\Process\ProcessCatalogue;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
/**
* Change impact of a module (docs/Prozessarchitektur/Architektur/05 §2): models and variants with their case types,
* extension points, dependent modules, parameters, whether it reads frozen contract data, the number of channels that
* chose an affected model (count only) and the test groups to run.
*/
#[Signature('process:impact {module : key of the module, e.g. offer.binding}')]
#[Description('Show which models, case types, dependent modules, channels and test groups a change of a process module affects')]
class ProcessImpact extends Command
{
public function handle(ProcessCatalogue $catalogue): int
{
$key = (string) $this->argument('module');
if (! $catalogue->hasModule($key)) {
$this->error("Unbekanntes Modul {$key}. Registriert: ".implode(', ', array_keys($catalogue->modules())));
return self::FAILURE;
}
$class = $catalogue->modules()[$key];
$definition = $class::definition();
$uses = [];
foreach ($catalogue->models() as $modelKey => $model) {
foreach ($model->variants() as $variant) {
if (in_array($key, $model->modules($variant->key), true)) {
$uses[] = $modelKey.($variant->key === 'standard' ? '' : ':'.$variant->key).' ('.implode('/', array_map(fn ($type): string => strtoupper($type->value), $model::caseTypes())).')';
}
}
}
$dependents = array_keys(array_filter($catalogue->modules(), fn (string $other): bool => collect($other::definition()->requires)->contains(fn ($dependency): bool => $dependency->module === $key)));
$modelKeys = array_map(fn (string $use): string => explode(' ', explode(':', $use)[0])[0], $uses);
$channels = Channel::withoutGlobalScopes()->get(['process_overrides'])->filter(fn (Channel $channel): bool => collect((array) $channel->process_overrides)->contains(fn ($config): bool => in_array($config['model'] ?? null, $modelKeys, true)))->count();
$this->table(['', $key.' v'.$class::version()], [
['Aufgabe', $definition->purpose],
['Phase / Aktivierung', $definition->phase.' / '.$definition->toggle.' / '.$definition->availability],
['Modelle', implode(', ', $uses) ?: '–'],
['Erweiterungspunkte', implode(', ', $definition->points) ?: 'fester Platz im Modell'],
['Benötigt', implode(', ', array_map(fn ($dependency): string => $dependency->module.($dependency->hard ? ' (hart)' : ' (weich)'), $definition->requires)) ?: '–'],
['Benötigt von', implode(', ', $dependents) ?: '–'],
['Läuft automatisch', is_subclass_of($class, RunsAutomatically::class) ? 'ja, Auslöser: '.implode(', ', $definition->triggers) : 'nein'],
['Preisbeitrag', is_subclass_of($class, ContributesToPrice::class) ? 'ja (CasePricing, nur vor Verbindlichkeit)' : 'nein'],
['Wertet Vertragsdaten aus', $definition->readsContractData ? 'ja – Bestandsfall-Test Pflicht (--group=ongoing)' : 'nein'],
['Parameter', implode(', ', array_map(fn ($parameter): string => is_string($parameter) ? $parameter : $parameter->value, $definition->parameters)) ?: '–'],
['Kanäle mit gewähltem Modell', (string) $channels],
['Tests', "--group=module:{$key} --group=golden --group=ongoing --group=runner"],
]);
return self::SUCCESS;
}
}
@@ -0,0 +1,31 @@
# Modulmatrix (erzeugt)
Erzeugt von `php artisan process:check --matrix` aus `config/process.php` – nicht von Hand ändern. Spalten: Modelle (Standardablauf; `V` = nur in einer Variante).
| Modul | Version | Phase | Aktivierung | Verfügbarkeit | hart abhängig von | a1.offer | a1.information | a2.offer | a2.information | a3.portal_booking | a4.portal_booking | a5.portal_booking | a6.internal | Testgruppe |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| `intake.record` | 1 | P01 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | `module:intake.record` |
| `guest.details` | 1 | P01 | mandatory | production | intake.record | ● | ● | ● | ● | ● | ● | ● | | `module:guest.details` |
| `guest.data_request` | 1 | P01 | optional | production | intake.record | ● | ● | ● | ● | ● | ● | ● | | `module:guest.data_request` |
| `hold` | 1 | P01 | conditional | production | intake.record | ● | ● | ● | ● | | | | | `module:hold` |
| `availability.check` | 1 | P01 | mandatory | production | | ● | ● | ● | ● | | | | | `module:availability.check` |
| `binding.portal` | 1 | P02 | mandatory | production | intake.record | | | | | ● | ● | ● | | `module:binding.portal` |
| `channels.block` | 1 | P02 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | `module:channels.block` |
| `offer.information` | 1 | P02 | mandatory | production | intake.record | ● | ● | ● | ● | | | | | `module:offer.information` |
| `offer.binding` | 2 | P02 | mandatory | production | guest.details, availability.check | ● | ● | ● | ● | | | | | `module:offer.binding` |
| `offer.acceptance` | 1 | P02 | mandatory | production | offer.binding | ● | ● | ● | ● | | | | | `module:offer.acceptance` |
| `documents.send` | 1 | P03 | mandatory | production | guest.details | ● | ● | ● | ● | ● | ● | ● | | `module:documents.send` |
| `documents.stay_confirmation` | 1 | P03 | optional | production | | | | | | | | | ● | `module:documents.stay_confirmation` |
| `case.tasks` | 1 | P03 | event_driven | production | | ● | ● | ● | ● | ● | ● | ● | ● | `module:case.tasks` |
| `change.proposal` | 1 | P03 | event_driven | production | | ● | ● | ● | ● | ● | ● | ● | | `module:change.proposal` |
| `case.closure` | 1 | P05 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | `module:case.closure` |
| `case.settlement` | 1 | P05 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | `module:case.settlement` |
| `payments.monitor` | 1 | P03 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | | `module:payments.monitor` |
| `portal.payout` | 1 | P03 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | | `module:portal.payout` |
| `payments.internal` | 1 | P03 | conditional | production | | | | | | | | | ● | `module:payments.internal` |
| `arrival.details` | 1 | P04 | optional | production | | ● | ● | ● | ● | ● | ● | ● | | `module:arrival.details` |
| `arrival.info` | 1 | P04 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | | `module:arrival.info` |
| `stay` | 1 | P04 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | `module:stay` |
| `review.request` | 1 | P05 | optional | production | stay | ● | ● | ● | ● | ● | ● | ● | | `module:review.request` |
| `guest.loyalty_status` | 1 | P01 | optional | tester_only | guest.details | V | | | | | | | | `module:guest.loyalty_status` |
| `pricing.loyalty_discount` | 1 | P02 | optional | tester_only | guest.loyalty_status | V | | | | | | | | `module:pricing.loyalty_discount` |
+4 -1
View File
@@ -10,7 +10,10 @@ prepare = [
["php", "-r", "copy('.env.example', '.env');"],
["php", "artisan", "key:generate", "--no-interaction"],
]
test = [["php", "-d", "memory_limit=512M", "vendor/bin/phpunit", "--testsuite=Feature", "--no-progress"]]
test = [
["php", "artisan", "process:check", "--no-interaction"],
["php", "-d", "memory_limit=512M", "vendor/bin/phpunit", "--testsuite=Feature", "--no-progress"],
]
finalize = [
["composer", "install", "--no-dev", "--prefer-dist", "--optimize-autoloader", "--no-interaction", "--no-progress"],
["php", "artisan", "optimize:clear", "--no-interaction"],
@@ -0,0 +1,109 @@
<?php
namespace Tests\Feature\Process;
use App\Enums\BookingStatus;
use App\Enums\ProcessSetting;
use App\Models\Booking;
use App\Models\Channel;
use App\Models\Property;
use App\Pricing\PriceCalculator;
use App\Pricing\StayRequest;
use App\Process\CaseContext;
use App\Process\Modules\ContributesToPrice;
use App\Process\Modules\ModuleDefinition;
use App\Process\Modules\RunsAutomatically;
use App\Process\ProcessCatalogue;
use App\Process\ProcessPlan;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;
/**
* The generic contract test of every registered module (docs/Prozessarchitektur/Architektur/02 §3.2): its definition is
* complete and consistent, and its reading methods (applies, activities, state, due, blockers, price lines) never
* write – for cases of every archetype and status. What a run may cause is checked per module in the runner, module and
* sandbox tests; this test only promises what it checks.
*/
#[Group('contract')]
class ModuleContractTest extends TestCase
{
use RefreshDatabase;
public function test_every_module_has_a_complete_definition(): void
{
$catalogue = app(ProcessCatalogue::class);
$phases = ['P01', 'P02', 'P03', 'P04', 'P05'];
$toggles = [ModuleDefinition::TOGGLE_MANDATORY, ModuleDefinition::TOGGLE_OPTIONAL, ModuleDefinition::TOGGLE_CONDITIONAL, ModuleDefinition::TOGGLE_EVENT_DRIVEN];
$effects = ['case_write', 'guest_mail', 'landlord_mail', 'document', 'calendar_hold', 'channel_task', 'network'];
foreach ($catalogue->modules() as $key => $class) {
$definition = $class::definition();
$this->assertMatchesRegularExpression('/^[a-z0-9_]+(\.[a-z0-9_]+)*$/', $key);
$this->assertNotSame('', trim($definition->label), "{$key}: label");
$this->assertNotSame('', trim($definition->purpose), "{$key}: purpose");
$this->assertContains($definition->phase, $phases, "{$key}: phase");
$this->assertContains($definition->toggle, $toggles, "{$key}: toggle");
$this->assertSame([], array_diff($definition->effects, $effects), "{$key}: unknown effect kinds");
$this->assertGreaterThanOrEqual(1, $class::version());
foreach ($definition->parameters as $parameter) {
$this->assertTrue($parameter instanceof ProcessSetting || (is_string($parameter) && $parameter !== ''), "{$key}: parameter");
}
if (is_subclass_of($class, RunsAutomatically::class)) {
$this->assertNotSame([], $definition->modes, "{$key}: an automatic module names its modes");
$this->assertNotSame([], $definition->triggers, "{$key}: an automatic module names its triggers");
}
if ($definition->isTesterOnly()) {
$this->assertNotSame([], $definition->points, "{$key}: a tester-only module sits at an extension point");
}
}
}
public function test_reading_methods_never_write(): void
{
$this->travelTo(CarbonImmutable::parse('2026-10-23 10:00'));
$this->seed(PropertySeeder::class);
$property = Property::sole();
$portal = Channel::factory()->for($property)->create(['booking_model' => 'portal_booking', 'process_overrides' => ['booking' => ['payments' => 'portal']]]);
$cases = [];
foreach ([BookingStatus::Reserved, BookingStatus::OfferSent, BookingStatus::Confirmed, BookingStatus::Completed, BookingStatus::Cancelled] as $index => $status) {
$cases[] = Booking::factory()->for($property)->create(['status' => $status, 'intake' => 'inquiry', 'arrival' => now()->addDays(40 + $index * 10)->toDateString(), 'departure' => now()->addDays(44 + $index * 10)->toDateString(), 'hold_expires_at' => now()->addDay()]);
$cases[] = Booking::factory()->for($property)->create(['status' => $status === BookingStatus::Reserved ? BookingStatus::Confirmed : $status, 'intake' => 'booking', 'import_channel_id' => $portal->id, 'origin_channel_id' => $portal->id, 'arrival' => now()->addDays(100 + $index * 10)->toDateString(), 'departure' => now()->addDays(104 + $index * 10)->toDateString()]);
}
$catalogue = app(ProcessCatalogue::class);
$writes = [];
DB::listen(function (QueryExecuted $query) use (&$writes): void {
if (preg_match('/^\s*(insert|update|delete|replace)\b/i', $query->sql) === 1) {
$writes[] = $query->sql;
}
});
foreach ($cases as $booking) {
$booking = $booking->fresh();
// Every module against every case: also modules of other models must read without side effects.
$plan = new ProcessPlan('a1.offer', 1, 'loyalty', array_map(fn (string $class): int => $class::version(), $catalogue->modules()), [], ProcessPlan::TESTER);
$context = new CaseContext($booking, $plan);
foreach (array_keys($catalogue->modules()) as $key) {
$module = $catalogue->module($key);
$module->applies($context);
$module->activities($context);
$module->state($context);
if ($module instanceof RunsAutomatically) {
$module->due($context);
$module->blockers($context);
$module->isOutward();
}
if ($module instanceof ContributesToPrice && $booking->arrival->lessThan(now()->addDays(55))) {
$module->priceLines($context, app(PriceCalculator::class)->calculate($property, new StayRequest($booking->arrival, $booking->departure, 2)));
}
}
}
$this->assertSame([], $writes, 'reading methods of modules must not write');
}
}
@@ -0,0 +1,112 @@
<?php
namespace Tests\Feature\Process;
use App\Actions\ContributeCaseFacts;
use App\Actions\ProcessPortalMail;
use App\Actions\SendBookingReminders;
use App\Actions\TakeOverExternalBooking;
use App\Channels\Mail\PortalMail;
use App\Enums\BookingStatus;
use App\Enums\BookingTaskKind;
use App\Enums\BookingTaskStatus;
use App\Enums\FactSource;
use App\Models\Booking;
use App\Models\BookingTask;
use App\Models\Channel;
use App\Models\Property;
use App\Process\CaseAutomation;
use App\Process\OutwardSuspension;
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\Mail\MailManager;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;
/**
* Decision O4 (intended deviation I-002): an open portal report of a cancellation or change, reliably assigned to a
* case, holds back the automatic messages it could make wrong – documents, arrival information, review request – until
* the landlord has clarified it. Internal work goes on, the booking itself is never changed by the report, and
* unassigned portal mails stop nothing.
*/
#[Group('runner')]
class PortalReportSuspendsAutomationTest extends TestCase
{
use RefreshDatabase;
private Property $property;
private Channel $portal;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-23 18:00'));
$this->seed([PropertySeeder::class, SiteSeeder::class]);
$this->property = Property::sole();
Storage::fake('local');
Content::save(['contract.terms' => '<p>Echte Bedingungen</p>', 'stay.cancellation' => '<p>Echtes Storno</p>']);
config(['mail.default' => 'array']);
Mail::swap(new MailManager($this->app));
Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051', 'test_recipient' => 'test@example.org', 'process_defaults' => ['processing' => 'automatic']]);
Http::preventStrayRequests();
$this->portal = Channel::factory()->for($this->property)->create(['name' => 'Destination Solutions', 'booking_model' => 'portal_booking', 'import_enabled' => false, 'settings' => ['import_url' => 'https://ds.example/a.ics', 'email_senders' => 'ds.example']]);
}
public function test_documents_wait_while_a_cancellation_report_is_open_and_go_after_clarification(): void
{
$booking = app(TakeOverExternalBooking::class)->handle($this->property, $this->portal, CarbonImmutable::parse('2026-12-05'), CarbonImmutable::parse('2026-12-12'), ['portal_reference' => 'DS-9', 'portal_total' => 98000, 'guests' => 2]);
$task = $this->report($booking);
app(ContributeCaseFacts::class)->handle($booking->fresh(), ['guest.first_name' => 'Dora', 'guest.last_name' => 'Gast', 'guest.email' => 'dora@example.org'], FactSource::PortalMail);
$booking->refresh();
$this->assertNull($booking->confirmation_sent_at, 'no documents while the report is open');
$this->assertSame(BookingStatus::Confirmed, $booking->status, 'the report never changes the booking');
$held = app(CaseAutomation::class)->advance($booking->fresh());
$this->assertSame([OutwardSuspension::reason($booking)], $held, 'the documents wait only for the clarification');
$task->update(['status' => BookingTaskStatus::Done, 'completed_at' => now(), 'note' => 'Portal bestätigt: keine Stornierung']);
$held = app(CaseAutomation::class)->advance($booking->fresh());
// After clarification the step is evaluated from the case's current state again: here the documents' own
// release rules (portal template, released texts) decide, no longer the report.
$this->assertNotContains(OutwardSuspension::reason($booking), $held);
$this->assertStringContainsString('Arbeitsfassung', implode(' ', $held));
}
public function test_arrival_information_waits_but_internal_tasks_go_on(): void
{
$booking = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => now()->addDays(2)->toDateString(), 'departure' => now()->addDays(6)->toDateString(), 'deposit_due_on' => now()->subDay()->toDateString(), 'confirmed_at' => now()]);
$this->report($booking);
app(SendBookingReminders::class)->handle();
$this->assertNull($booking->fresh()->arrival_info_sent_at);
$this->assertTrue(BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::DepositReminder)->exists(), 'internal tasks are not blocked');
}
public function test_an_unassigned_portal_mail_suspends_nothing(): void
{
$booking = Booking::factory()->for($this->property)->create(['status' => BookingStatus::Confirmed, 'arrival' => now()->addDays(2)->toDateString(), 'departure' => now()->addDays(6)->toDateString(), 'confirmed_at' => now()]);
app(ProcessPortalMail::class)->handle(new PortalMail('<x@ds.example>', 'noreply@ds.example', 'Buchung storniert: UNBEKANNT-1', 'Die Buchung vom 01.03.2027 bis 05.03.2027 wurde storniert.', CarbonImmutable::now()));
app(SendBookingReminders::class)->handle();
$this->assertNull(OutwardSuspension::reason($booking));
$this->assertNotNull($booking->fresh()->arrival_info_sent_at);
}
private function report(Booking $booking): BookingTask
{
return BookingTask::query()->create(['booking_id' => $booking->id, 'kind' => BookingTaskKind::PortalCancellationReported, 'status' => BookingTaskStatus::Open, 'title' => 'Portal meldet Stornierung']);
}
}