U-C: Kanalkonfigurator (Kanal › Ablauf): Modellwahl nach Kanalprofil (E2/O2), Schritte mit Schalter, Ausführung, Ausführenden und Fristen, Herkunft der Werte, Vorschau; ConfigureChannelProcess; Modell legt Einstellungen fest
Flache Prozessfelder im Kanalformular entfallen als Hauptansicht. Volle Suite 820/820. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d695566a7a
commit
c255783cec
13 files changed
+981
-50
No files matched your search
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Process;
|
||||
|
||||
use App\Actions\ConfigureChannelProcess;
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Actions\RequestReviews;
|
||||
use App\Actions\TakeOverExternalBooking;
|
||||
use App\Actions\TakeOverPortalInquiry;
|
||||
use App\Enums\ActivityState;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\CaseType;
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Enums\ProcessSetting;
|
||||
use App\Filament\Resources\Channels\Pages\ChannelProcess;
|
||||
use App\Models\Channel;
|
||||
use App\Models\Property;
|
||||
use App\Models\User;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\ChannelProcessConfiguration;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Package U-C: the channel configurator (docs/Prozessarchitektur/Architektur/03, criteria K01–K10, N4, N5).
|
||||
*/
|
||||
#[Group('configurator')]
|
||||
class ChannelProcessConfiguratorTest 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();
|
||||
}
|
||||
|
||||
/** K01 / E2 / O2 */
|
||||
public function test_only_admissible_models_per_channel_and_intake_are_offered(): void
|
||||
{
|
||||
$configuration = app(ChannelProcessConfiguration::class);
|
||||
$fewo = $this->channel('FeWo-direkt', 'mixed');
|
||||
$ds = $this->channel('Destination Solution', 'portal_booking');
|
||||
$listing = $this->channel('Ostseeklar', 'inquiry');
|
||||
$website = Channel::websiteOf($this->property);
|
||||
|
||||
$this->assertSame(['a2.offer', 'a2.information'], array_keys($configuration->admissibleModels($fewo, IntakeKind::Inquiry)));
|
||||
$this->assertSame(['a4.portal_booking'], array_keys($configuration->admissibleModels($fewo, IntakeKind::Booking)), 'O2: FeWo-direkt bookings only A4 for now');
|
||||
$this->assertSame(['a3.portal_booking'], array_keys($configuration->admissibleModels($ds, IntakeKind::Booking)));
|
||||
$this->assertSame([IntakeKind::Booking], $configuration->intakes($ds));
|
||||
$this->assertSame(['a2.offer', 'a2.information'], array_keys($configuration->admissibleModels($listing, IntakeKind::Inquiry)));
|
||||
$this->assertSame(['a1.offer', 'a1.information'], array_keys($configuration->admissibleModels($website, IntakeKind::Inquiry)));
|
||||
|
||||
// The restriction lives in the channel profile, not in the process core: a changed profile releases more models.
|
||||
$fewo->update(['settings' => [...(array) $fewo->settings, 'portal_profile' => 'generic']]);
|
||||
$this->assertSame(['a3.portal_booking', 'a4.portal_booking', 'a5.portal_booking'], array_keys($configuration->admissibleModels($fewo->fresh(), IntakeKind::Booking)));
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, ['model' => 'a4.portal_booking']);
|
||||
}
|
||||
|
||||
/** K01, K05, N4 */
|
||||
public function test_a_mixed_channel_gets_different_models_for_requests_and_bookings_and_running_cases_keep_their_plan(): void
|
||||
{
|
||||
$fewo = $this->channel('FeWo-direkt', 'mixed');
|
||||
$running = app(TakeOverExternalBooking::class)->handle($this->property, $fewo, CarbonImmutable::parse('2026-12-05'), CarbonImmutable::parse('2026-12-12'), ['portal_reference' => 'HA-ALT']);
|
||||
$before = $running->fresh()->profile;
|
||||
|
||||
app(ConfigureChannelProcess::class)->handle($fewo, IntakeKind::Inquiry, ['model' => 'a2.information']);
|
||||
app(ConfigureChannelProcess::class)->handle($fewo->fresh(), IntakeKind::Booking, ['model' => 'a4.portal_booking']);
|
||||
|
||||
$inquiry = app(TakeOverPortalInquiry::class)->handle($fewo->fresh(), CarbonImmutable::parse('2026-11-14'), CarbonImmutable::parse('2026-11-18'), 'HA-ANF');
|
||||
$booking = app(TakeOverExternalBooking::class)->handle($this->property, $fewo->fresh(), CarbonImmutable::parse('2027-07-10'), CarbonImmutable::parse('2027-07-17'), ['portal_reference' => 'HA-NEU']);
|
||||
|
||||
$this->assertSame(['a2.information', ProcessPlan::CONFIGURED, CaseType::A2], [$inquiry->profile['plan']['model'], $inquiry->profile['plan']['source'], $inquiry->case_type]);
|
||||
$this->assertFalse($inquiry->process()->preReservation(), 'the model fixes the pre-reservation');
|
||||
$this->assertSame(ProcessProfile::MODEL, $inquiry->process()->source(ProcessSetting::PreReservation));
|
||||
$this->assertSame(['a4.portal_booking', CaseType::A4], [$booking->profile['plan']['model'], $booking->case_type]);
|
||||
$this->assertSame($before, $running->fresh()->profile, 'K05: the running case keeps its frozen profile and plan');
|
||||
$this->assertSame(CaseType::A3, $running->fresh()->case_type);
|
||||
}
|
||||
|
||||
/** K07 */
|
||||
public function test_mandatory_steps_and_inadmissible_responsibilities_are_refused(): void
|
||||
{
|
||||
$fewo = $this->channel('FeWo-direkt', 'mixed');
|
||||
$configuration = app(ChannelProcessConfiguration::class);
|
||||
|
||||
$this->assertNotSame([], $configuration->problems($fewo, IntakeKind::Booking, ['model' => 'a4.portal_booking', 'steps' => ['binding.portal' => ['on' => false]]]));
|
||||
$this->assertNotSame([], $configuration->problems($fewo, IntakeKind::Booking, ['model' => 'a4.portal_booking', 'steps' => ['channels.block' => ['on' => false]]]));
|
||||
$this->assertNotSame([], $configuration->problems($fewo, IntakeKind::Inquiry, ['model' => 'a2.offer', 'steps' => ['availability.check' => ['on' => false]]]));
|
||||
$this->assertNotSame([], $configuration->problems($fewo, IntakeKind::Inquiry, ['model' => 'a2.offer', 'steps' => ['offer.acceptance' => ['on' => false]]]));
|
||||
$this->assertNotSame([], $configuration->problems($fewo, IntakeKind::Booking, ['model' => 'a4.portal_booking', 'settings' => ['payments' => 'landlord']]), 'A4 fixes portal collection');
|
||||
$this->assertSame([], $configuration->problems($fewo, IntakeKind::Inquiry, ['model' => 'a2.offer', 'steps' => ['review.request' => ['on' => false], 'guest.data_request' => ['on' => false]]]), 'optional steps may be switched off');
|
||||
}
|
||||
|
||||
/** K08 / O1: a variable responsibility changes without a model change, a fixed one cannot */
|
||||
public function test_arrival_information_can_go_to_the_portal_within_a4_without_changing_the_model(): void
|
||||
{
|
||||
$fewo = $this->channel('FeWo-direkt', 'mixed');
|
||||
app(ConfigureChannelProcess::class)->handle($fewo, IntakeKind::Booking, ['model' => 'a4.portal_booking', 'settings' => ['guest_messages' => 'portal']]);
|
||||
|
||||
$booking = app(TakeOverExternalBooking::class)->handle($this->property, $fewo->fresh(), CarbonImmutable::parse('2027-07-10'), CarbonImmutable::parse('2027-07-17'), ['portal_reference' => 'HA-K08']);
|
||||
|
||||
$this->assertSame([CaseType::A4, 'a4.portal_booking'], [$booking->case_type, $booking->profile['plan']['model']]);
|
||||
$arrival = collect(CaseActivities::for($booking))->firstWhere('key', 'arrival_info');
|
||||
$this->assertSame(ActivityState::External, $arrival->state);
|
||||
$documents = collect(CaseActivities::for($booking))->firstWhere('key', 'documents');
|
||||
$this->assertNotSame(ActivityState::External, $documents->state, 'the contract documentation stays ours in A4 (O1)');
|
||||
$this->assertNotSame([], app(ChannelProcessConfiguration::class)->problems($fewo->fresh(), IntakeKind::Booking, ['model' => 'a4.portal_booking', 'settings' => ['documents' => 'portal']]), 'contract documentation decides the case type');
|
||||
}
|
||||
|
||||
/** N5 */
|
||||
public function test_a_switched_off_optional_step_is_skipped_and_has_no_effect(): void
|
||||
{
|
||||
$website = Channel::websiteOf($this->property);
|
||||
app(ConfigureChannelProcess::class)->handle($website, IntakeKind::Inquiry, ['model' => 'a1.offer', 'steps' => ['review.request' => ['on' => false]]]);
|
||||
$booking = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', 'street' => 'Weg 1', 'postal_code' => '10115', 'city' => 'Berlin', 'country' => 'DE']);
|
||||
$booking->forceFill(['status' => BookingStatus::Confirmed, 'confirmed_at' => now()])->saveQuietly();
|
||||
|
||||
$this->assertNull(collect(CaseActivities::for($booking->fresh()))->firstWhere('key', 'review'));
|
||||
$preview = collect(app(ChannelProcessConfiguration::class)->preview($website->fresh(), IntakeKind::Inquiry, ['model' => 'a1.offer', 'steps' => ['review.request' => ['on' => false]]]))->firstWhere('module', 'review.request');
|
||||
$this->assertSame([false, 'im Kanal abgeschaltet'], [$preview['on'], $preview['reason']]);
|
||||
|
||||
$this->travelTo(CarbonImmutable::parse('2026-11-13 10:00'));
|
||||
app(RequestReviews::class)->handle();
|
||||
$this->assertNull($booking->fresh()->review_requested_at);
|
||||
}
|
||||
|
||||
/** K09 */
|
||||
public function test_the_loyalty_variant_can_be_drafted_but_not_saved(): void
|
||||
{
|
||||
$website = Channel::websiteOf($this->property);
|
||||
$configuration = app(ChannelProcessConfiguration::class);
|
||||
|
||||
$preview = collect($configuration->preview($website, IntakeKind::Inquiry, ['model' => 'a1.offer', 'variant' => 'loyalty']));
|
||||
$this->assertTrue($preview->firstWhere('module', 'pricing.loyalty_discount')['tester_only']);
|
||||
$this->assertSame([], $configuration->problems($website, IntakeKind::Inquiry, ['model' => 'a1.offer', 'variant' => 'loyalty'], sandbox: true));
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(ConfigureChannelProcess::class)->handle($website, IntakeKind::Inquiry, ['model' => 'a1.offer', 'variant' => 'loyalty']);
|
||||
}
|
||||
|
||||
/** K03: the preview lists exactly the steps that show up on a new case */
|
||||
public function test_the_preview_matches_the_course_of_a_new_case(): void
|
||||
{
|
||||
$website = Channel::websiteOf($this->property);
|
||||
$draft = ['model' => 'a1.offer'];
|
||||
app(ConfigureChannelProcess::class)->handle($website, IntakeKind::Inquiry, $draft);
|
||||
$booking = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org']);
|
||||
|
||||
$preview = collect(app(ChannelProcessConfiguration::class)->preview($website->fresh(), IntakeKind::Inquiry, $draft))->where('on', true)->pluck('module')->all();
|
||||
$this->assertSame(array_keys($booking->profile['plan']['modules']), collect(app(ChannelProcessConfiguration::class)->preview($website->fresh(), IntakeKind::Inquiry, $draft))->pluck('module')->all());
|
||||
foreach (['offer.binding', 'offer.acceptance', 'documents.send', 'stay', 'case.settlement'] as $module) {
|
||||
$this->assertContains($module, $preview);
|
||||
}
|
||||
$this->assertNotContains('offer.information', $preview);
|
||||
}
|
||||
|
||||
/** K02, K06, K10: the page in the simple view, inherited and set values with their origin */
|
||||
public function test_the_page_shows_the_steps_with_their_settings_and_saves(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->create());
|
||||
$website = Channel::websiteOf($this->property);
|
||||
|
||||
Livewire::test(ChannelProcess::class, ['record' => $website->getRouteKey()])
|
||||
->assertSee('Wie wird eine Anfrage über')
|
||||
->assertSee('Angebot mit Vorreservierung')
|
||||
->assertSee('Fehlende Angaben beim Gast anfragen')
|
||||
->assertSee('Pflicht')
|
||||
->assertSee('Vorschau: ein neuer Vorgang')
|
||||
->set('drafts.inquiry.settings.hold_hours', '24')
|
||||
->assertSee('hier gesetzt')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$profile = app(ProcessSettings::class)->forWebsite($this->property);
|
||||
$this->assertSame(24, $profile->holdHours());
|
||||
$this->assertSame(ProcessProfile::WEBSITE, $profile->source(ProcessSetting::HoldHours));
|
||||
$this->assertSame('a1.offer', $website->fresh()->process_overrides['inquiry']['model']);
|
||||
}
|
||||
|
||||
private function channel(string $name, string $model): Channel
|
||||
{
|
||||
return Channel::factory()->for($this->property)->create(['name' => $name, 'booking_model' => $model, 'import_enabled' => false, 'settings' => ['import_url' => 'https://portal.example/'.md5($name).'.ics']]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user