Boost-Slot-Grenzen (5/3) + Kategorie-Boost zum halben Satz

Entscheidung 13.07.: verkauft wird nur, was sichtbar ist — max. 5
gleichzeitige Boosts je Startseite, 3 je Branchenseite (= die sichtbaren
Plaetze; Hero-Slider damit vertagt). Neue Stufe Kategorie-Boost (nur
Branchenseite, 6/10/18 Credits = 50 % aufgerundet); der Startseiten-Boost
(12/20/35) erscheint weiter auf Start- UND Branchenseite.

- boosts.placement (home/category, Bestand = home) + BoostPlacement-Enum;
  Preise/Slots in config/credits.php (boost_category, boost_slots)
- BoostService::slotAvailability() je Ausgabe (Portal x Sprache, Kategorie
  zusaetzlich je Rubrik); ausgebucht -> soldOut-Exception mit fruehestem
  freien Termin; Verlaengerungen halten ihren Slot, Stufen verlaengern
  unabhaengig; Kategorie-Boost invalidiert nur Kategorie-Caches
- Startseite zeigt nur Home-Boosts; Branchenseite: Kategorie-Boosts mit
  Vorrang (ihre 3 Slots sind die Garantie), Home-Boosts fuellen den Rest
- Add-on-Panel der PM-Seite: zwei Boost-Angebote, bei vollem Inventar
  "Derzeit ausgebucht — frei ab" statt Kauf-Buttons (serverseitig gegated);
  Buchungsseiten-Preisliste um die Kategorie-Staffel ergaenzt

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-07-13 12:28:03 +00:00
parent 0677728d05
commit 0474d22347
19 changed files with 702 additions and 98 deletions

View file

@ -1,9 +1,13 @@
<?php
use App\Enums\BoostPlacement;
use App\Enums\Portal;
use App\Enums\PressReleaseClassification;
use App\Enums\PressReleaseStatus;
use App\Exceptions\BoostNotAllowedException;
use App\Exceptions\InsufficientCreditsException;
use App\Models\Boost;
use App\Models\Category;
use App\Models\PressRelease;
use App\Models\User;
use App\Services\Billing\CreditWalletService;
@ -14,14 +18,36 @@ beforeEach(function (): void {
$this->wallet = app(CreditWalletService::class);
});
function boostableRelease(User $user): PressRelease
function boostableRelease(User $user, array $attributes = []): PressRelease
{
return PressRelease::factory()->published()->create([
'user_id' => $user->id,
'classification' => PressReleaseClassification::Green->value,
...$attributes,
]);
}
/**
* Belegt `$count` Slots der Stufe mit fremden, aktiv geboosteten PMs
* derselben Ausgabe (Portal × Sprache, optional Rubrik).
*
* @return array<int, Boost>
*/
function occupySlots(int $count, BoostPlacement $placement, Portal $portal, ?Category $category = null): array
{
return collect(range(1, $count))->map(function (int $i) use ($placement, $portal, $category): Boost {
$pr = PressRelease::factory()->published()->forPortal($portal)->create([
'classification' => PressReleaseClassification::Green->value,
'category_id' => ($category ?? Category::factory()->create())->id,
]);
return Boost::factory()->for($pr)->create([
'placement' => $placement,
'ends_at' => now()->addDays($i),
]);
})->all();
}
test('only published green releases are boostable', function () {
$user = User::factory()->create();
@ -96,3 +122,114 @@ test('a second boost extends from the running end instead of overlapping', funct
expect($second->starts_at->timestamp)->toBe($first->ends_at->timestamp);
expect($second->ends_at->timestamp)->toBe($first->ends_at->copy()->addDays(14)->timestamp);
});
test('a category boost costs half the staffel and only activates the category placement', function () {
$user = User::factory()->create();
$this->wallet->credit($user, 10);
$pr = boostableRelease($user);
$boost = $this->service->boost($user, $pr, 7, BoostPlacement::Category);
expect($boost->placement)->toBe(BoostPlacement::Category);
expect($boost->credits_charged)->toBe(6);
expect($this->wallet->balance($user))->toBe(4);
expect($this->service->isBoosted($pr, BoostPlacement::Category))->toBeTrue();
expect($this->service->isBoosted($pr, BoostPlacement::Home))->toBeFalse();
});
test('the placements extend independently of each other', function () {
$user = User::factory()->create();
$this->wallet->credit($user, 100);
$pr = boostableRelease($user);
$home = $this->service->boost($user, $pr, 30, BoostPlacement::Home);
$category = $this->service->boost($user, $pr, 7, BoostPlacement::Category);
// Der Kategorie-Boost startet sofort — er verlängert NICHT den laufenden
// Startseiten-Boost (getrennte Stufen).
expect($category->starts_at->timestamp)->toBeLessThan($home->ends_at->timestamp);
expect($this->service->activeUntil($pr, BoostPlacement::Category)->timestamp)
->toBe($category->ends_at->timestamp);
});
test('a full homepage slot inventory rejects new home boosts with the next free date', function () {
$this->freezeTime();
$user = User::factory()->create();
$this->wallet->credit($user, 50);
$pr = boostableRelease($user, ['portal' => Portal::Presseecho->value]);
// 5 von 5 Startseiten-Slots der Ausgabe belegt; der früheste wird in
// einem Tag frei.
occupySlots(5, BoostPlacement::Home, Portal::Presseecho);
expect(fn () => $this->service->boost($user, $pr, 7))
->toThrow(BoostNotAllowedException::class, 'ausgebucht');
expect($this->wallet->balance($user))->toBe(50);
$availability = $this->service->slotAvailability($pr, BoostPlacement::Home);
expect($availability['available'])->toBeFalse();
expect($availability['freeAt']->timestamp)->toBe(now()->addDay()->timestamp);
});
test('an extension is allowed even when all slots are taken — the release keeps its slot', function () {
$user = User::factory()->create();
$this->wallet->credit($user, 50);
$pr = boostableRelease($user, ['portal' => Portal::Presseecho->value]);
$first = $this->service->boost($user, $pr, 7);
occupySlots(5, BoostPlacement::Home, Portal::Presseecho);
$second = $this->service->boost($user, $pr, 7);
expect($second->starts_at->timestamp)->toBe($first->ends_at->timestamp);
});
test('slots on another portal or in another language do not block the booking', function () {
$user = User::factory()->create();
$this->wallet->credit($user, 50);
$pr = boostableRelease($user, ['portal' => Portal::Presseecho->value, 'language' => 'de']);
// Volle Startseite beim anderen Spoke — für diese PM irrelevant.
occupySlots(5, BoostPlacement::Home, Portal::Businessportal24);
expect($this->service->boost($user, $pr, 7))->toBeInstanceOf(Boost::class);
});
test('a full category page rejects new category boosts while other categories stay open', function () {
$user = User::factory()->create();
$this->wallet->credit($user, 50);
$category = Category::factory()->create();
$pr = boostableRelease($user, [
'portal' => Portal::Presseecho->value,
'category_id' => $category->id,
]);
// 3 von 3 Kategorie-Slots dieser Rubrik belegt.
occupySlots(3, BoostPlacement::Category, Portal::Presseecho, $category);
expect(fn () => $this->service->boost($user, $pr, 7, BoostPlacement::Category))
->toThrow(BoostNotAllowedException::class, 'ausgebucht');
// Eine PM in einer anderen Rubrik ist nicht betroffen.
$other = boostableRelease($user, ['portal' => Portal::Presseecho->value]);
expect($this->service->boost($user, $other, 7, BoostPlacement::Category))->toBeInstanceOf(Boost::class);
});
test('home boosts do not consume category slots and vice versa', function () {
$user = User::factory()->create();
$this->wallet->credit($user, 50);
$category = Category::factory()->create();
$pr = boostableRelease($user, [
'portal' => Portal::Presseecho->value,
'category_id' => $category->id,
]);
// Startseite komplett voll (auch mit PMs derselben Rubrik) — die
// Kategorie-Slots bleiben davon unberührt.
occupySlots(5, BoostPlacement::Home, Portal::Presseecho, $category);
expect($this->service->boost($user, $pr, 7, BoostPlacement::Category))->toBeInstanceOf(Boost::class);
});

View file

@ -1,5 +1,6 @@
<?php
use App\Enums\BoostPlacement;
use App\Enums\Tier;
use App\Models\Plan;
use App\Models\User;
@ -46,6 +47,16 @@ test('boost credits follow the duration staffel and reject unknown durations', f
->toThrow(InvalidArgumentException::class);
});
test('category boost credits are half the homepage staffel, rounded up', function () {
expect($this->pricing->boostCredits(7, BoostPlacement::Category))->toBe(6);
expect($this->pricing->boostCredits(14, BoostPlacement::Category))->toBe(10);
expect($this->pricing->boostCredits(30, BoostPlacement::Category))->toBe(18);
expect($this->pricing->boostOptions(BoostPlacement::Category))->toBe([7 => 6, 14 => 10, 30 => 18]);
expect(fn () => $this->pricing->boostCredits(99, BoostPlacement::Category))
->toThrow(InvalidArgumentException::class);
});
test('flat prices match the decision update', function () {
expect($this->pricing->proofPdfCredits())->toBe(3);
expect($this->pricing->depublishCredits())->toBe(35);

View file

@ -1,5 +1,6 @@
<?php
use App\Enums\BoostPlacement;
use App\Enums\PressReleaseClassification;
use App\Models\Boost;
use App\Models\Category;
@ -8,6 +9,7 @@ use App\Models\PressRelease;
use App\Models\User;
use App\Services\Billing\CreditWalletService;
use App\Services\Billing\ProofPdfService;
use App\Services\PressRelease\BoostService;
use Database\Seeders\RolesAndPermissionsSeeder;
use Livewire\Volt\Volt as LivewireVolt;
use Tests\TestCase;
@ -49,8 +51,10 @@ test('a published green release shows the boost and proof add-ons', function ()
LivewireVolt::test('customer.press-releases.show', ['id' => $pr->id])
->assertSee('Add-ons')
->assertSee('Boost — Platzierung')
->assertSee('Startseiten-Boost')
->assertSee('7 Tage für 12 Credits buchen')
->assertSee('Kategorie-Boost')
->assertSee('7 Tage für 6 Credits buchen')
->assertSee('Veröffentlichungsnachweis')
->assertSee('Für 3 Credits kaufen');
});
@ -66,7 +70,8 @@ test('add-on buttons only debit after the purchase confirmation modal', function
->call('confirmBoost', 14)
->assertSet('pendingPurchase', [
'type' => 'boost',
'label' => 'Boost — 14 Tage Platzierung',
'placement' => 'home',
'label' => 'Startseiten-Boost — 14 Tage',
'credits' => 20,
'days' => 14,
'extendsUntil' => null,
@ -160,6 +165,57 @@ test('booking a boost from the detail page debits the wallet and activates it',
expect($pr->fresh()->isBoosted())->toBeTrue();
});
test('a category boost books through the confirmation modal at the half staffel', function () {
/** @var TestCase $this */
['customer' => $customer, 'pr' => $pr] = publishedGreenPrForOwner();
$this->wallet->credit($customer, 10);
$this->actingAs($customer);
LivewireVolt::test('customer.press-releases.show', ['id' => $pr->id])
->call('confirmBoost', 7, 'category')
->assertSet('pendingPurchase.placement', 'category')
->assertSet('pendingPurchase.label', 'Kategorie-Boost — 7 Tage')
->assertSet('pendingPurchase.credits', 6)
->set('purchaseConfirmed', true)
->call('buyPendingAddOn');
expect($customer->fresh()->creditBalance())->toBe(4); // 10 - 6 (7 Tage, halber Satz)
expect(app(BoostService::class)->isBoosted($pr->fresh(), BoostPlacement::Category))->toBeTrue();
expect(app(BoostService::class)->isBoosted($pr->fresh(), BoostPlacement::Home))->toBeFalse();
});
test('sold-out slots replace the buy buttons with the next free date', function () {
/** @var TestCase $this */
['customer' => $customer, 'pr' => $pr] = publishedGreenPrForOwner();
$this->wallet->credit($customer, 40);
// Alle 5 Startseiten-Slots der Ausgabe belegt (fremde PMs, gleiche Ausgabe).
$freeAt = now()->addDays(2);
foreach (range(1, 5) as $i) {
$other = PressRelease::factory()->published()->create([
'portal' => $pr->portal->value,
'classification' => PressReleaseClassification::Green->value,
]);
Boost::factory()->for($other)->create(['ends_at' => $freeAt->copy()->addDays($i - 1)]);
}
$this->actingAs($customer);
LivewireVolt::test('customer.press-releases.show', ['id' => $pr->id])
->assertSee('Derzeit ausgebucht — der nächste Platz wird am '.$freeAt->format('d.m.Y').' frei.')
->assertDontSee('7 Tage für 12 Credits buchen')
// Der Kategorie-Boost hat ein eigenes Slot-Inventar und bleibt buchbar.
->assertSee('7 Tage für 6 Credits buchen');
// Serverseitiges Gate: ein direkter Kauf-Call bucht trotzdem nicht.
LivewireVolt::test('customer.press-releases.show', ['id' => $pr->id])
->call('buyBoost', 7);
expect($customer->fresh()->creditBalance())->toBe(40);
expect($pr->fresh()->isBoosted())->toBeFalse();
});
test('buying a proof from the detail page unlocks the download', function () {
/** @var TestCase $this */
['customer' => $customer, 'pr' => $pr] = publishedGreenPrForOwner();

View file

@ -1,5 +1,6 @@
<?php
use App\Enums\BoostPlacement;
use App\Enums\Portal;
use App\Enums\PressReleaseClassification;
use App\Models\Boost;
@ -10,6 +11,7 @@ use App\Models\User;
use App\Services\Billing\CreditWalletService;
use App\Services\PressRelease\BoostService;
use App\Services\Web\HomePageData;
use Illuminate\Support\Facades\Cache;
use Tests\TestCase;
/**
@ -126,3 +128,75 @@ test('a boosted release leads its category page and is labelled', function () {
'Neueste unbezahlte Meldung',
]);
});
test('a category boost leads its category page but never the homepage', function () {
/** @var TestCase $this */
['boosted' => $boosted, 'newest' => $newest] = boostPlacementFixture();
Boost::factory()->for($boosted)->category()->create();
// Branchenseite: Kategorie-Boost besetzt den Lead-Slot.
$this->get('https://presseecho.test/de/category/energie-klima')
->assertSuccessful()
->assertSeeTextInOrder(['Top-Platzierung', 'Geboostete aeltere Meldung']);
// Startseite: bleibt bei der Chronologie — der Kategorie-Boost kauft
// sie nicht mit (Entscheidung 13.07.).
$data = app(HomePageData::class)->build(Portal::Presseecho);
expect($data['leadRelease']->id)->toBe($newest->id)
->and($data['boostedIds'])->toBe([]);
});
test('category boosts take the category slots ahead of homepage boosts', function () {
/** @var TestCase $this */
['boosted' => $categoryBoosted, 'newest' => $newest, 'category' => $category, 'company' => $company] = boostPlacementFixture();
// Neuere PM mit Startseiten-Boost — auf der Branchenseite hat der
// Kategorie-Boost trotzdem Vorrang (seine 3 Slots sind die Garantie).
$homeBoosted = PressRelease::factory()
->published()
->forPortal(Portal::Presseecho)
->for($category)
->for($company)
->create([
'title' => 'Startseiten-Boost Meldung',
'slug' => 'startseiten-boost-meldung',
'published_at' => now()->subHour(),
'classification' => PressReleaseClassification::Green->value,
]);
Boost::factory()->for($categoryBoosted)->category()->create();
Boost::factory()->for($homeBoosted)->create();
// Ohne Vorrang würde die neuere Startseiten-Boost-Meldung den Lead
// chronologisch gewinnen — der Kategorie-Boost muss vorne stehen.
$this->get('https://presseecho.test/de/category/energie-klima')
->assertSuccessful()
->assertSeeTextInOrder([
'Geboostete aeltere Meldung',
'Startseiten-Boost Meldung',
]);
});
test('booking a category boost invalidates the category page but keeps the homepage cache', function () {
/** @var TestCase $this */
['boosted' => $boosted, 'newest' => $newest] = boostPlacementFixture();
$owner = User::factory()->create(['is_active' => true]);
app(CreditWalletService::class)->credit($owner, 40);
// Beide Seiten in den Cache legen — noch ohne Boost.
expect(app(HomePageData::class)->build(Portal::Presseecho)['leadRelease']->id)->toBe($newest->id);
$this->get('https://presseecho.test/de/category/energie-klima')
->assertSuccessful()
->assertDontSeeText('Top-Platzierung');
app(BoostService::class)->boost($owner, $boosted, 7, BoostPlacement::Category);
// Branchenseite sofort aktualisiert, Startseiten-Cache bleibt stehen
// (der Kategorie-Boost berührt die Startseite nicht).
expect(Cache::has('web.home.presseecho.de'))->toBeTrue();
$this->get('https://presseecho.test/de/category/energie-klima')
->assertSuccessful()
->assertSeeText('Top-Platzierung');
});