65 lines
2.6 KiB
TypeScript
65 lines
2.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { TR_BILLING } from '@/i18n/tr-billing'
|
|
|
|
import { validateAutoReloadInputs } from './billing-amounts'
|
|
import { resolveRefusal } from './errors'
|
|
import { okBilling, okSubscription, postTrainBillingState, postTrainSubscriptionState } from './fixtures.test-util'
|
|
import { deriveBillingView } from './use-billing-state'
|
|
|
|
describe('Turkish billing contracts', () => {
|
|
it('keeps routes, amount bounds and action policy unchanged across languages', () => {
|
|
for (const kind of [
|
|
'consent_required',
|
|
'insufficient_scope',
|
|
'remote_spending_revoked',
|
|
'session_revoked',
|
|
'cli_billing_disabled',
|
|
'remote_spending_disabled',
|
|
'role_required',
|
|
'idempotency_conflict',
|
|
'no_payment_method',
|
|
'org_access_denied',
|
|
'monthly_cap_exceeded',
|
|
'rate_limited',
|
|
'temporarily_unavailable',
|
|
'stripe_unavailable',
|
|
'upgrade_cap_exceeded',
|
|
'endpoint_unavailable',
|
|
'timeout',
|
|
'transport',
|
|
'unknown'
|
|
]) {
|
|
const refusal = { kind, message: '', portalUrl: 'https://portal.nousresearch.com/billing', retryAfter: 120 }
|
|
const english = resolveRefusal(refusal)
|
|
const turkish = resolveRefusal(refusal, TR_BILLING)
|
|
expect(turkish.action).toEqual(english.action)
|
|
expect(turkish.title).not.toBe(english.title)
|
|
expect(turkish.message).not.toBe(english.message)
|
|
}
|
|
|
|
const bounds = { min_usd: '10', max_usd: '100' }
|
|
expect(validateAutoReloadInputs('15', '20', bounds, TR_BILLING)).toEqual(
|
|
validateAutoReloadInputs('15', '20', bounds)
|
|
)
|
|
expect(validateAutoReloadInputs('20', '15', bounds, TR_BILLING).error).toBe(TR_BILLING.reloadGreater)
|
|
expect(resolveRefusal({ kind: 'transport', message: 'upstream diagnostic' }, TR_BILLING).message).toBe(
|
|
'upstream diagnostic'
|
|
)
|
|
})
|
|
|
|
it('translates the derived overview without altering prices or plan identities', () => {
|
|
const args = [okBilling(postTrainBillingState), okSubscription(postTrainSubscriptionState)] as const
|
|
const english = deriveBillingView(...args)
|
|
const turkish = deriveBillingView(...args, TR_BILLING)
|
|
expect(turkish.summary[0].label).toBe('Bakiye')
|
|
expect(turkish.summary[0].value).toBe(english.summary[0].value)
|
|
expect(turkish.plan?.tierName).toBe(english.plan?.tierName)
|
|
expect(turkish.plan?.price).toBe(english.plan?.price)
|
|
expect(turkish.paymentRow?.action?.url).toBe(english.paymentRow?.action?.url)
|
|
expect(turkish.tiers.map(tier => [tier.tierId, tier.state, tier.priceDisplay])).toEqual(
|
|
english.tiers.map(tier => [tier.tierId, tier.state, tier.priceDisplay])
|
|
)
|
|
})
|
|
})
|