2026-05-03 20:26:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Features\MemberLimit;
|
2026-05-03 22:36:26 +00:00
|
|
|
use App\Features\MonthlyCreditsLimit;
|
2026-05-03 20:26:55 +00:00
|
|
|
use App\Features\SocialAccountLimit;
|
|
|
|
|
use App\Features\WorkspaceLimit;
|
|
|
|
|
use App\Models\Account;
|
|
|
|
|
use App\Models\Plan;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Laravel\Pennant\Feature;
|
|
|
|
|
|
2026-05-07 13:59:48 +00:00
|
|
|
test('forgetPlanFeatureCache drops the cached plan-scoped features', function () {
|
2026-05-03 20:26:55 +00:00
|
|
|
$starter = Plan::where('slug', 'starter')->first();
|
|
|
|
|
$plus = Plan::where('slug', 'plus')->first();
|
|
|
|
|
|
|
|
|
|
$account = Account::factory()->create(['plan_id' => $starter->id]);
|
|
|
|
|
|
2026-05-07 13:59:48 +00:00
|
|
|
// Prime the Pennant cache against the starter plan.
|
|
|
|
|
Feature::for($account)->value(WorkspaceLimit::class);
|
|
|
|
|
Feature::for($account)->value(SocialAccountLimit::class);
|
|
|
|
|
Feature::for($account)->value(MemberLimit::class);
|
|
|
|
|
Feature::for($account)->value(MonthlyCreditsLimit::class);
|
|
|
|
|
|
|
|
|
|
expect(DB::table('features')->where('scope', 'account|'.$account->id)->count())
|
|
|
|
|
->toBe(4);
|
2026-05-03 20:26:55 +00:00
|
|
|
|
2026-05-07 13:59:48 +00:00
|
|
|
// Move the account to a plan with different limits and forget the cache.
|
2026-05-03 20:26:55 +00:00
|
|
|
$account->update(['plan_id' => $plus->id]);
|
2026-05-07 13:59:48 +00:00
|
|
|
$account->forgetPlanFeatureCache();
|
2026-05-03 20:26:55 +00:00
|
|
|
$account->load('plan');
|
|
|
|
|
|
2026-05-07 13:59:48 +00:00
|
|
|
expect(DB::table('features')->where('scope', 'account|'.$account->id)->count())
|
|
|
|
|
->toBe(0);
|
|
|
|
|
|
2026-05-03 20:26:55 +00:00
|
|
|
expect(Feature::for($account)->value(WorkspaceLimit::class))->toBe($plus->workspace_limit);
|
|
|
|
|
expect(Feature::for($account)->value(SocialAccountLimit::class))->toBe($plus->social_account_limit);
|
|
|
|
|
expect(Feature::for($account)->value(MemberLimit::class))->toBe($plus->member_limit);
|
2026-05-03 22:36:26 +00:00
|
|
|
expect(Feature::for($account)->value(MonthlyCreditsLimit::class))->toBe($plus->monthly_credits_limit);
|
2026-05-03 20:26:55 +00:00
|
|
|
});
|