65 lines
2.4 KiB
PHP
65 lines
2.4 KiB
PHP
<?php
|
|
|
|
use App\Actions\BookAddon;
|
|
use App\Actions\OpenSubscription;
|
|
use App\Models\Order;
|
|
use App\Models\Subscription;
|
|
use App\Services\Billing\AddonCatalogue;
|
|
|
|
/**
|
|
* Höchstens drei Blöcke.
|
|
*
|
|
* Der Deckel liegt dort, wo Aufsteigen billiger wird: Start + 3 Blöcke sind
|
|
* 90 GB für 84 €, Team ist 85 GB für 79 € mit mehr Nutzern und mehr RAM. Er
|
|
* gehört in die Aktion und nicht ins Formular — dieselbe Lektion wie bei
|
|
* ReissueTakeover (v1.3.82): die Ansicht versteckte den Knopf, die Methode
|
|
* prüfte nichts, und Codex fand es zweimal.
|
|
*/
|
|
function limitContract(string $plan = 'start'): Subscription
|
|
{
|
|
$order = Order::factory()->create(['plan' => $plan, 'datacenter' => 'fsn', 'status' => 'paid']);
|
|
|
|
return app(OpenSubscription::class)($order);
|
|
}
|
|
|
|
it('lehnt den vierten Block auf einmal ab', function () {
|
|
$subscription = limitContract();
|
|
|
|
expect(fn () => app(BookAddon::class)($subscription, AddonCatalogue::STORAGE, 4))
|
|
->toThrow(RuntimeException::class);
|
|
|
|
expect($subscription->addons()->count())->toBe(0);
|
|
});
|
|
|
|
it('zählt drei einzelne Buchungen als drei', function () {
|
|
$subscription = limitContract();
|
|
|
|
foreach (range(1, 3) as $ignored) {
|
|
app(BookAddon::class)($subscription, AddonCatalogue::STORAGE, 1, Order::factory()->create([
|
|
'customer_id' => $subscription->customer_id, 'type' => 'addon', 'addon_key' => 'storage', 'status' => 'paid',
|
|
]));
|
|
}
|
|
|
|
expect(fn () => app(BookAddon::class)($subscription, AddonCatalogue::STORAGE, 1, Order::factory()->create([
|
|
'customer_id' => $subscription->customer_id, 'type' => 'addon', 'addon_key' => 'storage', 'status' => 'paid',
|
|
])))->toThrow(RuntimeException::class);
|
|
|
|
expect((int) $subscription->addons()->active()->sum('quantity'))->toBe(3);
|
|
});
|
|
|
|
it('zählt eine gekündigte Buchung nicht mit', function () {
|
|
$subscription = limitContract();
|
|
$addon = app(BookAddon::class)($subscription, AddonCatalogue::STORAGE, 3);
|
|
|
|
app(BookAddon::class)->cancel($addon);
|
|
|
|
expect(app(AddonCatalogue::class)->bookableQuantity($subscription->refresh(), AddonCatalogue::STORAGE))->toBe(3);
|
|
});
|
|
|
|
it('sagt, wie viele noch gehen', function () {
|
|
$subscription = limitContract();
|
|
app(BookAddon::class)($subscription, AddonCatalogue::STORAGE, 2);
|
|
|
|
expect(app(AddonCatalogue::class)->bookableQuantity($subscription->refresh(), AddonCatalogue::STORAGE))->toBe(1);
|
|
});
|