refactor: flatten plans.features JSON to typed columns
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>
This commit is contained in:
@@ -43,12 +43,12 @@ it('saves email frequency on edit', function (): void {
|
||||
|
||||
Livewire::test(EditPlan::class, ['record' => $plan->id])
|
||||
->fillForm([
|
||||
'features.email.frequency' => 'daily',
|
||||
'email_frequency' => 'daily',
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
expect($plan->fresh()->features['email']['frequency'])->toBe('daily');
|
||||
expect($plan->fresh()->email_frequency)->toBe('daily');
|
||||
});
|
||||
|
||||
it('saves sms daily limit on edit', function (): void {
|
||||
@@ -56,12 +56,12 @@ it('saves sms daily limit on edit', function (): void {
|
||||
|
||||
Livewire::test(EditPlan::class, ['record' => $plan->id])
|
||||
->fillForm([
|
||||
'features.sms.daily_limit' => 3,
|
||||
'sms_daily_limit' => 3,
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
expect($plan->fresh()->features['sms']['daily_limit'])->toBe(3);
|
||||
expect($plan->fresh()->sms_daily_limit)->toBe(3);
|
||||
});
|
||||
|
||||
it('saves null fuel type max for pro (unlimited)', function (): void {
|
||||
@@ -69,10 +69,10 @@ it('saves null fuel type max for pro (unlimited)', function (): void {
|
||||
|
||||
Livewire::test(EditPlan::class, ['record' => $plan->id])
|
||||
->fillForm([
|
||||
'features.fuel_types.max' => null,
|
||||
'max_fuel_types' => null,
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
expect($plan->fresh()->features['fuel_types']['max'])->toBeNull();
|
||||
expect($plan->fresh()->max_fuel_types)->toBeNull();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user