43 lines
1.5 KiB
PHP
43 lines
1.5 KiB
PHP
<?php
|
|
|
|
use App\Listeners\HandleStripeWebhook;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Laravel\Cashier\Events\WebhookReceived;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('busts the plan cache on customer.subscription.created', function (): void {
|
|
$user = User::factory()->create(['stripe_id' => 'cus_created_1']);
|
|
Cache::tags(['plans'])->put("plan_for_user_{$user->id}", 'stale', 3600);
|
|
|
|
(new HandleStripeWebhook)->handle(new WebhookReceived([
|
|
'type' => 'customer.subscription.created',
|
|
'data' => ['object' => ['customer' => 'cus_created_1']],
|
|
]));
|
|
|
|
expect(Cache::tags(['plans'])->get("plan_for_user_{$user->id}"))->toBeNull();
|
|
});
|
|
|
|
it('ignores subscription.created when the user is not found', function (): void {
|
|
(new HandleStripeWebhook)->handle(new WebhookReceived([
|
|
'type' => 'customer.subscription.created',
|
|
'data' => ['object' => ['customer' => 'cus_unknown']],
|
|
]));
|
|
|
|
expect(true)->toBeTrue();
|
|
});
|
|
|
|
it('busts the plan cache on customer.subscription.updated', function (): void {
|
|
$user = User::factory()->create(['stripe_id' => 'cus_updated_1']);
|
|
Cache::tags(['plans'])->put("plan_for_user_{$user->id}", 'stale', 3600);
|
|
|
|
(new HandleStripeWebhook)->handle(new WebhookReceived([
|
|
'type' => 'customer.subscription.updated',
|
|
'data' => ['object' => ['customer' => 'cus_updated_1']],
|
|
]));
|
|
|
|
expect(Cache::tags(['plans'])->get("plan_for_user_{$user->id}"))->toBeNull();
|
|
});
|