The features JSON column required defensive fallback stubs in three places (Plan::resolveForUser, PlanFeatures::__construct, PlanSeeder) and silently swallowed misspelled keys. Typed columns give Eloquent type-safe reads, simplify the Filament form (no more dotted JSON paths), and let resolveForUser fail loud when the free row is missing. PlanFeatures public API is unchanged so consumers (jobs, middleware) need no rewrites — one missed JSON read in SendScheduledWhatsAppJob was caught and converted to a typed where() query. tests/Pest.php seeds PlanSeeder in beforeEach so any feature test that resolves a plan finds the free row, mirroring production where plans always exist. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
79 lines
2.6 KiB
PHP
79 lines
2.6 KiB
PHP
<?php
|
|
|
|
use App\Filament\Resources\Plans\Pages\EditPlan;
|
|
use App\Filament\Resources\Plans\Pages\ListPlans;
|
|
use App\Models\Plan;
|
|
use App\Models\User;
|
|
use Filament\Actions\DeleteAction;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
$this->artisan('db:seed', ['--class' => 'PlanSeeder']);
|
|
$this->actingAs(User::factory()->create(['is_admin' => true]));
|
|
});
|
|
|
|
// ─── ListPlans ────────────────────────────────────────────────────────────────
|
|
|
|
it('lists all four plans', function (): void {
|
|
Livewire::test(ListPlans::class)
|
|
->assertCanSeeTableRecords(Plan::all());
|
|
});
|
|
|
|
it('has no create button on the list page', function (): void {
|
|
Livewire::test(ListPlans::class)
|
|
->assertActionDoesNotExist('create');
|
|
});
|
|
|
|
// ─── EditPlan — no delete ─────────────────────────────────────────────────────
|
|
|
|
it('has no delete action on the edit page', function (): void {
|
|
$plan = Plan::where('name', 'basic')->first();
|
|
|
|
Livewire::test(EditPlan::class, ['record' => $plan->id])
|
|
->assertActionDoesNotExist(DeleteAction::class);
|
|
});
|
|
|
|
// ─── EditPlan — saves features correctly ─────────────────────────────────────
|
|
|
|
it('saves email frequency on edit', function (): void {
|
|
$plan = Plan::where('name', 'free')->first();
|
|
|
|
Livewire::test(EditPlan::class, ['record' => $plan->id])
|
|
->fillForm([
|
|
'email_frequency' => 'daily',
|
|
])
|
|
->call('save')
|
|
->assertHasNoFormErrors();
|
|
|
|
expect($plan->fresh()->email_frequency)->toBe('daily');
|
|
});
|
|
|
|
it('saves sms daily limit on edit', function (): void {
|
|
$plan = Plan::where('name', 'plus')->first();
|
|
|
|
Livewire::test(EditPlan::class, ['record' => $plan->id])
|
|
->fillForm([
|
|
'sms_daily_limit' => 3,
|
|
])
|
|
->call('save')
|
|
->assertHasNoFormErrors();
|
|
|
|
expect($plan->fresh()->sms_daily_limit)->toBe(3);
|
|
});
|
|
|
|
it('saves null fuel type max for pro (unlimited)', function (): void {
|
|
$plan = Plan::where('name', 'pro')->first();
|
|
|
|
Livewire::test(EditPlan::class, ['record' => $plan->id])
|
|
->fillForm([
|
|
'max_fuel_types' => null,
|
|
])
|
|
->call('save')
|
|
->assertHasNoFormErrors();
|
|
|
|
expect($plan->fresh()->max_fuel_types)->toBeNull();
|
|
});
|