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_conditions_decide_which_annexes_fit_a_booking(): void { $linen = Extra::query()->create(['property_id' => $this->property->id, 'name' => 'Wäschepaket', 'price' => 2300, 'pricing' => 'per_item', 'is_active' => true]); $portal = Channel::factory()->for($this->property)->create(['name' => 'FeWo-direkt']); $always = $this->annex('WLAN', ContractAnnex::ALWAYS); $withLinen = $this->annex('Wäsche', ContractAnnex::EXTRA, $linen->id); $viaPortal = $this->annex('Portal', ContractAnnex::CHANNEL, $portal->id); $manual = $this->annex('Key', ContractAnnex::MANUAL); $template = ContractTemplate::query()->create(['name' => 'T', 'version' => 1, 'annex_ids' => [$always->id, $withLinen->id, $viaPortal->id, $manual->id]]); $plain = $this->booking(); $this->assertSame(['WLAN'], $template->annexesFor($plain)->pluck('name')->all()); $withExtra = $this->booking(['extras' => [$linen->id => 2], 'arrival' => '2026-12-01', 'departure' => '2026-12-04']); $this->assertEqualsCanonicalizing(['WLAN', 'Wäsche'], $template->annexesFor($withExtra)->pluck('name')->all()); $fromPortal = $this->booking(['import_channel_id' => $portal->id, 'source' => 'portal', 'arrival' => '2026-11-20', 'departure' => '2026-11-23']); $this->assertEqualsCanonicalizing(['WLAN', 'Portal'], $template->annexesFor($fromPortal)->pluck('name')->all()); } public function test_the_offer_freezes_the_matching_annexes_and_shows_them_everywhere(): void { $annex = $this->annex('WLAN', ContractAnnex::ALWAYS, null, 'Anlage WLAN', '
WLAN für {{ mieter }}
'); $template = ContractTemplate::query()->create(['name' => 'T', 'version' => 1, 'body' => 'Vertrag
', 'annex_ids' => [$annex->id]]); $offer = app(SendOffer::class)->handle($this->booking(), ['contract_template_id' => $template->id]); $this->assertSame([$annex->id], array_column($offer->offer_terms['annexes'], 'id')); $annex->update(['body' => 'GEÄNDERT
']); $rendered = OfferTerms::annexes($offer->fresh()); $this->assertStringContainsString($offer->guest->full_name, $rendered[0]['html']); $this->assertStringNotContainsString('GEÄNDERT', $rendered[0]['html']); $this->get(app(SendOffer::class)->offerUrl($offer))->assertOk()->assertSee('Anlage: Anlage WLAN'); Storage::disk('local')->assertExists($offer->offer_path); } public function test_an_explicit_selection_in_the_offer_replaces_the_automatic_one(): void { $auto = $this->annex('WLAN', ContractAnnex::ALWAYS); $manual = $this->annex('Key', ContractAnnex::MANUAL); $template = ContractTemplate::query()->create(['name' => 'T', 'version' => 1, 'annex_ids' => [$auto->id]]); $offer = app(SendOffer::class)->handle($this->booking(), ['contract_template_id' => $template->id, 'annex_ids' => [$manual->id]]); $this->assertSame(['Key'], array_column($offer->offer_terms['annexes'], 'name')); $none = app(SendOffer::class)->handle($this->booking(['arrival' => '2026-12-01', 'departure' => '2026-12-04']), ['contract_template_id' => $template->id, 'annex_ids' => []]); $this->assertSame([], $none->offer_terms['annexes']); } public function test_used_annex_versions_are_locked_and_new_versions_can_be_made(): void { $annex = $this->annex('WLAN', ContractAnnex::ALWAYS); $template = ContractTemplate::query()->create(['name' => 'T', 'version' => 1, 'annex_ids' => [$annex->id]]); $this->assertTrue(ContractAnnexResource::canEdit($annex)); app(SendOffer::class)->handle($this->booking(), ['contract_template_id' => $template->id]); $this->assertFalse(ContractAnnexResource::canEdit($annex->fresh())); $this->actingAs(User::factory()->create()); Livewire::test(ListContractAnnexes::class)->callAction(TestAction::make('newVersion')->table($annex), []); $this->assertSame([1, 2], ContractAnnex::query()->where('name', 'WLAN')->orderBy('version')->pluck('version')->all()); } public function test_recording_extra_services_in_the_booking_changes_the_preselected_annexes(): void { $linen = Extra::query()->create(['property_id' => $this->property->id, 'name' => 'Wäschepaket', 'price' => 0, 'pricing' => 'per_item', 'is_active' => true]); $annex = $this->annex('Wäsche', ContractAnnex::EXTRA, $linen->id); $template = ContractTemplate::query()->create(['name' => 'T', 'version' => 1, 'annex_ids' => [$annex->id]]); $this->property->update(['contract_template_id' => $template->id]); $booking = $this->booking(); $this->actingAs(User::factory()->create()); $this->assertSame([], OfferTerms::templateFor($booking)->annexesFor($booking)->all()); Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()]) ->callAction('services', ['items' => [['extra_id' => $linen->id, 'quantity' => 2]]]) ->assertNotified('Zusatzleistungen gespeichert'); $booking = $booking->fresh(); $this->assertSame([$linen->id => 2], $booking->extras); $this->assertSame(['Wäsche'], OfferTerms::templateFor($booking)->annexesFor($booking)->pluck('name')->all()); } private function annex(string $name, string $type, ?int $conditionId = null, string $title = 'Anlage', string $body = 'Text
'): ContractAnnex { return ContractAnnex::query()->create(['name' => $name, 'version' => 1, 'title' => $title, 'body' => $body, 'condition_type' => $type, 'condition_id' => $conditionId]); } /** * @param array