travelTo(CarbonImmutable::parse('2026-10-22 10: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', 'fewo.spam.min_seconds' => 0]); Mail::swap(new MailManager($this->app)); Settings::tenant()->update([ 'bank_iban' => 'DE02120300000000202051', 'test_recipient' => 'test@example.org', 'process_defaults' => ['processing' => 'automatic', 'data_request_mode' => 'automatic'], ]); Mailbox::query()->create(['tenant_id' => Settings::tenant()->id, 'host' => 'imap.example.org', 'username' => 'anfragen@example.org', 'password' => 'x', 'mode' => Mailbox::FULL, 'address' => 'anfragen@example.org', 'is_active' => true]); // Bring your own key: the landlord's own access (here OpenRouter), no operator key. TenantService::query()->create(['tenant_id' => Settings::tenant()->id, 'service' => TenantServiceKey::AiGuestMail->value, 'is_enabled' => true, 'api_key' => 'sk-or-test', 'settings' => ['provider' => 'openrouter', 'small_model' => 'vendor/small-model', 'review_model' => 'vendor/large-model']]); app(TenantFeatures::class)->forget(); Http::preventStrayRequests(); } public function test_from_an_incomplete_website_request_to_the_binding_booking(): void { // 1. The guest asks on the website without an address. Livewire::test(BookingRequest::class) ->call('selectDate', '2026-11-07')->call('selectDate', '2026-11-10') ->set('firstName', 'Gesa')->set('lastName', 'Gast')->set('email', 'gesa@example.org')->set('privacyAccepted', true) ->call('submit')->assertHasNoErrors(); $booking = Booking::query()->sole(); // 2. Clarification hold of the automatic mode, a data request went out (test operation: only to the test address). $this->assertSame([BookingStatus::Reserved, Booking::HOLD_CLARIFICATION], [$booking->status, $booking->hold_purpose]); $this->assertTrue($booking->hold_expires_at->equalTo(now()->addMinutes(15))); $request = $booking->openDataRequest(); $this->assertSame(DataRequest::OPEN, $request->status); $question = BookingMessage::query()->where('booking_id', $booking->id)->where('subject', 'like', '%Bitte ergänzen%')->sole(); $this->assertSame('test', $question->audience, 'test operation: not delivered to the guest'); // The provider of the landlord's own AI access (faked; no network). $this->fakeExtraction([ ['field' => 'guest.street', 'value' => 'Lindenallee 12', 'evidence' => 'Lindenallee 12', 'confidence' => 0.97], ['field' => 'guest.postal_code', 'value' => '10115', 'evidence' => '10115 Berlin', 'confidence' => 0.97], ['field' => 'guest.city', 'value' => 'Berlin', 'evidence' => '10115 Berlin', 'confidence' => 0.97], ]); // 3. The guest answers by e-mail; the inbox reads it, assigns it by the reply reference and stores it once. $reply = new PortalMail('', 'test@example.org', 'Re: '.$question->subject, "Hallo,\nunsere Anschrift: Lindenallee 12, 10115 Berlin, Deutschland.\nGesa", CarbonImmutable::now(), inReplyTo: trim((string) $question->message_id, '<>')); $reader = Mockery::mock(MailboxReader::class); $reader->shouldReceive('fetchAll')->andReturn([$reply]); $this->app->instance(MailboxReader::class, $reader); $this->artisan('channels:fetch-mail')->assertSuccessful(); $this->artisan('channels:fetch-mail')->assertSuccessful(); $message = InboundMessage::query()->sole(); // The server delivers the reference without angle brackets; it is assigned anyway, and evaluated at once. $this->assertSame([InboundMessage::PROCESSED, $booking->id, 'reply', true], [$message->status, $message->booking_id, $message->match_reason, $message->test_mode]); $this->assertNull($request->fresh()->next_reminder_at, 'the answer stops the reminder'); // 4. The inbox evaluated the reply at once (extraction → rules → fact intake); the five-minute run finds nothing left. $this->artisan('messages:extract')->assertSuccessful(); $booking->refresh(); $this->assertSame('Lindenallee 12', $booking->guest->street); $this->assertSame('DE', $booking->guest->country, 'confirmed with the website form'); $this->assertSame(3, CaseFact::query()->where('booking_id', $booking->id)->where('outcome', CaseFact::APPLIED)->where('source', 'llm')->count()); $this->assertSame([BookingStatus::OfferSent, Booking::HOLD_OFFER], [$booking->status, $booking->hold_purpose]); $this->assertTrue($booking->hold_expires_at->equalTo(now()->addHours(48)), 'the offer hold is the unchanged one'); $this->assertSame(DataRequest::COMPLETED, $request->fresh()->status); // 5. The guest accepts the offer → binding booking. $this->post(URL::temporarySignedRoute('offers.accept', $booking->hold_expires_at, ['booking' => $booking, 'v' => $booking->offer_version]), ['terms' => '1'])->assertRedirect(); $this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status); $this->assertSame(0, BookingMessage::query()->where('audience', 'guest')->count(), 'nothing reached a guest in test operation'); } /** E-036 / M12: a booking binding on the portal stays binding without guest data and gets no clarification. */ public function test_a_binding_portal_booking_stays_binding_and_is_only_completed(): void { $portal = Channel::factory()->for($this->property)->create(['name' => 'FeWo-direkt', 'booking_model' => 'portal_booking', 'settings' => ['email_senders' => 'fewo-direkt.de']]); $booking = app(TakeOverExternalBooking::class)->handle($this->property, $portal, CarbonImmutable::parse('2026-12-05'), CarbonImmutable::parse('2026-12-08'), ['portal_reference' => 'HA-7']); $this->assertSame(BookingStatus::Confirmed, $booking->status); $this->assertNull($booking->guest_id); $this->assertNull($booking->openDataRequest(), 'no way to the guest yet: nothing is sent'); $this->assertSame('none', $booking->clarificationState()['state']); $this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status); } /** * @param list> $facts */ private function fakeExtraction(array $facts): void { Http::fake(['https://openrouter.ai/api/v1/chat/completions' => fn (Request $request) => Http::response([ 'id' => 'gen', 'model' => $request->data()['model'], 'choices' => [['finish_reason' => 'stop', 'message' => ['role' => 'assistant', 'content' => json_encode(['facts' => $facts, 'change_requests' => [], 'intent' => 'answer', 'uncertainties' => []])]]], 'usage' => ['prompt_tokens' => 10, 'completion_tokens' => 10], ])]); } }