import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { getPaymentOptions } from './subscription.payment-config' const ENV_KEYS = [ 'MANUAL_SUBSCRIPTION_PAYMENTS_ENABLED', 'MANUAL_PAYMENT_EVIDENCE_UPLOAD_ENABLED', 'PAYMENT_EVIDENCE_SCANNER_MODE', 'PAYMENT_EVIDENCE_SCANNER_PATH', 'BANK_TRANSFER_ENABLED', 'BANK_TRANSFER_ACCOUNT_NAME', 'BANK_TRANSFER_BANK_NAME', 'BANK_TRANSFER_ACCOUNT_REFERENCE', 'CHECK_PAYMENT_ENABLED', 'CHECK_PAYMENT_PAYEE', 'CHECK_PAYMENT_DELIVERY_ADDRESS', 'NODE_ENV', ] as const describe('subscription payment configuration', () => { const originalEnv = new Map() beforeEach(() => { for (const key of ENV_KEYS) originalEnv.set(key, process.env[key]) }) afterEach(() => { for (const key of ENV_KEYS) { const value = originalEnv.get(key) if (value === undefined) delete process.env[key] else process.env[key] = value } originalEnv.clear() vi.clearAllMocks() }) it('exposes local manual payment methods when evidence scanning is ready', () => { process.env.NODE_ENV = 'development' expect(getPaymentOptions('en').methods).toEqual([ { method: 'BANK_TRANSFER', enabled: true, instructions: { accountName: 'RentalDriveGo SARL', bankName: 'Local Development Bank', accountReference: 'DEV-MA64-0000-0000-0000', message: 'Enter the bank transfer reference and upload the transfer receipt.', }, }, { method: 'CHECK', enabled: true, instructions: { payee: 'RentalDriveGo SARL', deliveryAddress: 'Local development billing desk', message: 'Enter the check number and upload a check copy.', }, }, ]) }) it('hides manual methods in production when the evidence pipeline is not ready', () => { process.env.NODE_ENV = 'production' process.env.MANUAL_SUBSCRIPTION_PAYMENTS_ENABLED = 'true' process.env.MANUAL_PAYMENT_EVIDENCE_UPLOAD_ENABLED = 'true' process.env.BANK_TRANSFER_ENABLED = 'true' process.env.CHECK_PAYMENT_ENABLED = 'true' expect(getPaymentOptions('en').methods).toEqual([]) }) })