travelTo(CarbonImmutable::parse('2026-10-23 10:00')); $this->seed(PropertySeeder::class); $this->property = Property::sole(); Mail::fake(); } /** Case A: Destination Solutions today – we collect, we document (E-016 for the described account). */ public function test_case_a_destination_solutions_today_is_a3(): void { $ds = $this->channel('Destination Solution', []); $options = app(ChannelProcessConfiguration::class)->modelOptions($ds, IntakeKind::Booking); $this->assertSame(Capability::SUGGESTED, app(ChannelCapabilities::class)->resolve($ds)['collects_payment']->source); $this->assertTrue($options['a3.portal_booking']['admissible']); $this->assertFalse($options['a4.portal_booking']['admissible']); $restriction = $options['a4.portal_booking']['restrictions'][0]; $this->assertSame('Kanalfähigkeit', $restriction->kind); $this->assertStringContainsString('Zieht das Portal das Geld des Gastes ein?', $restriction->reason); $this->assertSame('Portalbuchung, eigene Abwicklung', $restriction->alternative, 'the allowed alternative is named'); $this->assertStringContainsString('Inkasso', (string) $restriction->change); } /** Case B: the account changes – the portal collects. The existing A4 model fits; no new logic. */ public function test_case_b_destination_solutions_with_portal_collection_switches_to_the_existing_a4_model(): void { $ds = $this->channel('Destination Solution', []); $configuration = app(ChannelProcessConfiguration::class); $before = $configuration->modelOptions($ds, IntakeKind::Booking); $this->assertFalse($before['a4.portal_booking']['admissible']); // The unsaved draft already changes what fits. $draft = ['collects_payment' => '1']; $this->assertTrue($configuration->modelOptions($ds, IntakeKind::Booking, $draft)['a4.portal_booking']['admissible']); $this->assertFalse($configuration->modelOptions($ds, IntakeKind::Booking, $draft)['a3.portal_booking']['admissible']); app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, ['model' => 'a4.portal_booking', 'capabilities' => $draft], by: 'Lars'); $ds->refresh(); $capability = app(ChannelCapabilities::class)->resolve($ds)['collects_payment']; $this->assertSame([true, Capability::CONFIRMED, 'Lars'], [$capability->value, $capability->source, $capability->confirmedBy]); $this->assertSame('Inkasso: ja', $ds->settings['process_history'][0]['capabilities'][0]); $booking = app(TakeOverExternalBooking::class)->handle($this->property, $ds, CarbonImmutable::parse('2026-12-05'), CarbonImmutable::parse('2026-12-09'), ['portal_reference' => 'DS-NEU']); $this->assertSame([CaseType::A4, 'a4.portal_booking'], [$booking->case_type, $booking->profile['plan']['model']]); $this->assertSame(ProcessProfile::MODEL, $booking->process()->source(ProcessSetting::Payments)); } /** The old stored value `payments = portal` is a derived capability and is shown as such – not overwritten unnoticed. */ public function test_a_stored_old_setting_becomes_a_derived_capability_and_is_not_silently_overridden(): void { $ds = $this->channel('Destination Solution', ['booking' => ['payments' => 'portal']]); $this->actingAs(User::factory()->create()); $capability = app(ChannelCapabilities::class)->resolve($ds)['collects_payment']; $this->assertSame([true, Capability::DERIVED], [$capability->value, $capability->source], 'the stored setting wins over the profile suggestion'); // The derived model of this channel is A4 – the page keeps it instead of switching to A3. $page = Livewire::test(ChannelProcess::class, ['record' => $ds->getRouteKey()])->set('intake', 'booking'); $this->assertSame('a4.portal_booking', $page->get('drafts')['booking']['model']); $page->assertSee('abgeleitet aus Ihrer bisherigen Einstellung'); } public function test_saving_a_model_that_overrides_a_stored_setting_needs_the_confirmation_and_is_recorded(): void { $channel = $this->channel('Sonstiges Portal', ['booking' => ['payments' => 'portal', 'guest_messages' => 'portal']]); $channel->update(['settings' => [...(array) $channel->settings, 'capabilities' => ['collects_payment' => ['value' => false, 'at' => now()->toIso8601String(), 'by' => 'Lars']]]]); $configuration = app(ChannelProcessConfiguration::class); $conflicts = $configuration->conflicts($channel->refresh(), IntakeKind::Booking, 'a3.portal_booking'); $this->assertSame([ProcessSetting::Payments], array_column($conflicts, 'setting')); try { app(ConfigureChannelProcess::class)->handle($channel, IntakeKind::Booking, ['model' => 'a3.portal_booking'], by: 'Lars'); $this->fail('saving without the confirmation must be refused'); } catch (ValidationException $exception) { $this->assertStringContainsString('ausdrücklich bestätigen', $exception->errors()['process'][0]); $this->assertStringContainsString('Bisher eingestellt: „Das Portal“', $exception->errors()['process'][1]); } $this->assertSame('portal', $channel->fresh()->process_overrides['booking']['payments'], 'nothing was changed'); app(ConfigureChannelProcess::class)->handle($channel, IntakeKind::Booking, ['model' => 'a3.portal_booking'], by: 'Lars', acknowledgeConflicts: true); $channel->refresh(); $this->assertArrayNotHasKey('payments', $channel->process_overrides['booking']); $this->assertSame('portal', $channel->process_overrides['booking']['guest_messages'], 'what the model does not fix stays'); $this->assertStringContainsString('Bisher eingestellt', $channel->settings['process_history'][0]['removed_settings'][0]); } public function test_unknown_capabilities_block_nothing_but_ask_for_confirmation(): void { $generic = $this->channel('Irgendein Portal', []); $options = app(ChannelProcessConfiguration::class)->modelOptions($generic, IntakeKind::Booking); $this->assertSame(['a3.portal_booking', 'a4.portal_booking', 'a5.portal_booking'], array_keys(array_filter($options, fn (array $option): bool => $option['admissible']))); $this->assertNotSame([], $options['a4.portal_booking']['hints']); } public function test_a5_needs_both_capabilities_and_says_which_is_missing(): void { $fewo = $this->channel('FeWo-direkt', []); $a5 = app(ChannelProcessConfiguration::class)->modelOptions($fewo, IntakeKind::Booking)['a5.portal_booking']; $this->assertFalse($a5['admissible']); $this->assertStringContainsString('Vertragsunterlagen', $a5['restrictions'][0]->change); $this->assertTrue(app(ChannelProcessConfiguration::class)->modelOptions($fewo, IntakeKind::Booking, ['provides_contract_documents' => '1'])['a5.portal_booking']['admissible'], 'O2 is a suggestion: with a confirmed capability A5 becomes available'); } /** * @param array $overrides */ private function channel(string $name, array $overrides): Channel { return Channel::factory()->for($this->property)->create(['name' => $name, 'booking_model' => 'portal_booking', 'process_overrides' => $overrides, 'import_enabled' => false, 'settings' => ['import_url' => 'https://portal.example/'.md5($name).'.ics']]); } }