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

@@ -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']);
}
}