- 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
43 lines
2.1 KiB
PHP
43 lines
2.1 KiB
PHP
<?php
|
|
|
|
use App\Listeners\DowngradeUserOnSubscriptionDeleted;
|
|
use App\Models\User;
|
|
use App\Models\UserNotificationPreference;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Cashier\Events\WebhookReceived;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('disables whatsapp and sms preferences when a stripe subscription is deleted', function (): void {
|
|
$user = User::factory()->create(['stripe_id' => 'cus_test_123']);
|
|
|
|
UserNotificationPreference::query()->insert([
|
|
['user_id' => $user->id, 'channel' => 'whatsapp', 'fuel_type' => 'E10', 'enabled' => true, 'created_at' => now(), 'updated_at' => now()],
|
|
['user_id' => $user->id, 'channel' => 'sms', 'fuel_type' => 'E10', 'enabled' => true, 'created_at' => now(), 'updated_at' => now()],
|
|
['user_id' => $user->id, 'channel' => 'email', 'fuel_type' => 'E10', 'enabled' => true, 'created_at' => now(), 'updated_at' => now()],
|
|
]);
|
|
|
|
(new DowngradeUserOnSubscriptionDeleted)->handle(new WebhookReceived([
|
|
'type' => 'customer.subscription.deleted',
|
|
'data' => ['object' => ['customer' => 'cus_test_123']],
|
|
]));
|
|
|
|
expect(UserNotificationPreference::where('user_id', $user->id)->where('channel', 'whatsapp')->value('enabled'))->toBeFalse();
|
|
expect(UserNotificationPreference::where('user_id', $user->id)->where('channel', 'sms')->value('enabled'))->toBeFalse();
|
|
expect(UserNotificationPreference::where('user_id', $user->id)->where('channel', 'email')->value('enabled'))->toBeTrue();
|
|
});
|
|
|
|
it('ignores non-deletion webhook events', function (): void {
|
|
$user = User::factory()->create(['stripe_id' => 'cus_test_456']);
|
|
UserNotificationPreference::query()->insert([
|
|
['user_id' => $user->id, 'channel' => 'whatsapp', 'fuel_type' => 'E10', 'enabled' => true, 'created_at' => now(), 'updated_at' => now()],
|
|
]);
|
|
|
|
(new DowngradeUserOnSubscriptionDeleted)->handle(new WebhookReceived([
|
|
'type' => 'customer.subscription.updated',
|
|
'data' => ['object' => ['customer' => 'cus_test_456']],
|
|
]));
|
|
|
|
expect(UserNotificationPreference::where('user_id', $user->id)->where('channel', 'whatsapp')->value('enabled'))->toBeTrue();
|
|
});
|