presseportale/tests/Feature/CreditPricingServiceTest.php
Kevin Adametz 4853d48b83 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>
2026-07-13 12:28:03 +00:00

73 lines
3 KiB
PHP

<?php
use App\Enums\BoostPlacement;
use App\Enums\Tier;
use App\Models\Plan;
use App\Models\User;
use App\Services\Billing\CreditPricingService;
beforeEach(function (): void {
$this->pricing = app(CreditPricingService::class);
});
test('extra-pm credits follow the tier staffel', function () {
expect($this->pricing->extraPmCredits(Tier::Einzel))->toBe(19);
expect($this->pricing->extraPmCredits(Tier::Starter))->toBe(15);
expect($this->pricing->extraPmCredits(Tier::Business))->toBe(12);
expect($this->pricing->extraPmCredits(Tier::Pro))->toBe(10);
expect($this->pricing->extraPmCredits(Tier::Agency))->toBe(8);
});
test('a user without a plan is on the Einzel tier and pays the full extra-pm rate', function () {
$user = User::factory()->create();
expect($user->currentTier())->toBe(Tier::Einzel);
expect($this->pricing->extraPmCreditsFor($user))->toBe(19);
});
test('a subscriber inherits the tier of the plan slug', function () {
$user = User::factory()->create();
$plan = Plan::factory()->create([
'slug' => 'business',
'stripe_price_id_monthly' => 'price_biz_'.fake()->unique()->randomNumber(6),
]);
subscribeUserToPlan($user, $plan);
expect($user->currentTier())->toBe(Tier::Business);
expect($this->pricing->extraPmCreditsFor($user))->toBe(12);
});
test('boost credits follow the duration staffel and reject unknown durations', function () {
expect($this->pricing->boostCredits(7))->toBe(12);
expect($this->pricing->boostCredits(14))->toBe(20);
expect($this->pricing->boostCredits(30))->toBe(35);
expect($this->pricing->boostOptions())->toBe([7 => 12, 14 => 20, 30 => 35]);
expect(fn () => $this->pricing->boostCredits(99))
->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);
});
test('review free quota follows the tier staffel', function () {
expect($this->pricing->reviewFreeQuota(Tier::Einzel))->toBe(4);
expect($this->pricing->reviewFreeQuota(Tier::Starter))->toBe(12);
expect($this->pricing->reviewFreeQuota(Tier::Business))->toBe(30);
expect($this->pricing->reviewFreeQuota(Tier::Pro))->toBe(60);
expect($this->pricing->reviewFreeQuota(Tier::Agency))->toBe(120);
expect($this->pricing->reviewDailyLimit())->toBe(10);
expect($this->pricing->reviewOverflowCost())->toBe(1);
});