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' => '

Echte Bedingungen

', 'stay.cancellation' => '

Echtes Storno

']); 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('Der Geschäftsprozess') ->call('selectBlock', 'finance') ->assertSee('Wer zieht das Geld des Gastes ein?') ->assertSee('Eigenes Inkasso') ->assertSee('Portal-Inkasso') ->assertSee('Mehrstufige Mahnungen', escape: false) ->assertSee('Zahlungen des Gastes') ->call('selectBlock', 'documents') ->assertSee('Eigene Vertragsdokumentation') ->assertSee('Externe Vertragsunterlagen'); } 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', 'guest_communication' => 'guest_comm.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', 'guest_communication' => 'guest_comm.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->call('selectBlock', 'finance')->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', 'guest_communication' => 'guest_comm.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 $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]); } }