Add subscription tiers, notification preferences, and logging infrastructure
- Add database migrations for plans, subscriptions, notification preferences, and notification log tables - Implement DispatchUserNotificationJob to handle channel resolution, daily limits, and logging (sent/tier_restricted/daily_limit) - Add SendScheduledWhatsAppJob for scheduled notification delivery - Create PlanFeatures service to resolve tier capabilities, check daily limits, and validate fuel
This commit is contained in:
78
tests/Feature/Tiers/PlanResourceTest.php
Normal file
78
tests/Feature/Tiers/PlanResourceTest.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?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([
|
||||
'features.email.frequency' => 'daily',
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
expect($plan->fresh()->features['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([
|
||||
'features.sms.daily_limit' => 3,
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
expect($plan->fresh()->features['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([
|
||||
'features.fuel_types.max' => null,
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
expect($plan->fresh()->features['fuel_types']['max'])->toBeNull();
|
||||
});
|
||||
Reference in New Issue
Block a user