Files
carmanagement/apps/api/src/modules/subscriptions/subscription.payment-config.test.ts
T
root c9915a8315
Build & Push / Pipeline Tests (push) Successful in 1m28s
Test / Type Check (all packages) (push) Successful in 32s
Build & Push / Build & Push Docker Image (push) Failing after 1m23s
Test / API Unit Tests (push) Successful in 50s
Test / Homepage Unit Tests (push) Successful in 27s
Test / Carplace Unit Tests (push) Successful in 24s
Test / Admin Unit Tests (push) Successful in 24s
Test / Dashboard Unit Tests (push) Successful in 25s
Test / API Integration Tests (push) Successful in 49s
remove stripe
2026-08-16 22:36:05 -04:00

72 lines
2.2 KiB
TypeScript

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<string, string | undefined>()
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([])
})
})