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

+186
View File
@@ -0,0 +1,186 @@
<?php
namespace Tests\Feature\Process;
use App\Enums\IntakeKind;
use App\Filament\Resources\Channels\Pages\ChannelProcess;
use App\Filament\Resources\Channels\Pages\ChannelProcessTest;
use App\Models\Booking;
use App\Models\Channel;
use App\Models\ProcessTestRun;
use App\Models\Property;
use App\Models\User;
use App\Process\Tester\ProcessSandbox;
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\Mail;
use Illuminate\Support\Facades\Process;
use Livewire\Livewire;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;
/**
* Package U-D: the process tester plays scenarios in a process of its own with the same business logic (T01, T02,
* T05) and leaves the real data untouched (T03).
*/
#[Group('sandbox')]
class ProcessTesterTest extends TestCase
{
use RefreshDatabase;
private Property $property;
private User $user;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-23 10:00'));
$this->seed([PropertySeeder::class, SiteSeeder::class]);
$this->property = Property::sole();
Content::save(['contract.terms' => '<p>Echte Bedingungen</p>', 'stay.cancellation' => '<p>Echtes Storno</p>']);
Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051', 'test_recipient' => 'vermieter@example.org', 'process_defaults' => ['processing' => 'automatic', 'clarification_hold_auto_minutes' => 120, 'data_request_mode' => 'automatic']]);
$this->user = User::factory()->create();
self::template();
}
public static function template(): void
{
$template = storage_path('app/sandbox/template.sqlite');
$newest = max(array_map('filemtime', glob(database_path('migrations/*.php'))));
if (! is_file($template) || filemtime($template) < $newest) {
// A fresh process, as at deployment (the migrator binds the schema of the process that runs it).
Process::path(base_path())->timeout(120)->run([PHP_BINARY, 'artisan', 'process:sandbox-template'])->throw();
}
}
public function test_a_scenario_runs_isolated_with_the_real_business_logic_and_leaves_no_trace(): void
{
Mail::fake();
$website = Channel::websiteOf($this->property);
$run = app(ProcessSandbox::class)->run($website, IntakeKind::Inquiry, ['model' => 'a1.offer'], 'missing_address', ['arrival' => '2026-11-07', 'nights' => 3, 'guests' => 2], 3, $this->user);
$report = $run->report;
$this->assertNull($report['aborted'] ?? null, json_encode($report));
$this->assertSame(ProcessTestRun::COMPLETED, $run->outcome);
$this->assertCount(3, $report['timeline']);
$this->assertSame(['a1.offer', 1, 'A1'], [$report['plan']['model'], $report['plan']['version'], $report['plan']['case_type']]);
// Same logic as the real case: data request and clarification hold, later the offer.
[$request, $expired, $answer] = $report['timeline'];
$this->assertStringContainsString('reserviert', $request['situation']);
$this->assertContains('tester@sandbox.invalid', array_column($request['mails'], 'to'), 'mails are simulated and go to the test address');
$this->assertSame('Angebot gesendet', $answer['status']);
$this->assertStringContainsString('Angebot', implode(' ', array_column($answer['mails'], 'subject')));
$this->assertSame([], $report['violations']);
// Nothing reached the real data: no case, no mail.
$this->assertSame(0, Booking::query()->count());
Mail::assertNothingSent();
$this->assertDirectoryDoesNotExist(storage_path('app/sandbox/runs/'.$run->id));
}
public function test_a_run_with_the_same_snapshot_gives_the_same_report(): void
{
$website = Channel::websiteOf($this->property);
$inputs = ['arrival' => '2026-11-07', 'nights' => 3, 'guests' => 2];
$first = app(ProcessSandbox::class)->run($website, IntakeKind::Inquiry, ['model' => 'a1.offer'], 'complete_request', $inputs, 3, $this->user);
$second = app(ProcessSandbox::class)->run($website, IntakeKind::Inquiry, ['model' => 'a1.offer'], 'complete_request', $inputs, 3, $this->user);
$strip = fn (array $report): array => array_map(fn (array $event): array => array_diff_key($event, ['effects' => true]), $report['timeline']);
$this->assertSame($strip($first->report), $strip($second->report));
}
public function test_the_loyalty_variant_runs_in_the_tester_only(): void
{
$website = Channel::websiteOf($this->property);
$run = app(ProcessSandbox::class)->run($website, IntakeKind::Inquiry, ['model' => 'a1.offer', 'variant' => 'loyalty'], 'returning_guest', ['arrival' => '2026-11-07', 'nights' => 3, 'guests' => 2], 3, $this->user);
$this->assertNull($run->report['aborted'] ?? null, json_encode($run->report));
$this->assertSame('loyalty', $run->report['plan']['variant']);
$timeline = $run->report['timeline'];
$lines = array_column(end($timeline)['price']['lines'], 'label');
$this->assertNotEmpty(array_filter($lines, fn (string $label): bool => str_starts_with($label, 'Stammgastrabatt')), 'the discount enters the price before it is fixed');
$this->assertNull($website->fresh()->process_overrides['inquiry']['variant'] ?? null, 'nothing was saved');
}
/** S07/S08/S13: a portal booking by mail (twice), portal amounts and a cancellation report – A4 of FeWo-direkt */
public function test_a_portal_booking_scenario_with_cancellation_report(): void
{
$fewo = Channel::factory()->for($this->property)->create(['name' => 'FeWo-direkt', 'booking_model' => 'mixed', 'status' => 'setup', 'is_active' => false, 'import_enabled' => false, 'settings' => ['import_url' => 'https://www.fewo-direkt.de/x.ics']]);
$run = app(ProcessSandbox::class)->run($fewo, IntakeKind::Booking, ['model' => 'a4.portal_booking', 'settings' => ['guest_messages' => 'portal']], 'portal_booking', ['arrival' => '2026-11-14', 'nights' => 4, 'guests' => 2, 'portal_total' => 980, 'cancellation' => true], 6, $this->user);
$report = $run->report;
$this->assertNull($report['aborted'] ?? null, json_encode($report));
$this->assertSame(['a4.portal_booking', 'A4'], [$report['plan']['model'], $report['plan']['case_type']]);
[$mail, $repeated, , $amounts, $cancellation] = $report['timeline'];
$this->assertSame('Bestätigt', $mail['status'] ?? null, json_encode($mail));
$this->assertSame($mail['situation'], $repeated['situation'], 'the same mail twice: one case');
$this->assertStringContainsString('laut Portal', implode(' ', array_column($amounts['activities'], 'detail')));
$this->assertContains('Das Portal meldet eine Stornierung – bitte prüfen', array_column($cancellation['activities'], 'label'));
$this->assertSame('Bestätigt', $cancellation['status'], 'the report never cancels');
$this->assertSame(0, Booking::query()->count());
$this->assertFalse((bool) $fewo->fresh()->is_active, 'the real channel is unchanged');
}
/** S12/T06: a failing mail server leaves the case in a defined state */
public function test_a_mail_failure_keeps_the_case(): void
{
$run = app(ProcessSandbox::class)->run(Channel::websiteOf($this->property), IntakeKind::Inquiry, ['model' => 'a1.offer'], 'mail_failure', ['arrival' => '2026-11-07', 'nights' => 3, 'guests' => 2], 2, $this->user);
$request = $run->report['timeline'][1];
$this->assertNull($run->report['aborted'] ?? null);
// v0.11 behaviour: the offer is saved even if its mail fails (SendOffer reports it); nothing went out.
$this->assertSame('Angebot gesendet', $request['status'], 'the case is kept');
$this->assertSame([], $request['mails'], 'no mail went out');
}
/** T01/T02: from the configurator with the unsaved draft, step by step, with a readable report */
public function test_the_landlord_tests_the_unsaved_draft_step_by_step(): void
{
$this->actingAs($this->user);
$website = Channel::websiteOf($this->property);
$configurator = Livewire::test(ChannelProcess::class, ['record' => $website->getRouteKey()])
->call('toggleStep', 'review.request')
->call('test');
$configurator->assertRedirect();
$this->assertFalse(session('process-tester.draft.'.$website->id.'.inquiry')['steps']['review.request']['on']);
Livewire::test(ChannelProcessTest::class, ['record' => $website->getRouteKey()])
->assertSee('Vollständige Anfrage bis zur Buchung')
->set('inputs.arrival', '2026-11-07')
->call('start')
->assertSee('Bericht')
->assertSee('Gast fragt mit allen Angaben an')
->assertSee('simuliert')
->call('next')
->assertSee('Sie senden das Angebot');
$this->assertNull($website->fresh()->process_overrides['inquiry']['steps'] ?? null, 'the draft was never saved');
$this->assertSame(2, ProcessTestRun::query()->count());
}
public function test_without_the_isolation_the_tester_is_locked(): void
{
$this->actingAs($this->user);
$template = storage_path('app/sandbox/template.sqlite');
rename($template, $template.'.off');
try {
Livewire::test(ChannelProcessTest::class, ['record' => Channel::websiteOf($this->property)->getRouteKey()])
->assertSee('auf diesem Server gesperrt')
->assertDontSee('Test starten');
} finally {
rename($template.'.off', $template);
}
}
}