import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { resolvePriceId, priceIdToTier } from '@/lib/billing/stripe-prices'; describe('billing-price-map', () => { const originalEnv = process.env; beforeEach(() => { process.env = { ...originalEnv, STRIPE_PRICE_PRO_MONTHLY: 'price_pro_monthly_test', STRIPE_PRICE_PRO_ANNUAL: 'price_pro_annual_test', STRIPE_PRICE_BUSINESS_MONTHLY: 'price_business_monthly_test', STRIPE_PRICE_BUSINESS_ANNUAL: 'price_business_annual_test', }; }); afterEach(() => { process.env = originalEnv; }); describe('resolvePriceId', () => { it('returns PRO monthly price ID', () => { expect(resolvePriceId('PRO', 'month')).toBe('price_pro_monthly_test'); }); it('returns PRO annual price ID', () => { expect(resolvePriceId('PRO', 'year')).toBe('price_pro_annual_test'); }); it('returns BUSINESS monthly price ID', () => { expect(resolvePriceId('BUSINESS', 'month')).toBe('price_business_monthly_test'); }); it('returns BUSINESS annual price ID', () => { expect(resolvePriceId('BUSINESS', 'year')).toBe('price_business_annual_test'); }); it('throws if env variable is not set', () => { delete process.env.STRIPE_PRICE_PRO_MONTHLY; expect(() => resolvePriceId('PRO', 'month')).toThrow(); }); }); describe('priceIdToTier', () => { it('resolves PRO monthly price ID to PRO tier', () => { expect(priceIdToTier('price_pro_monthly_test')).toBe('PRO'); }); it('resolves PRO annual price ID to PRO tier', () => { expect(priceIdToTier('price_pro_annual_test')).toBe('PRO'); }); it('resolves BUSINESS monthly price ID to BUSINESS tier', () => { expect(priceIdToTier('price_business_monthly_test')).toBe('BUSINESS'); }); it('resolves BUSINESS annual price ID to BUSINESS tier', () => { expect(priceIdToTier('price_business_annual_test')).toBe('BUSINESS'); }); it('returns null for unknown price ID', () => { expect(priceIdToTier('price_unknown_xyz')).toBeNull(); }); it('returns null when env variables are not set', () => { delete process.env.STRIPE_PRICE_PRO_MONTHLY; delete process.env.STRIPE_PRICE_PRO_ANNUAL; delete process.env.STRIPE_PRICE_BUSINESS_MONTHLY; delete process.env.STRIPE_PRICE_BUSINESS_ANNUAL; expect(priceIdToTier('price_pro_monthly_test')).toBeNull(); }); }); });