Echte Credit-Wallet (1 Credit = 1 EUR) mit append-only Ledger als Basis fuer die Credit-Oekonomie aus dem Decision-Update (Rev. 4): - credit_wallets (denormalisierter Saldo) + credit_transactions (Ledger, vorzeichenbehaftet, balance_after, polymorphe reference) - CreditWalletService: einziger Schreibpfad, atomar mit Row-Lock, InsufficientCreditsException mit shortfall fuer den Mini-Checkout - Tier-Enum (Einzel/Starter/Business/Pro/Agency) + User::currentTier() - CreditPricingService: tier-gestaffelte Ableitung aus config/credits.php (Extra-PM 19/15/12/10/8, Boost 12/20/35, PDF 3, Depublish 25, Pruef-Quota) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
62 lines
2.4 KiB
PHP
62 lines
2.4 KiB
PHP
<?php
|
|
|
|
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('flat prices match the decision update', function () {
|
|
expect($this->pricing->proofPdfCredits())->toBe(3);
|
|
expect($this->pricing->depublishCredits())->toBe(25);
|
|
});
|
|
|
|
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);
|
|
});
|