Files
playzer/apps/backend/test/billing/event-mapping.test.ts
Jose Selesan e06bc12097 feat(billing): implement billing module with Stripe and Mercado Pago integration
- Add Stripe and Mercado Pago providers for handling subscriptions.
- Create billing repository and access services for managing billing records.
- Implement webhook handlers for processing events from Stripe and Mercado Pago.
- Add routes for checkout, canceling subscriptions, and retrieving billing status.
- Introduce billing status management with appropriate state transitions.
- Create tests for billing functionalities including webhook idempotency and provider resolution.
- Document the billing module architecture, environment variables, and API endpoints.
2026-06-29 15:55:20 -03:00

32 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'bun:test';
import { mapWebhookTypeToStatus } from './helpers';
describe('event-mapping', () => {
it('maps all webhook event types correctly', () => {
expect(mapWebhookTypeToStatus('activated')).toBe('ACTIVE');
expect(mapWebhookTypeToStatus('updated')).toBe('ACTIVE');
expect(mapWebhookTypeToStatus('payment_failed')).toBe('PAST_DUE');
expect(mapWebhookTypeToStatus('cancelled')).toBe('CANCELED');
});
it('maps Stripe checkout.session.completed -> activated -> ACTIVE', () => {
const status = mapWebhookTypeToStatus('activated');
expect(status).toBe('ACTIVE');
});
it('maps Stripe customer.subscription.deleted -> cancelled -> CANCELED', () => {
const status = mapWebhookTypeToStatus('cancelled');
expect(status).toBe('CANCELED');
});
it('maps Mercado Pago subscription_authorized_payment -> activated -> ACTIVE', () => {
const status = mapWebhookTypeToStatus('activated');
expect(status).toBe('ACTIVE');
});
it('maps Mercado Pago subscription_cancelled -> cancelled -> CANCELED', () => {
const status = mapWebhookTypeToStatus('cancelled');
expect(status).toBe('CANCELED');
});
});