travelTo(CarbonImmutable::parse('2026-10-22 10:00')); $this->seed([PropertySeeder::class, SiteSeeder::class]); $this->property = Property::sole(); Mail::fake(); Storage::fake('local'); $this->withoutVite(); } public function test_offer_uses_the_chosen_template_and_freezes_it_with_name_and_version(): void { $template = $this->template('Portal XY', ['terms' => '

Bedingungen Portal XY

', 'cancellation' => '

Storno bis 30 Tage

']); $offer = $this->offer(['contract_template_id' => $template->id]); $this->assertSame('Bedingungen Portal XY', trim(strip_tags($offer->offerText('contract.terms')))); $this->assertSame(['id' => $template->id, 'name' => 'Portal XY', 'version' => 1], $offer->offer_terms['template']); $this->assertNotNull($offer->offer_pdf_sha256); // blank template fields fall back to the website text $this->assertNotEmpty($offer->offerText('contract.closing')); } public function test_default_order_is_explicit_choice_then_portal_then_property(): void { $propertyDefault = $this->template('Direkt', ['terms' => '

DIREKT

']); $portalDefault = $this->template('Portal', ['terms' => '

PORTAL

']); $this->property->update(['contract_template_id' => $propertyDefault->id]); $channel = Channel::factory()->for($this->property)->create(['process_overrides' => ['booking' => ['contract_template_id' => $portalDefault->id]]]); $direct = $this->offer(); $viaPortal = $this->offer([], ['import_channel_id' => $channel->id, 'arrival' => '2026-12-01', 'departure' => '2026-12-04']); $this->assertSame('DIREKT', trim(strip_tags($direct->offerText('contract.terms')))); $this->assertSame('PORTAL', trim(strip_tags($viaPortal->offerText('contract.terms')))); } public function test_editing_a_template_later_does_not_change_a_sent_offer_or_the_contract(): void { $template = $this->template('Direkt', ['terms' => '

VERSION EINS

']); $offer = $this->offer(['contract_template_id' => $template->id]); $template->update(['texts' => ['terms' => '

GEƄNDERT

']]); app(AcceptOffer::class)->handle($offer->fresh(), 1); $this->assertSame('VERSION EINS', trim(strip_tags($offer->fresh()->offerText('contract.terms')))); } public function test_used_versions_are_locked_and_a_new_version_can_be_made(): void { $template = $this->template('Direkt', ['terms' => '

A

']); $this->assertTrue(ContractTemplateResource::canEdit($template)); $this->offer(['contract_template_id' => $template->id]); $this->assertFalse(ContractTemplateResource::canEdit($template->fresh())); $this->assertFalse(ContractTemplateResource::canDelete($template->fresh())); $this->actingAs(User::factory()->create()); Livewire::test(ListContractTemplates::class)->callAction(TestAction::make('newVersion')->table($template), []); $this->assertSame([1, 2], ContractTemplate::query()->where('name', 'Direkt')->orderBy('version')->pluck('version')->all()); $this->assertTrue(ContractTemplateResource::canEdit(ContractTemplate::query()->where('version', 2)->sole())); } public function test_final_contract_is_a_document_of_record_that_is_never_rewritten(): void { $offer = $this->offer(); app(AcceptOffer::class)->handle($offer->fresh(), 1); $booking = $offer->fresh(); $content = Storage::disk('local')->get($booking->contract_path); $this->assertSame(hash('sha256', $content), $booking->contract_pdf_sha256); $this->travel(3)->days(); app(ConfirmBooking::class)->resend($booking); app(RentalContract::class)->generate($booking->fresh()); $this->assertSame($content, Storage::disk('local')->get($booking->contract_path)); $this->assertSame($booking->contract_pdf_sha256, $booking->fresh()->contract_pdf_sha256); } /** * @param array $texts */ private function template(string $name, array $texts): ContractTemplate { return ContractTemplate::query()->create(['released_at' => now(), 'name' => $name, 'version' => 1, 'texts' => $texts]); } /** * @param array $changes * @param array $attributes */ private function offer(array $changes = [], array $attributes = []): Booking { $booking = Booking::factory()->for($this->property)->reserved(now()->addHours(48))->create([ 'arrival' => '2026-11-07', 'departure' => '2026-11-10', 'guests' => 2, ...$attributes, ]); return app(SendOffer::class)->handle($booking, $changes); } }