Add tier feature design spec, annual billing, fuel type normalization, and admin subscription management
- Add comprehensive tier feature matrix spec defining Free/Basic/Plus/Pro capabilities across recommendations, predictions, history, logs, tools, and family sharing - Add `stripe_price_id_annual` column to plans table and rename existing column to `stripe_price_id_monthly` - Normalize legacy fuel type aliases (petrol→e10, diesel→b7_standard) in users table - Implement BillingController with checkout, portal, success/cancel routes supporting monthly/annual cadence - Add admin subscription assignment in Filament user edit page with admin-granted subscription support - Add DowngradeUserOnSubscriptionDeleted listener to disable WhatsApp/SMS preferences on subscription cancellation - Add MissedNotificationsOverview widget to Filament user detail page - Add PollFuelPricesTest covering auto-refresh scenarios - Add PriceReliability enum with reliability classification based on price age - Add fuelTypes.js constants file exporting FUEL_TYPES from window global
This commit is contained in:
66
tests/Feature/Payments/AssignTierFromEditPageTest.php
Normal file
66
tests/Feature/Payments/AssignTierFromEditPageTest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
use App\Filament\Resources\UserResource\Pages\EditUser;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function (): void {
|
||||
$this->artisan('db:seed', ['--class' => 'PlanSeeder']);
|
||||
$admin = User::factory()->create(['is_admin' => true]);
|
||||
$this->actingAs($admin);
|
||||
});
|
||||
|
||||
it('creates an admin-granted subscription when a paid tier is chosen', function (): void {
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::test(EditUser::class, ['record' => $user->id])
|
||||
->fillForm(['tier' => 'basic', 'cadence' => 'monthly'])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
$subscription = $user->subscriptions()->first();
|
||||
expect($user->subscriptions()->count())->toBe(1)
|
||||
->and($subscription->stripe_id)->toStartWith('admin_')
|
||||
->and($subscription->stripe_status)->toBe('active')
|
||||
->and(Plan::resolveForUser($user->fresh())->name)->toBe('basic');
|
||||
});
|
||||
|
||||
it('removes any admin-granted subscription when tier is set to free', function (): void {
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::test(EditUser::class, ['record' => $user->id])
|
||||
->fillForm(['tier' => 'basic', 'cadence' => 'monthly'])
|
||||
->call('save');
|
||||
expect($user->subscriptions()->count())->toBe(1);
|
||||
|
||||
Livewire::test(EditUser::class, ['record' => $user->fresh()->id])
|
||||
->fillForm(['tier' => 'free'])
|
||||
->call('save');
|
||||
|
||||
expect($user->subscriptions()->count())->toBe(0)
|
||||
->and(Plan::resolveForUser($user->fresh())->name)->toBe('free');
|
||||
});
|
||||
|
||||
it('refuses to change tier when the user has a real Stripe subscription', function (): void {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$user->subscriptions()->create([
|
||||
'type' => 'default',
|
||||
'stripe_id' => 'sub_real_stripe_id',
|
||||
'stripe_status' => 'active',
|
||||
'stripe_price' => 'price_plus_monthly',
|
||||
'quantity' => 1,
|
||||
]);
|
||||
|
||||
Livewire::test(EditUser::class, ['record' => $user->id])
|
||||
->fillForm(['tier' => 'pro', 'cadence' => 'monthly'])
|
||||
->call('save');
|
||||
|
||||
$adminCount = $user->subscriptions()->where('stripe_id', 'like', 'admin_%')->count();
|
||||
expect($adminCount)->toBe(0)
|
||||
->and($user->subscriptions()->count())->toBe(1);
|
||||
});
|
||||
Reference in New Issue
Block a user