Files
fuel-price/tests/Feature/Tiers/PlanResourceTest.php
Ovidiu U 4220b1b86a
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
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
2026-04-14 16:20:51 +01:00

79 lines
2.7 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([
'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();
});