diff --git a/app/Process/Tester/SandboxContext.php b/app/Process/Tester/SandboxContext.php index ecfa98f..7e0b163 100644 --- a/app/Process/Tester/SandboxContext.php +++ b/app/Process/Tester/SandboxContext.php @@ -72,7 +72,7 @@ public function request(array $guest): Booking public function travel(int $minutes): void { Date::setTestNow(now()->addMinutes($minutes)); - foreach (['bookings:expire-holds', 'bookings:auto-offers', 'cases:data-requests'] as $command) { + foreach (['bookings:advance-waiting', 'bookings:expire-holds', 'bookings:auto-offers', 'cases:data-requests'] as $command) { Artisan::call($command); } app(SendBookingReminders::class)->handle(); diff --git a/app/Process/Tester/ScenarioCatalogue.php b/app/Process/Tester/ScenarioCatalogue.php index 3d59e32..ef84e43 100644 --- a/app/Process/Tester/ScenarioCatalogue.php +++ b/app/Process/Tester/ScenarioCatalogue.php @@ -5,8 +5,11 @@ use App\Enums\IntakeKind; use App\Process\Tester\Scenarios\CommunicationFailure; use App\Process\Tester\Scenarios\CompleteRequest; +use App\Process\Tester\Scenarios\GeneralQuestionMessage; +use App\Process\Tester\Scenarios\MessageOtherMedium; use App\Process\Tester\Scenarios\MissingAddress; use App\Process\Tester\Scenarios\PortalBooking; +use App\Process\Tester\Scenarios\PortalConfirmationWait; use App\Process\Tester\Scenarios\PortalInquiry; use App\Process\Tester\Scenarios\ReturningGuest; use App\Process\Tester\Scenarios\Scenario; @@ -17,7 +20,7 @@ final class ScenarioCatalogue { /** @var list> */ - public const SCENARIOS = [CompleteRequest::class, MissingAddress::class, PortalInquiry::class, ReturningGuest::class, CommunicationFailure::class, PortalBooking::class]; + public const SCENARIOS = [CompleteRequest::class, MissingAddress::class, PortalInquiry::class, ReturningGuest::class, CommunicationFailure::class, PortalBooking::class, PortalConfirmationWait::class, MessageOtherMedium::class, GeneralQuestionMessage::class]; /** * @return array> diff --git a/app/Process/Tester/Scenarios/GeneralQuestionMessage.php b/app/Process/Tester/Scenarios/GeneralQuestionMessage.php new file mode 100644 index 0000000..785a11c --- /dev/null +++ b/app/Process/Tester/Scenarios/GeneralQuestionMessage.php @@ -0,0 +1,57 @@ + ['label' => 'Nachricht', 'default' => 'question', 'type' => 'select', 'options' => ['question' => 'Sind Hunde erlaubt?', 'stay' => 'Ist die Wohnung im Dezember frei?', 'unclear' => 'ok danke']], + ]; + } + + public function events(array $inputs): array + { + $text = match ((string) ($inputs['text'] ?? 'question')) { + 'stay' => 'Ist die Wohnung vom 12.12. bis 19.12. frei? Wir würden gern buchen.', + 'unclear' => 'ok danke', + default => 'Sind Hunde erlaubt und gibt es einen Parkplatz?', + }; + + return [new ScenarioEvent('Nachricht im Chat ohne Vorgang', fn (SandboxContext $context) => app(MessageIntake::class)->handle( + new IncomingMessage(Medium::Chat, 'chat-visitor-1', $text, CarbonImmutable::now(), 'tester-'.md5($text)), + ))]; + } +} diff --git a/app/Process/Tester/Scenarios/MessageOtherMedium.php b/app/Process/Tester/Scenarios/MessageOtherMedium.php new file mode 100644 index 0000000..96ec717 --- /dev/null +++ b/app/Process/Tester/Scenarios/MessageOtherMedium.php @@ -0,0 +1,63 @@ + ['label' => 'Medium', 'default' => 'whatsapp', 'type' => 'select', 'options' => ['whatsapp' => 'WhatsApp', 'chat' => 'Chat']], + 'reference' => ['label' => 'Bezug', 'default' => 'verified', 'type' => 'select', 'options' => ['verified' => 'überprüfter Bezug zum Vorgang', 'none' => 'kein Bezug (nur Absender)', 'contradicting' => 'überprüfter Bezug, Text nennt andere Nummer']], + 'consent' => ['label' => 'Einwilligung des Gastes liegt vor', 'default' => true, 'type' => 'bool'], + ]; + } + + public function events(array $inputs): array + { + return [ + new ScenarioEvent('Anfrage des Gastes liegt vor', fn (SandboxContext $context) => $context->request([])), + new ScenarioEvent('Nachricht des Gastes im anderen Medium', function (SandboxContext $context) use ($inputs): void { + $reference = (string) ($inputs['reference'] ?? 'verified'); + $text = 'Wir kommen am Anreisetag gegen 16 Uhr an.'.($reference === 'contradicting' ? ' Vorgang 2099-0001' : ''); + app(MessageIntake::class)->handle(new IncomingMessage( + Medium::tryFrom((string) ($inputs['medium'] ?? 'whatsapp')) ?? Medium::WhatsApp, '+49170000000', $text, CarbonImmutable::now(), 'tester-'.md5($text), + $reference === 'none' ? null : $context->booking?->id, (bool) ($inputs['consent'] ?? true), + )); + }), + ]; + } +} diff --git a/app/Process/Tester/Scenarios/PortalConfirmationWait.php b/app/Process/Tester/Scenarios/PortalConfirmationWait.php new file mode 100644 index 0000000..d0164a3 --- /dev/null +++ b/app/Process/Tester/Scenarios/PortalConfirmationWait.php @@ -0,0 +1,76 @@ + ['label' => 'Bestätigungsmail', 'default' => 'late', 'type' => 'select', 'options' => ['immediate' => 'sofort', 'late' => 'nach 5 Stunden', 'missing' => 'bleibt aus']], + ]; + } + + public function events(array $inputs): array + { + $known = new ScenarioEvent('Buchung ist bekannt (ohne Bestätigungsmail des Portals)', function (SandboxContext $context): void { + $context->booking = app(TakeOverExternalBooking::class)->handle($context->property, $context->channel, $context->arrival(), $context->departure(), [ + 'portal_reference' => $this->reference($context), 'portal_total' => 98000, 'guests' => $context->guests(), + 'guest' => ['first_name' => 'Testgast', 'last_name' => 'Portal', 'email' => 'portalgast@tester.invalid', 'street' => 'Teststraße 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'], + ]); + }); + + return [$known, ...match ((string) ($inputs['confirmation'] ?? 'late')) { + 'immediate' => [$this->mailEvent()], + 'missing' => [new ScenarioEvent('60 Stunden vergehen – die Mail bleibt aus', fn (SandboxContext $context) => $context->travel(60 * 60))], + default => [new ScenarioEvent('5 Stunden vergehen', fn (SandboxContext $context) => $context->travel(5 * 60)), $this->mailEvent()], + }]; + } + + private function mailEvent(): ScenarioEvent + { + return new ScenarioEvent('Bestätigungsmail des Portals kommt an', function (SandboxContext $context): void { + $senders = array_values(array_filter(array_map('trim', explode(',', (string) ($context->channel->setting('email_senders') ?? ''))))); + $text = "Gast: Testgast Portal\nAnreise: ".$context->arrival()->format('d.m.Y')."\nAbreise: ".$context->departure()->format('d.m.Y')."\nBuchungsnummer: ".$this->reference($context); + app(ProcessPortalMail::class)->handle(new PortalMail('<'.md5($text).'@tester.invalid>', 'buchung@'.($senders[0] ?? 'portal.invalid'), 'Neue Buchung', $text, CarbonImmutable::now())); + }); + } + + private function reference(SandboxContext $context): string + { + return 'TEST-'.$context->arrival()->format('md'); + } +} diff --git a/tests/Feature/Process/ProcessTesterTest.php b/tests/Feature/Process/ProcessTesterTest.php index ad27a59..68d72e2 100644 --- a/tests/Feature/Process/ProcessTesterTest.php +++ b/tests/Feature/Process/ProcessTesterTest.php @@ -6,6 +6,7 @@ use App\Filament\Resources\Channels\Pages\ChannelProcess; use App\Filament\Resources\Channels\Pages\ChannelProcessTest; use App\Models\Booking; +use App\Models\BookingTask; use App\Models\Channel; use App\Models\ProcessTestRun; use App\Models\Property; @@ -132,6 +133,39 @@ public function test_a_portal_booking_scenario_with_cancellation_report(): void $this->assertFalse((bool) $fewo->fresh()->is_active, 'the real channel is unchanged'); } + /** V2.1: waiting for the portal's confirmation – shows the wait, the protected occupation and the escalation in the tester */ + public function test_the_portal_confirmation_scenarios_show_waiting_arrival_and_escalation(): void + { + $portal = Channel::factory()->for($this->property)->create(['name' => 'Destination Solution', 'booking_model' => 'portal_booking', 'status' => 'setup', 'is_active' => false, 'import_enabled' => false, 'settings' => ['import_url' => 'https://ds.example/a.ics', 'email_senders' => 'ds.example']]); + $draft = ['model' => 'a3.portal_booking', 'settings' => ['await_portal_confirmation' => '1', 'booking_notice' => 'automatic']]; + + $late = app(ProcessSandbox::class)->run($portal, IntakeKind::Booking, $draft, 'portal_confirmation_wait', ['arrival' => '2026-11-14', 'nights' => 4, 'guests' => 2, 'confirmation' => 'late'], 6, $this->user)->report; + $missing = app(ProcessSandbox::class)->run($portal, IntakeKind::Booking, $draft, 'portal_confirmation_wait', ['arrival' => '2026-11-14', 'nights' => 4, 'guests' => 2, 'confirmation' => 'missing'], 6, $this->user)->report; + + $this->assertNull($late['aborted'] ?? null, json_encode($late)); + $known = $late['timeline'][0]; + $this->assertStringContainsString('wartet', json_encode($known['activities'], JSON_UNESCAPED_UNICODE)); + $this->assertSame([], $known['mails'], 'nothing goes out while the confirmation is missing'); + $this->assertNotEmpty(end($late['timeline'])['mails'], 'after the confirmation the booking information goes out (sandbox only)'); + $this->assertStringContainsString('ausgeblieben', json_encode(end($missing['timeline'])['activities'], JSON_UNESCAPED_UNICODE)); + $this->assertSame(0, Booking::query()->count()); + $this->assertSame(0, BookingTask::query()->count(), 'the escalation task exists only inside the sandbox'); + } + + /** V2.1 E/F: other media and questions without a case, through the isolated tester */ + public function test_the_message_scenarios_show_assignment_and_never_create_a_case(): void + { + config(['communication.media.chat.active' => true, 'communication.media.whatsapp.active' => true]); + $website = Channel::websiteOf($this->property); + + $question = app(ProcessSandbox::class)->run($website, IntakeKind::Inquiry, ['model' => 'a1.offer'], 'general_question_message', ['text' => 'question'], 1, $this->user)->report; + $reply = app(ProcessSandbox::class)->run($website, IntakeKind::Inquiry, ['model' => 'a1.offer'], 'message_other_medium', ['arrival' => '2026-11-07', 'nights' => 3, 'guests' => 2, 'medium' => 'whatsapp', 'reference' => 'none', 'consent' => true], 2, $this->user)->report; + + $this->assertNull($question['aborted'] ?? null, json_encode($question)); + $this->assertNull($reply['aborted'] ?? null, json_encode($reply)); + $this->assertSame(0, Booking::query()->count()); + } + /** S12/T06: a failing mail server leaves the case in a defined state */ public function test_a_mail_failure_keeps_the_case(): void {