travelTo(CarbonImmutable::parse('2026-10-23 10:00')); $this->seed(PropertySeeder::class); $this->property = Property::sole(); Storage::fake('local'); Mail::fake(); Content::save(['contract.terms' => '
Echte Bedingungen
', 'stay.cancellation' => 'Echtes Storno
']); Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051', 'process_defaults' => ['processing' => 'automatic']]); DocumentReleases::set(DocumentKind::ExternalRecord, true, 'Test'); $template = ContractTemplate::query()->create(['name' => 'Portalunterlagen', 'version' => 1, 'body' => 'Mietvertrag {{ mieter }}
', 'released_at' => now(), 'portal_terms_confirmed_at' => now()]); $this->portal = Channel::factory()->for($this->property)->create(['name' => 'Destination Solution', 'booking_model' => 'portal_booking', 'import_enabled' => false, 'case_intake' => 'create', 'process_overrides' => ['booking' => ['contract_template_id' => $template->id]], 'settings' => ['import_url' => 'https://ds.example/a.ics', 'email_senders' => 'ds.example']]); } /** Case D: the contract is filed internally; the guest gets only a booking information. */ public function test_case_d_contract_only_internal_and_the_guest_gets_only_a_booking_information(): void { $this->configure(['contract_delivery' => 'internal', 'booking_notice' => 'automatic']); $booking = $this->booking(); $booking->refresh(); $this->assertNotNull($booking->contract_path, 'the contract was created and filed'); $this->assertNull($booking->confirmation_sent_at, 'but not sent'); Mail::assertNotSent(BookingDocumentation::class); Mail::assertNotSent(BookingConfirmed::class); Mail::assertSent(BookingNotice::class, 1); $activities = collect(CaseActivities::for($booking))->keyBy('key'); $this->assertSame([ActivityState::Done, 'Vertrag intern abgelegt'], [$activities['documents']->state, $activities['documents']->label]); $this->assertSame(ActivityState::Done, $activities['booking_notice']->state); // Sending the contract later by hand stays possible and fills the usual record. $this->assertTrue(app(SendBookingDocuments::class)->handle($booking->fresh())); $this->assertNotNull($booking->fresh()->confirmation_sent_at); Mail::assertSent(BookingDocumentation::class, 1); } public function test_the_default_setting_sends_the_contract_documents_as_before_and_no_notice(): void { $this->configure([]); $booking = $this->booking(); Mail::assertSent(BookingDocumentation::class, 1); Mail::assertNotSent(BookingNotice::class); $this->assertNotNull($booking->fresh()->confirmation_sent_at); $this->assertNull(collect(CaseActivities::for($booking->fresh()))->firstWhere('key', 'booking_notice')); } public function test_the_contract_after_release_by_hand_is_prepared_but_not_sent(): void { $this->configure(['contract_delivery' => 'manual']); $booking = $this->booking(); Mail::assertNothingSent(); $this->assertNull($booking->fresh()->contract_path); $this->assertSame('sendDocuments', collect(CaseActivities::for($booking->fresh()))->firstWhere('key', 'documents')->action); } public function test_the_portal_confirmation_is_not_needed_when_the_portal_provides_everything_so_no_own_notice_goes_out(): void { $this->configure(['booking_notice' => 'automatic_unless_portal_confirmed', 'contract_delivery' => 'internal'], capabilities: ['messages_guest' => '1']); $booking = $this->bookingFromMail(); Mail::assertNotSent(BookingNotice::class); $notice = collect(CaseActivities::for($booking->fresh()))->firstWhere('key', 'booking_notice'); $this->assertSame(ActivityState::NotApplicable, $notice->state); $this->assertStringContainsString('Das Portal informiert den Gast selbst und hat die Buchung bestätigt', $notice->detail); $this->assertFalse(SendBookingNotice::sent($booking->fresh())); } /** Case C: the occupation is protected at once; the guest-facing steps wait for the portal's mail. */ public function test_case_c_guest_facing_steps_wait_for_the_portal_confirmation_and_the_occupation_does_not(): void { $this->configure(['await_portal_confirmation' => '1', 'booking_notice' => 'automatic'], capabilities: ['sends_confirmation_mail' => '1']); // The booking is recognised without the portal's mail (e.g. a calendar entry or a manual entry). $booking = $this->booking(withGuest: true); $booking->refresh(); $this->assertTrue(Booking::query()->occupying()->whereKey($booking->id)->exists(), 'the booking is binding and occupies from the start'); $this->assertNull($booking->confirmation_sent_at); Mail::assertNothingSent(); $activities = collect(CaseActivities::for($booking))->keyBy('key'); $this->assertSame(ActivityState::Waiting, $activities['portal_confirmation']->state); $this->assertSame(ActivityState::Waiting, $activities['documents']->state); $this->assertStringContainsString('wartet auf die Bestätigungsmail des Portals', $activities['documents']->detail); $this->assertSame(ActivityState::Waiting, $activities['booking_notice']->state); $this->assertNotSame(ActivityState::Waiting, $activities['stay']->state === ActivityState::Waiting ? ActivityState::Open : ActivityState::Done, 'independent steps are not held up'); // The portal's mail arrives late and is assigned to the case by its reference: everything goes on. $this->travel(5)->hours(); $this->portalMail('Neue Buchung', $this->bookingText('DS-WAIT')); $booking->refresh(); $this->assertNotNull(PortalConfirmation::evidence($booking)); $this->assertNotNull($booking->confirmation_sent_at, 'the contract documents went out after the confirmation'); Mail::assertSent(BookingNotice::class, 1); } public function test_a_missing_confirmation_escalates_once_and_sends_nothing(): void { $this->configure(['await_portal_confirmation' => '1', 'portal_confirmation_wait_hours' => '24', 'booking_notice' => 'automatic']); $booking = $this->booking(withGuest: true); $this->artisan('bookings:advance-waiting')->assertSuccessful(); $this->assertSame(0, BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::PortalConfirmationMissing)->count(), 'within the time: nothing'); $this->travel(25)->hours(); $this->artisan('bookings:advance-waiting')->assertSuccessful(); $this->artisan('bookings:advance-waiting')->assertSuccessful(); $task = BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::PortalConfirmationMissing)->sole(); $this->assertSame(BookingTaskStatus::Open, $task->status); Mail::assertNothingSent(); $this->assertTrue(Booking::query()->occupying()->whereKey($booking->id)->exists()); $this->assertSame(ActivityState::Problem, collect(CaseActivities::for($booking->fresh()))->firstWhere('key', 'portal_confirmation')->state); // The mail comes after all: the task closes and the waiting steps go on. $this->portalMail('Neue Buchung', $this->bookingText('DS-WAIT')); $this->artisan('bookings:advance-waiting')->assertSuccessful(); $this->assertSame(BookingTaskStatus::Done, $task->fresh()->status); $this->assertNotNull($booking->fresh()->confirmation_sent_at); } public function test_the_landlord_confirms_in_the_case_and_the_waiting_steps_continue(): void { $this->configure(['await_portal_confirmation' => '1', 'booking_notice' => 'automatic']); $booking = $this->booking(withGuest: true); $this->assertNull($booking->fresh()->confirmation_sent_at); PortalConfirmation::confirm($booking->fresh(), 'Ingrid', 'im Portal gesehen'); app(ProcessRunner::class)->advance($booking->fresh(), 'portal.mail'); $this->assertSame('landlord', PortalConfirmation::evidence($booking->fresh())['source']); $this->assertNotNull($booking->fresh()->confirmation_sent_at); Mail::assertSent(BookingNotice::class, 1); } /** * @param array