2026-04-14 20:50:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Enums\Plan\Slug;
|
|
|
|
|
use App\Models\Plan;
|
|
|
|
|
|
|
|
|
|
test('plan can be created with factory', function () {
|
2026-04-14 20:56:13 +00:00
|
|
|
Plan::where('slug', Slug::Pro)->delete();
|
|
|
|
|
|
2026-04-14 20:50:41 +00:00
|
|
|
$plan = Plan::factory()->create([
|
|
|
|
|
'slug' => Slug::Pro,
|
|
|
|
|
'name' => 'Pro',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect($plan)->toBeInstanceOf(Plan::class)
|
|
|
|
|
->and($plan->slug)->toBe(Slug::Pro)
|
|
|
|
|
->and($plan->name)->toBe('Pro')
|
|
|
|
|
->and($plan->is_archived)->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('plan slug is cast to enum', function () {
|
2026-04-14 20:56:13 +00:00
|
|
|
$plan = Plan::where('slug', Slug::Starter)->first();
|
2026-04-14 20:50:41 +00:00
|
|
|
|
|
|
|
|
expect($plan->slug)->toBeInstanceOf(Slug::class)
|
|
|
|
|
->and($plan->slug)->toBe(Slug::Starter)
|
|
|
|
|
->and($plan->slug->label())->toBe('Starter');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('active scope excludes archived plans', function () {
|
2026-04-14 20:56:13 +00:00
|
|
|
$activeBefore = Plan::active()->count();
|
2026-04-14 20:50:41 +00:00
|
|
|
|
2026-04-14 20:56:13 +00:00
|
|
|
$plan = Plan::where('slug', Slug::Pro)->first();
|
|
|
|
|
$plan->update(['is_archived' => true]);
|
2026-04-14 20:50:41 +00:00
|
|
|
|
2026-04-14 20:56:13 +00:00
|
|
|
expect(Plan::active()->count())->toBe($activeBefore - 1);
|
2026-04-14 20:50:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('integer fields are cast correctly', function () {
|
2026-04-14 20:56:13 +00:00
|
|
|
$plan = Plan::where('slug', Slug::Starter)->first();
|
2026-04-14 20:50:41 +00:00
|
|
|
|
|
|
|
|
expect($plan->social_account_limit)->toBeInt()
|
|
|
|
|
->and($plan->member_limit)->toBeInt()
|
2026-04-15 01:22:04 +00:00
|
|
|
->and($plan->workspace_limit)->toBeInt()
|
2026-05-03 22:36:26 +00:00
|
|
|
->and($plan->monthly_credits_limit)->toBeInt()
|
2026-04-14 20:50:41 +00:00
|
|
|
->and($plan->sort)->toBeInt();
|
|
|
|
|
});
|