Files
fewo-stommer/tests/Feature/Process/TemplateProcessTesterTest.php
T
LarsandClaude Sonnet 5.5 c46f4a032b Kanalkonfigurator und Prozess-Tester auf Schablonenbasis
Geschäftsentscheidungen zuerst (Schablonen je Bereich, Voreinstellungen A3–A5), Einzelschritte
eingeklappt, Auswirkungsanalyse beim Schablonenwechsel, unbestätigte Portal-Fähigkeiten gekennzeichnet.
Tester-Bericht nennt Schablonen, unabhängig laufende Schritte und fehlende Nachweise; alle vier
Kombinationen sind als Szenario getestet. Doku: SCHABLONEN.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 10:56:51 +01:00

135 lines
7.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Tests\Feature\Process;
use App\Enums\IntakeKind;
use App\Models\Booking;
use App\Models\BookingTask;
use App\Models\Channel;
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 PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;
/**
* Acceptance of the template composition: the four combinations of collection and contract documentation are played
* through the isolated process tester with a synthetic externally binding booking. The report must show the templates
* used, which steps run independently of waiting ones and which evidence is missing – and the combinations must differ in
* exactly the way their templates promise.
*/
#[Group('sandbox')]
class TemplateProcessTesterTest extends TestCase
{
use RefreshDatabase;
private Property $property;
private User $user;
private Channel $portal;
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']]);
$this->user = User::factory()->create();
ProcessTesterTest::template();
$this->portal = Channel::factory()->for($this->property)->create(['name' => 'Destination Solution', 'booking_model' => 'portal_booking', 'status' => 'setup', 'is_active' => false, 'import_enabled' => false, 'settings' => ['import_url' => 'https://ds.example/a.ics', 'email_senders' => 'ds.example', 'portal_profile' => 'generic']]);
}
/**
* @return array<string, array{0: string, 1: string}>
*/
public static function combinations(): array
{
return [
'eigenes Inkasso + eigene Vertragsdokumentation' => ['collection.own', 'contract_docs.own'],
'Portal-Inkasso + eigene Vertragsdokumentation' => ['collection.portal', 'contract_docs.own'],
'Portal-Inkasso + externe Vertragsunterlagen' => ['collection.portal', 'contract_docs.external'],
'eigenes Inkasso + externe Vertragsunterlagen' => ['collection.own', 'contract_docs.external'],
];
}
#[DataProvider('combinations')]
public function test_every_combination_runs_in_the_tester_and_differs_as_its_templates_promise(string $collection, string $documents): void
{
$report = $this->play($collection, $documents);
$this->assertNull($report['aborted'] ?? null, json_encode($report));
$this->assertSame([], $report['violations']);
$this->assertSame(['external.booking', 1], [$report['plan']['model'], $report['plan']['version']]);
$this->assertEqualsCanonicalizing([$collection.'@1', $documents.'@1'], array_column($report['plan']['templates'], 'reference'), 'the report names the templates used');
foreach ($report['plan']['templates'] as $template) {
$this->assertNotEmpty($template['modules']);
$this->assertFalse($template['capabilities'][0]['confirmed'], 'a capability nobody confirmed is not shown as proven');
}
[$known, , $confirmed] = $report['timeline'];
$labels = fn (array $event): array => array_column($event['activities'], 'label');
$states = fn (array $event): array => array_column($event['activities'], 'state_key', 'label');
// Finance: exactly one of the two collections shows up.
if ($collection === 'collection.own') {
$this->assertContains('Anzahlung erhalten', $labels($known));
$this->assertNotContains('Auszahlung von Destination Solution auf unser Konto', $labels($known));
$this->assertEmpty(array_filter($labels($known), fn (string $label): bool => str_starts_with($label, 'Zahlung des Gastes an')), 'no portal collection');
$this->assertContains('Anzahlung erhalten', $known['waiting'], 'we wait for the guest payments: evidence is missing');
} else {
$this->assertNotContains('Anzahlung erhalten', $labels($known), 'no own payment request towards the guest');
$this->assertSame('external', $states($known)['Zahlung des Gastes an Destination Solution']);
$this->assertContains('Auszahlung von Destination Solution auf unser Konto', $known['waiting'], 'the payout evidence is missing');
}
// Contract documentation: ours has to be checked and sent, the portal's is external. Only ours ever goes out as a contract.
if ($documents === 'contract_docs.own') {
$this->assertSame('waiting', $states($known)['Buchungsunterlagen prüfen und senden'], 'our documents wait for the portal confirmation');
$this->assertSame('open', $states($confirmed)['Buchungsunterlagen prüfen und senden'], 'then the landlord sends them (approval, not automatic)');
} else {
$this->assertSame('external', $states($known)['Buchungsunterlagen an den Gast']);
$this->assertNotContains('Buchungsunterlagen prüfen und senden', $labels($confirmed));
$this->assertEmpty(array_filter(array_column($confirmed['mails'], 'subject'), fn (string $subject): bool => str_contains($subject, 'Buchungsbestätigung') || str_contains($subject, 'Mietvertrag')), 'no contract from us');
}
// Independent steps keep running while the confirmation, the documents and the payments wait.
$this->assertContains('Kontaktdaten des Gastes', $known['independent']);
$this->assertContains('Anreisedaten', $known['independent']);
$this->assertContains('Bestätigung des Portals abwarten', $confirmed['independent'], 'the confirmation ends while the payments still wait');
$this->assertContains('Buchungsinformation an den Gast (automatisch)', $confirmed['independent']);
$this->assertSame(0, Booking::query()->count(), 'nothing reached the real data');
$this->assertSame(0, BookingTask::query()->count());
}
public function test_the_tester_runs_the_fourth_combination_and_marks_it_as_such(): void
{
$report = $this->play('collection.own', 'contract_docs.external');
$this->assertSame('A3', $report['plan']['case_type'], 'classified by who collects – no archetype of its own');
$values = collect($report['plan']['configuration'])->keyBy('question');
$this->assertSame(['Wir', 'festgelegt durch die gewählte Funktionsschablone'], [$values['Wer kümmert sich um die Zahlungen des Gastes?']['value'] ?? null, $values['Wer kümmert sich um die Zahlungen des Gastes?']['source'] ?? null]);
}
/**
* @return array<string, mixed>
*/
private function play(string $collection, string $documents): array
{
$draft = ['model' => 'external.booking', 'templates' => ['collection' => $collection, 'contract_documents' => $documents], 'settings' => ['await_portal_confirmation' => '1', 'booking_notice' => 'automatic']];
return app(ProcessSandbox::class)->run($this->portal, IntakeKind::Booking, $draft, 'portal_confirmation_wait', ['arrival' => '2026-11-14', 'nights' => 4, 'guests' => 2, 'confirmation' => 'late'], 6, $this->user)->report;
}
}