From a3ab1b6657873eeae38fd699c450db36fa2bf943 Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 5 Nov 2026 09:41:31 +0100 Subject: [PATCH] =?UTF-8?q?Kanalkonfigurator:=20best=C3=A4tigter=20Modellw?= =?UTF-8?q?echsel=20(A4=E2=86=92A3)=20speicherbar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Veraltete Altwerte (payments/guest_messages = portal), die das gewählte Modell überstimmt, blockierten das Speichern trotz bestätigter Übernahme: problems() prüfte den Entwurf vor der Entfernung, und nicht erlaubte variable Verantwortlichkeiten zählten nicht als Konflikt. Jetzt: conflicts() listet auch nicht mehr erlaubte Verantwortlichkeiten, problems()/profileWith() ignorieren die zu entfernenden Altwerte. Regressionstests A3/A4, Altwerte, Bestätigung, laufende Vorgänge. Co-Authored-By: Claude Sonnet 5.5 --- app/Process/ChannelProcessConfiguration.php | 36 ++++++++++ .../Feature/Process/ChannelCapabilityTest.php | 67 ++++++++++++++++++- 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/app/Process/ChannelProcessConfiguration.php b/app/Process/ChannelProcessConfiguration.php index 2dc9eb5..c2eb652 100644 --- a/app/Process/ChannelProcessConfiguration.php +++ b/app/Process/ChannelProcessConfiguration.php @@ -158,9 +158,43 @@ public function conflicts(Channel $channel, IntakeKind $intake, string $modelKey 'text' => $setting->question().' Bisher eingestellt: „'.$setting->describe($value).'“. Das Modell „'.$modelKey.'“ legt fest: „'.$setting->describe($fixedValue).'“.']; } + // Stored responsibilities the model does not allow (variable ones, not fixed through fixes()) are just as stale. + $responsibilities = $this->catalogue->model($modelKey)::responsibilities(); + foreach (Responsibilities::SETTINGS as $field => $setting) { + $value = $setting->normalize($stored[$setting->value] ?? null); + $responsibility = $value === null ? null : Responsibility::tryFrom((string) $value); + if ($responsibility === null || $responsibilities->admits($setting, $responsibility) || in_array($setting, array_column($conflicts, 'setting'), true)) { + continue; + } + $allowed = collect($responsibilities->allowed($field))->map(fn (Responsibility $allowedValue): string => $setting->describe($allowedValue->value))->implode(' oder '); + $conflicts[] = ['setting' => $setting, 'stored' => $setting->describe($value), 'fixed' => $allowed, + 'text' => $setting->question().' Bisher eingestellt: „'.$setting->describe($value).'“. Das Modell „'.$modelKey.'“ erlaubt: „'.$allowed.'“.']; + } + return $conflicts; } + /** + * The draft without the stored settings the chosen model overrides (see conflicts()): the landlord has to confirm their + * removal when saving, so they are neither validated against the model nor saved again. + * + * @param array $draft + * @return array + */ + public function withoutOverriddenSettings(Channel $channel, IntakeKind $intake, array $draft): array + { + $stored = (array) (($channel->process_overrides ?? [])[$intake->value] ?? []); + foreach ($this->conflicts($channel, $intake, (string) ($draft['model'] ?? '')) as $conflict) { + $key = $conflict['setting']->value; + $value = $draft['settings'][$key] ?? null; + if (array_key_exists($key, (array) ($draft['settings'] ?? [])) && (string) $conflict['setting']->normalize($value) === (string) $conflict['setting']->normalize($stored[$key] ?? null)) { + unset($draft['settings'][$key]); + } + } + + return $draft; + } + /** * The model a new case of this channel and intake would follow now: the chosen one, or the one derived from the * settings as before (marked as derived). @@ -276,6 +310,7 @@ public function preview(Channel $channel, IntakeKind $intake, array $draft): arr */ public function problems(Channel $channel, IntakeKind $intake, array $draft, bool $sandbox = false): array { + $draft = $this->withoutOverriddenSettings($channel, $intake, $draft); $problems = []; if (! in_array($intake, $this->intakes($channel), true)) { $problems[] = 'Dieser Kanal liefert keine '.($intake === IntakeKind::Booking ? 'festen Buchungen' : 'Anfragen').'.'; @@ -335,6 +370,7 @@ public function problems(Channel $channel, IntakeKind $intake, array $draft, boo */ public function profileWith(Channel $channel, IntakeKind $intake, array $draft): ProcessProfile { + $draft = $this->withoutOverriddenSettings($channel, $intake, $draft); $preview = clone $channel; $overrides = (array) ($channel->process_overrides ?? []); $overrides[$intake->value] = [...array_filter((array) ($draft['settings'] ?? []), fn (mixed $value): bool => $value !== null && $value !== ''), 'model' => $draft['model'] ?? null, 'variant' => $draft['variant'] ?? 'standard', 'steps' => (array) ($draft['steps'] ?? [])]; diff --git a/tests/Feature/Process/ChannelCapabilityTest.php b/tests/Feature/Process/ChannelCapabilityTest.php index 577bdd5..4b27d55 100644 --- a/tests/Feature/Process/ChannelCapabilityTest.php +++ b/tests/Feature/Process/ChannelCapabilityTest.php @@ -129,7 +129,7 @@ public function test_saving_a_model_that_overrides_a_stored_setting_needs_the_co $configuration = app(ChannelProcessConfiguration::class); $conflicts = $configuration->conflicts($channel->refresh(), IntakeKind::Booking, 'a3.portal_booking'); - $this->assertSame([ProcessSetting::Payments], array_column($conflicts, 'setting')); + $this->assertSame([ProcessSetting::Payments, ProcessSetting::GuestMessages], array_column($conflicts, 'setting'), 'fixed and no longer allowed responsibilities are both listed'); try { app(ConfigureChannelProcess::class)->handle($channel, IntakeKind::Booking, ['model' => 'a3.portal_booking'], by: 'Lars'); @@ -144,10 +144,73 @@ public function test_saving_a_model_that_overrides_a_stored_setting_needs_the_co $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->assertArrayNotHasKey('guest_messages', $channel->process_overrides['booking'], 'a responsibility the model does not allow is removed with it'); $this->assertStringContainsString('Bisher eingestellt', $channel->settings['process_history'][0]['removed_settings'][0]); } + /** + * Regression: Destination Solutions with the old `payments = portal`, switched to A3 in the configurator with the + * confirmation. The page carries the stale value in its draft; saving used to fail with "Inkasso … nicht zulässig". + */ + public function test_confirmed_switch_from_old_portal_collection_to_a3_saves_through_the_page(): void + { + $ds = $this->channel('Destination Solution', ['booking' => ['payments' => 'portal', 'guest_messages' => 'portal', 'contract_delivery' => 'manual']]); + $this->actingAs(User::factory()->create()); + + $page = Livewire::test(ChannelProcess::class, ['record' => $ds->getRouteKey()])->set('intake', 'booking'); + $this->assertSame('portal', $page->get('drafts')['booking']['settings']['payments'], 'the page carries the stale value'); + $page->set('capabilityDraft.collects_payment', '0')->call('chooseModel', 'a3.portal_booking'); + $this->assertSame([], $page->instance()->problems(), 'a stored value the confirmed switch removes is not an error'); + + $page->call('save')->assertNotified('Nicht gespeichert'); + $this->assertSame('portal', $ds->fresh()->process_overrides['booking']['payments'], 'without the confirmation nothing changes'); + + $page->set('acknowledge', true)->call('save')->assertNotified('Ablauf gespeichert'); + + $ds->refresh(); + $this->assertSame('a3.portal_booking', $ds->process_overrides['booking']['model']); + $this->assertArrayNotHasKey('payments', $ds->process_overrides['booking']); + $this->assertArrayNotHasKey('guest_messages', $ds->process_overrides['booking'], 'a responsibility the model does not allow goes with it'); + $this->assertSame('manual', $ds->process_overrides['booking']['contract_delivery'], 'unrelated stored settings stay'); + $this->assertSame([], $page->instance()->conflicts(), 'the stale setting does not return as an error or conflict'); + $this->assertSame([], $page->instance()->problems()); + $this->assertArrayNotHasKey('payments', $page->get('drafts')['booking']['settings']); + } + + /** A3 → A4 → A3 keeps the stored values consistent; stored values the target model accepts are untouched. */ + public function test_switching_between_a3_and_a4_keeps_settings_consistent(): void + { + $ds = $this->channel('Destination Solution', []); + $configuration = app(ChannelProcessConfiguration::class); + $save = app(ConfigureChannelProcess::class); + + $save->handle($ds, IntakeKind::Booking, ['model' => 'a3.portal_booking', 'capabilities' => ['collects_payment' => '0'], 'settings' => ['guest_messages' => 'landlord']], by: 'Lars'); + $this->assertSame('landlord', $ds->fresh()->process_overrides['booking']['guest_messages']); + + $save->handle($ds->fresh(), IntakeKind::Booking, ['model' => 'a4.portal_booking', 'capabilities' => ['collects_payment' => '1']], by: 'Lars'); + $this->assertSame('a4.portal_booking', $ds->fresh()->process_overrides['booking']['model']); + $this->assertSame([], $configuration->conflicts($ds->fresh(), IntakeKind::Booking, 'a4.portal_booking')); + + $save->handle($ds->fresh(), IntakeKind::Booking, ['model' => 'a3.portal_booking', 'capabilities' => ['collects_payment' => '0']], by: 'Lars'); + $this->assertSame('a3.portal_booking', $ds->fresh()->process_overrides['booking']['model']); + } + + /** A running case keeps its frozen plan when the channel model changes; other channels and intake kinds stay untouched. */ + public function test_a_confirmed_switch_does_not_touch_running_cases_or_other_channels(): void + { + $ds = $this->channel('Destination Solution', ['booking' => ['payments' => 'portal']]); + $other = $this->channel('Sonstiges Portal', ['booking' => ['payments' => 'portal'], 'inquiry' => ['hold_hours' => 12]]); + $ds->update(['process_overrides' => [...$ds->process_overrides, 'inquiry' => ['hold_hours' => 24]]]); + $booking = app(TakeOverExternalBooking::class)->handle($this->property, $ds->fresh(), CarbonImmutable::parse('2026-12-05'), CarbonImmutable::parse('2026-12-09'), ['portal_reference' => 'DS-ALT']); + $frozen = $booking->fresh()->profile; + + app(ConfigureChannelProcess::class)->handle($ds->fresh(), IntakeKind::Booking, ['model' => 'a3.portal_booking', 'capabilities' => ['collects_payment' => '0'], 'settings' => ['payments' => 'portal']], by: 'Lars', acknowledgeConflicts: true); + + $this->assertSame($frozen, $booking->fresh()->profile, 'the running case keeps its frozen plan'); + $this->assertSame('portal', $other->fresh()->process_overrides['booking']['payments'], 'another channel is untouched'); + $this->assertSame(['hold_hours' => 24], array_intersect_key($ds->fresh()->process_overrides['inquiry'], ['hold_hours' => 1]), 'the other intake kind is untouched'); + } + public function test_unknown_capabilities_block_nothing_but_ask_for_confirmation(): void { $generic = $this->channel('Irgendein Portal', []);