Spaces:
Paused
Paused
Download apps/prevision-api/src/webhooks/webhooks.service.spec.ts from modventures/prevision: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/modventures/prevision/resolve/main/apps/prevision-api/src/webhooks/webhooks.service.spec.ts
- Command line
-
hf download hf://spaces/modventures/prevision/apps/prevision-api/src/webhooks/webhooks.service.spec.ts
-
curl -L -o webhooks.service.spec.ts https://huggingface.co/spaces/modventures/prevision/resolve/main/apps/prevision-api/src/webhooks/webhooks.service.spec.ts
1.37 kB
| import type Stripe from 'stripe'; | |
| import type { SubscriptionsService } from '../subscriptions/subscriptions.service.js'; | |
| import { WebhooksService } from './webhooks.service.js'; | |
| const event = (type: string, object: object) => ({ type, data: { object } }) as unknown as Stripe.Event; | |
| describe('WebhooksService', () => { | |
| const subscriptions = { syncFromStripe: vi.fn() }; | |
| const service = new WebhooksService(subscriptions as unknown as SubscriptionsService); | |
| beforeEach(() => vi.clearAllMocks()); | |
| it.each(['customer.subscription.created', 'customer.subscription.updated', 'customer.subscription.deleted'])( | |
| 'syncs the subscription on %s', | |
| async (type) => { | |
| await service.handle(event(type, { id: 'sub_1' })); | |
| expect(subscriptions.syncFromStripe).toHaveBeenCalledWith('sub_1'); | |
| }, | |
| ); | |
| it('syncs the subscription a completed checkout created', async () => { | |
| await service.handle(event('checkout.session.completed', { subscription: 'sub_2' })); | |
| expect(subscriptions.syncFromStripe).toHaveBeenCalledWith('sub_2'); | |
| }); | |
| it('ignores other events and checkouts without a subscription', async () => { | |
| await service.handle(event('invoice.paid', { id: 'in_1' })); | |
| await service.handle(event('checkout.session.completed', { subscription: null })); | |
| expect(subscriptions.syncFromStripe).not.toHaveBeenCalled(); | |
| }); | |
| }); | |