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>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-05 10:56:51 +01:00
1 parent e95ba4f986
commit c46f4a032b
12 files changed
+810 -10

No files matched your search

@@ -0,0 +1,236 @@
<?php
namespace Tests\Feature\Process;
use App\Actions\ConfigureChannelProcess;
use App\Actions\TakeOverExternalBooking;
use App\Enums\IntakeKind;
use App\Enums\ProcessSetting;
use App\Filament\Resources\Channels\Pages\ChannelProcess;
use App\Models\Booking;
use App\Models\Channel;
use App\Models\Property;
use App\Models\User;
use App\Process\ChannelProcessConfiguration;
use App\Process\ConfigurationImpact;
use App\Process\ProcessCatalogue;
use App\Process\ProcessPlan;
use App\Process\ProcessProfile;
use App\Process\ProcessSettings;
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 Illuminate\Validation\ValidationException;
use Livewire\Livewire;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;
/**
* The channel configurator on the composition: the business decisions come first, the single steps stay reachable and
* configurable, nothing changes silently, running cases keep their plan.
*/
#[Group('configurator')]
class TemplateConfiguratorTest extends TestCase
{
use RefreshDatabase;
private Property $property;
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']);
Http::preventStrayRequests();
$this->actingAs(User::factory()->create());
}
public function test_the_page_shows_the_business_decisions_first_and_keeps_the_steps_reachable(): void
{
$ds = $this->channel('Destination Solution', []);
Livewire::test(ChannelProcess::class, ['record' => $ds->getRouteKey()])
->call('chooseModel', 'external.booking')
->assertSee('Geschäftsentscheidungen')
->assertSee('Wer zieht das Geld des Gastes ein?')
->assertSee('Eigenes Inkasso')
->assertSee('Portal-Inkasso')
->assertSee('Eigene Vertragsdokumentation')
->assertSee('Externe Vertragsunterlagen')
->assertSee('Mehrstufige Mahnungen', escape: false)
->assertSee('Einzelschritte einstellen')
->assertSee('Zahlungen des Gastes');
}
public function test_an_archetype_moves_to_the_base_process_with_the_same_combination_and_saves(): void
{
$fewo = $this->channel('FeWo-direkt', [], 'mixed');
$page = Livewire::test(ChannelProcess::class, ['record' => $fewo->getRouteKey()])->set('intake', 'booking');
$page->assertSee('Auf Schablonen umstellen')->call('applyPreset', 'a4.portal_booking');
$this->assertSame(['external.booking', ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own']], [$page->get('drafts')['booking']['model'], $page->get('drafts')['booking']['templates']]);
$this->assertSame([], $page->instance()->problems());
$page->call('save')->assertNotified('Ablauf gespeichert');
$this->assertSame('external.booking', $fewo->fresh()->process_overrides['booking']['model']);
$this->assertEquals(['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own'], $fewo->fresh()->process_overrides['booking']['templates']);
$booking = $this->takeOver($fewo->fresh(), 'FD-1');
$this->assertEquals(['collection' => 'collection.portal@1', 'contract_documents' => 'contract_docs.own@1'], ProcessPlan::of($booking)->templates);
$this->assertSame('A4', strtoupper($booking->case_type->value));
}
public function test_a_template_the_portal_cannot_support_cannot_be_chosen_and_says_why(): void
{
$fewo = $this->channel('FeWo-direkt', [], 'mixed');
$page = Livewire::test(ChannelProcess::class, ['record' => $fewo->getRouteKey()])->set('intake', 'booking')->call('applyPreset', 'a4.portal_booking');
$page->call('chooseTemplate', 'collection', 'collection.own');
$this->assertSame('collection.portal', $page->get('drafts')['booking']['templates']['collection'], 'refused: FeWo-direkt collects the money');
$page->assertSee('Passt gerade nicht')->assertSee('Zieht das Portal das Geld des Gastes ein?');
// The landlord corrects the capability first: now the template fits.
$page->set('capabilityDraft.collects_payment', '0')->call('chooseTemplate', 'collection', 'collection.own');
$this->assertSame('collection.own', $page->get('drafts')['booking']['templates']['collection']);
}
public function test_unconfirmed_capabilities_are_flagged_and_never_taken_as_proven(): void
{
$generic = $this->channel('Irgendein Portal', [], 'portal_booking');
$options = app(ChannelProcessConfiguration::class)->templateOptions($generic, app(ProcessCatalogue::class)->model('external.booking'));
$this->assertTrue($options['collection']['collection.own']['admissible'], 'unknown blocks nothing');
$this->assertSame(['collects_payment'], $options['collection']['collection.own']['unconfirmed']);
$this->assertNotSame([], $options['contract_documents']['contract_docs.external']['hints']);
$fewo = $this->channel('FeWo-direkt Profil', [], 'mixed');
$suggested = app(ChannelProcessConfiguration::class)->templateOptions($fewo, app(ProcessCatalogue::class)->model('external.booking'));
$this->assertContains('collects_payment', $suggested['collection']['collection.portal']['unconfirmed'], 'a suggestion of the channel profile is not a confirmation');
$this->assertStringContainsString('nicht als bestätigt', implode(' ', $suggested['collection']['collection.portal']['hints']));
}
/** The A4 → A3 regression of the archetypes, now as a switch of the collection template */
public function test_switching_the_collection_template_shows_every_consequence_and_needs_the_confirmation(): void
{
$ds = $this->channel('Destination Solution', ['booking' => ['payments' => 'portal', 'guest_messages' => 'portal', 'contract_delivery' => 'manual', 'steps' => ['review.request' => ['on' => false]]]]);
$ds->update(['settings' => [...(array) $ds->settings, 'capabilities' => ['messages_guest' => ['value' => false, 'at' => now()->toIso8601String(), 'by' => 'Lars']]]]);
$page = Livewire::test(ChannelProcess::class, ['record' => $ds->getRouteKey()])->set('intake', 'booking');
$page->set('capabilityDraft.collects_payment', '0')->call('chooseModel', 'external.booking')->call('chooseTemplate', 'collection', 'collection.own');
$conflicts = collect($page->instance()->conflicts())->map(fn (array $conflict): string => $conflict['setting']->value)->all();
$this->assertEqualsCanonicalizing(['payments', 'guest_messages'], $conflicts, 'the stale collection and the stale portal communication are conflicts, not silent changes');
$page->assertSee('Bisherige Einstellungen widersprechen');
$page->call('save')->assertNotified('Nicht gespeichert');
$this->assertSame('portal', $ds->fresh()->process_overrides['booking']['payments'], 'nothing changed without the confirmation');
$page->set('acknowledge', true)->call('save')->assertNotified('Ablauf gespeichert');
$saved = $ds->fresh()->process_overrides['booking'];
$this->assertSame('external.booking', $saved['model']);
$this->assertArrayNotHasKey('payments', $saved);
$this->assertArrayNotHasKey('guest_messages', $saved);
$this->assertSame('manual', $saved['contract_delivery'], 'parameters of the kept modules survive');
$this->assertSame(['review.request' => ['on' => false]], $saved['steps'], 'so does a switched-off optional step');
$this->assertStringContainsString('Bisher eingestellt', $ds->fresh()->settings['process_history'][0]['removed_settings'][0]);
$this->assertEquals(['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own'], $saved['templates']);
}
public function test_the_impact_of_a_template_change_names_modules_responsibility_and_open_ends(): void
{
$fewo = $this->channel('FeWo-direkt', ['booking' => ['steps' => []]], 'mixed');
app(ConfigureChannelProcess::class)->handle($fewo, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own']]);
$impact = app(ConfigurationImpact::class)->ofTemplates($fewo->fresh(), IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.external']]);
$impact = collect($impact)->keyBy('area');
$this->assertEqualsCanonicalizing(['Finanzabwicklung (Inkasso)', 'Vertragsdokumentation'], $impact->keys()->all());
$finance = $impact['Finanzabwicklung (Inkasso)'];
$documents = $impact['Vertragsdokumentation'];
$this->assertSame(['Portal-Inkasso', 'Eigenes Inkasso'], [$finance['from'], $finance['to']]);
$this->assertSame(['Auszahlung des Portals'], $finance['removed']);
$this->assertSame(['Zahlungen des Gastes'], $finance['kept']);
$this->assertSame(['from' => 'Das Portal', 'to' => 'Wir'], $finance['responsibility']);
$this->assertContains('Mehrstufige Mahnungen (rechtliche Ausgestaltung offen)', $finance['extensions']);
$this->assertSame(['from' => 'Wir', 'to' => 'Das Portal'], $documents['responsibility']);
$this->assertSame([], app(ConfigurationImpact::class)->ofTemplates($fewo->fresh(), IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own']]), 'no change, no impact');
}
public function test_the_modules_of_a_template_stay_individually_configurable_and_the_inheritance_holds(): void
{
Settings::tenant()->update(['process_defaults' => ['contract_delivery' => 'manual']]);
$ds = $this->channel('Destination Solution', []);
app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own']]);
$page = Livewire::test(ChannelProcess::class, ['record' => $ds->fresh()->getRouteKey()])->set('intake', 'booking');
$documents = collect($page->instance()->steps())->firstWhere('module', 'documents.send');
$this->assertSame('Eigene Vertragsdokumentation', $documents['template']);
$this->assertContains('contract_delivery', array_column($documents['parameters'], 'key'), 'the module of the template has its own parameters');
$this->assertNotNull($documents['mode_setting'], 'and its own mode');
$this->assertSame('manual', app(ProcessSettings::class)->resolve($this->property, $ds->fresh(), IntakeKind::Booking)->value(ProcessSetting::ContractDelivery));
$this->assertSame(ProcessProfile::TENANT, app(ProcessSettings::class)->resolve($this->property, $ds->fresh(), IntakeKind::Booking)->source(ProcessSetting::ContractDelivery));
$page->set('drafts.booking.settings.contract_delivery', 'automatic')->set('drafts.booking.settings.processing', 'approval')->call('save')->assertNotified('Ablauf gespeichert');
$profile = app(ProcessSettings::class)->resolve($this->property, $ds->fresh(), IntakeKind::Booking);
$this->assertSame(['automatic', ProcessProfile::CHANNEL], [$profile->value(ProcessSetting::ContractDelivery), $profile->source(ProcessSetting::ContractDelivery)]);
$this->assertSame(ProcessProfile::TEMPLATE, $profile->source(ProcessSetting::Payments));
}
public function test_a_template_does_not_override_a_parameter_set_by_hand_and_a_contradicting_responsibility_is_refused(): void
{
$ds = $this->channel('Destination Solution', []);
$configuration = app(ChannelProcessConfiguration::class);
$problems = $configuration->problems($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own'], 'settings' => ['payments' => 'portal']]);
$this->assertNotSame([], $problems, 'a responsibility set by hand may not contradict the template');
$this->assertStringContainsString('widerspricht der Schablone', implode(' ', $problems));
$this->assertSame([], $configuration->problems($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own'], 'settings' => ['payments' => 'landlord', 'contract_delivery' => 'manual']]));
$this->expectException(ValidationException::class);
app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own'], 'settings' => ['payments' => 'portal']]);
}
public function test_changing_the_templates_leaves_running_cases_and_their_plans_untouched(): void
{
$ds = $this->channel('Destination Solution', []);
app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own']]);
$running = $this->takeOver($ds->fresh(), 'DS-ALT');
$frozen = $running->fresh()->profile;
app(ConfigureChannelProcess::class)->handle($ds->fresh(), IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.external'], 'capabilities' => ['collects_payment' => '1', 'provides_contract_documents' => '1']]);
$new = $this->takeOver($ds->fresh(), 'DS-NEU', '2027-09-10');
$this->assertSame($frozen, $running->fresh()->profile, 'the running case keeps profile and plan');
$this->assertSame('collection.own@1', ProcessPlan::of($running->fresh())->templates['collection']);
$this->assertSame('collection.portal@1', ProcessPlan::of($new)->templates['collection']);
$this->assertSame(['landlord', 'portal'], [$running->fresh()->process()->payments()->value, $new->process()->payments()->value]);
}
/**
* @param array<string, mixed> $overrides
*/
private function channel(string $name, array $overrides, string $model = 'portal_booking'): Channel
{
return Channel::factory()->for($this->property)->create(['name' => $name, 'booking_model' => $model, 'process_overrides' => $overrides, 'import_enabled' => false, 'settings' => ['import_url' => 'https://portal.example/'.md5($name).'.ics']]);
}
private function takeOver(Channel $channel, string $reference, string $arrival = '2027-07-10'): Booking
{
$arrival = CarbonImmutable::parse($arrival);
return app(TakeOverExternalBooking::class)->handle($this->property, $channel, $arrival, $arrival->addDays(7), ['portal_reference' => $reference]);
}
}