now = CarbonImmutable::parse('2026-02-01 10:00'); $this->property = Property::factory()->create(['cleaning_fee' => 10000, 'included_guests' => 2]); Season::factory()->for($this->property)->create(['name' => 'Winter', 'starts_on' => '2026-01-03', 'ends_on' => '2026-06-01', 'nightly_rate' => 5000, 'min_nights' => 3]); } public function test_only_public_offers_without_code_in_their_booking_window_are_shown(): void { $this->offer(['name' => 'Ab 3 Nächten', 'min_nights' => 3]); $this->offer(['name' => 'Intern', 'is_public' => false]); $this->offer(['name' => 'Stammgast', 'code' => 'OSTSEE']); $this->offer(['name' => 'Abgelaufen', 'bookable_until' => '2026-01-31 23:59']); $this->offer(['name' => 'Vorbei', 'stay_until' => '2026-01-20']); $this->offer(['name' => 'Inaktiv', 'is_active' => false]); $this->assertSame(['Ab 3 Nächten'], $this->titles()); } public function test_highlighted_offers_come_first_then_priority(): void { $this->offer(['name' => 'Normal', 'priority' => 0]); $this->offer(['name' => 'Wichtig', 'priority' => 5]); $this->offer(['name' => 'Hervorgehoben', 'is_featured' => true]); $this->assertSame(['Hervorgehoben', 'Wichtig', 'Normal'], $this->titles()); $this->assertSame(['Hervorgehoben'], $this->showcase()->current($this->property, $this->now, featuredOnly: true)->map(fn (AdvertisedOffer $offer): string => $offer->title)->all()); } public function test_fixed_dates_are_advertised_with_their_price_only_while_free(): void { $this->offer([ 'name' => 'Ostsee-Woche', 'kind' => OfferKind::FixedDates, 'stay_from' => '2026-03-07', 'stay_until' => '2026-03-14', 'discount_type' => DiscountType::FixedStayPrice, 'discount_value' => 29900, ]); $advertised = $this->showcase()->current($this->property, $this->now)->sole(); $this->assertSame('2026-03-07', $advertised->arrival->toDateString()); $this->assertSame(29900 + 10000, $advertised->quote->total()); $this->assertSame(7 * 5000 + 10000, $advertised->regularTotal()); $this->assertStringContainsString('anreise=2026-03-07', $advertised->bookingUrl()); BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-03-10', 'ends_on' => '2026-03-12']); $this->assertSame([], $this->titles()); } public function test_gap_filler_advertises_each_gap_found_in_the_calendar(): void { BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-05', 'ends_on' => '2026-02-10']); BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-12', 'ends_on' => '2026-02-20']); BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-23', 'ends_on' => '2026-03-01']); $this->offer(['name' => 'Lückenfüller', 'kind' => OfferKind::GapFiller, 'max_gap_nights' => 4, 'waives_min_stay' => true, 'discount_value' => 20]); $gaps = $this->showcase()->current($this->property, $this->now) ->map(fn (AdvertisedOffer $offer): string => $offer->arrival->format('d.m.').'–'.$offer->departure->format('d.m.')) ->all(); $this->assertSame(['10.02.–12.02.', '20.02.–23.02.'], $gaps); } public function test_gap_below_minimum_stay_is_not_advertised_unless_the_offer_waives_it(): void { $this->property->update(['min_stay_fill_gaps' => false]); BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-05', 'ends_on' => '2026-02-10']); BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-12', 'ends_on' => '2026-02-20']); $this->offer(['name' => 'Lückenfüller', 'kind' => OfferKind::GapFiller, 'max_gap_nights' => 4, 'discount_value' => 20]); $this->assertSame([], $this->titles()); } public function test_offers_section_shows_the_advertised_offers_on_the_website(): void { $this->travelTo($this->now); $unusedLandlord = $this->property->tenant_id; $this->property->delete(); Tenant::query()->whereKey($unusedLandlord)->delete(); $this->seed([PropertySeeder::class, SiteSeeder::class]); SpecialOffer::factory()->for(Property::query()->sole())->create(['name' => 'Ab 3 Nächten −10 %', 'min_nights' => 3, 'discount_value' => 10]); $this->withoutVite() ->get(route('booking.create')) ->assertOk() ->assertSee('Ab 3 Nächten −10 %') ->assertSee('ab 3 Nächten'); } /** * @return list */ private function titles(): array { return $this->showcase()->current($this->property, $this->now)->map(fn (AdvertisedOffer $offer): string => $offer->title)->all(); } private function showcase(): OfferShowcase { return app(OfferShowcase::class); } /** * @param array $attributes */ private function offer(array $attributes): SpecialOffer { return SpecialOffer::factory()->for($this->property)->create($attributes); } }