5f06256271
Build & Push / Pipeline Tests (push) Failing after 1m58s
Build & Push / Build & Push Docker Image (push) Has been skipped
Test / Type Check (all packages) (push) Successful in 58s
Test / API Unit Tests (push) Successful in 1m9s
Test / Homepage Unit Tests (push) Successful in 46s
Test / Carplace Unit Tests (push) Successful in 43s
Test / Admin Unit Tests (push) Successful in 41s
Test / Dashboard Unit Tests (push) Successful in 45s
Test / API Integration Tests (push) Failing after 1m9s
40 lines
2.2 KiB
TypeScript
40 lines
2.2 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
communicationSettingsSchema,
|
|
createManualPaymentSubmissionSchema,
|
|
manualCheckoutSchema,
|
|
} from './subscription.schemas'
|
|
import { addBillingPeriod, normalizeExternalReference } from './subscription.manual.service'
|
|
|
|
describe('manual subscription payment contracts', () => {
|
|
it('accepts only bank transfer and check manual checkout', () => {
|
|
const base = { plan: 'GROWTH', billingPeriod: 'ANNUAL', currency: 'MAD', idempotencyKey: crypto.randomUUID() }
|
|
expect(manualCheckoutSchema.safeParse({ ...base, method: 'BANK_TRANSFER' }).success).toBe(true)
|
|
expect(manualCheckoutSchema.safeParse({ ...base, method: 'STRIPE' }).success).toBe(false)
|
|
})
|
|
|
|
it('normalizes references without discarding the display value', () => {
|
|
const submittedReference = ' bank txn-123 '
|
|
const parsed = createManualPaymentSubmissionSchema.parse({ method: 'BANK_TRANSFER', submittedReference, idempotencyKey: crypto.randomUUID() })
|
|
expect(parsed.submittedReference).toBe('bank txn-123')
|
|
expect(normalizeExternalReference(parsed.submittedReference)).toBe('BANK TXN-123')
|
|
})
|
|
|
|
it('enforces the company-enabled communication language set', () => {
|
|
const valid = {
|
|
timezone: 'Africa/Casablanca', reminderLocalTime: '09:00',
|
|
enabledCommunicationLocales: ['ar', 'fr'], defaultCommunicationLocale: 'fr',
|
|
contacts: [{ email: 'billing@example.ma', locale: 'ar', isPrimary: true, receivePaymentNotices: true, isActive: true }],
|
|
}
|
|
expect(communicationSettingsSchema.safeParse(valid).success).toBe(true)
|
|
expect(communicationSettingsSchema.safeParse({ ...valid, defaultCommunicationLocale: 'en' }).success).toBe(false)
|
|
expect(communicationSettingsSchema.safeParse({ ...valid, contacts: [{ ...valid.contacts[0], locale: 'en' }] }).success).toBe(false)
|
|
expect(communicationSettingsSchema.safeParse({ ...valid, enabledCommunicationLocales: [] }).success).toBe(false)
|
|
})
|
|
|
|
it('clamps month-end and leap-year billing periods', () => {
|
|
expect(addBillingPeriod(new Date('2028-01-31T12:00:00.000Z'), 'MONTHLY').toISOString()).toBe('2028-02-29T12:00:00.000Z')
|
|
expect(addBillingPeriod(new Date('2028-02-29T12:00:00.000Z'), 'ANNUAL').toISOString()).toBe('2029-02-28T12:00:00.000Z')
|
|
})
|
|
})
|