2023-02-07 10:38:20 -05:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import { formatPriceForDisplayData } from '../../../../../frontend/js/features/subscription/util/recurly-pricing'
|
2024-04-18 04:13:51 -04:00
|
|
|
import { formatCurrencyLocalized } from '@/shared/utils/currency'
|
2023-02-07 10:38:20 -05:00
|
|
|
|
|
|
|
describe('formatPriceForDisplayData', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
window.metaAttributesCache = new Map()
|
|
|
|
})
|
|
|
|
afterEach(function () {
|
|
|
|
window.metaAttributesCache = new Map()
|
|
|
|
})
|
|
|
|
it('should handle no tax rate', function () {
|
2024-04-18 04:13:51 -04:00
|
|
|
const data = formatPriceForDisplayData(
|
|
|
|
'1000',
|
|
|
|
0,
|
|
|
|
'USD',
|
|
|
|
'en',
|
|
|
|
formatCurrencyLocalized
|
|
|
|
)
|
2023-02-07 10:38:20 -05:00
|
|
|
expect(data).to.deep.equal({
|
2024-04-18 04:13:51 -04:00
|
|
|
totalForDisplay: '$1,000',
|
2023-02-07 10:38:20 -05:00
|
|
|
totalAsNumber: 1000,
|
2024-04-18 04:13:51 -04:00
|
|
|
subtotal: '$1,000.00',
|
2023-02-07 10:38:20 -05:00
|
|
|
tax: '$0.00',
|
|
|
|
includesTax: false,
|
|
|
|
})
|
|
|
|
window.metaAttributesCache = new Map()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should handle a tax rate', function () {
|
2024-04-18 04:13:51 -04:00
|
|
|
const data = formatPriceForDisplayData(
|
|
|
|
'380',
|
|
|
|
0.2,
|
|
|
|
'EUR',
|
|
|
|
'en',
|
|
|
|
formatCurrencyLocalized
|
|
|
|
)
|
2023-02-07 10:38:20 -05:00
|
|
|
expect(data).to.deep.equal({
|
|
|
|
totalForDisplay: '€456',
|
|
|
|
totalAsNumber: 456,
|
|
|
|
subtotal: '€380.00',
|
|
|
|
tax: '€76.00',
|
|
|
|
includesTax: true,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should handle total with cents', function () {
|
2024-04-18 04:13:51 -04:00
|
|
|
const data = formatPriceForDisplayData(
|
|
|
|
'8',
|
|
|
|
0.2,
|
|
|
|
'EUR',
|
|
|
|
'en',
|
|
|
|
formatCurrencyLocalized
|
|
|
|
)
|
2023-02-07 10:38:20 -05:00
|
|
|
expect(data).to.deep.equal({
|
|
|
|
totalForDisplay: '€9.60',
|
|
|
|
totalAsNumber: 9.6,
|
|
|
|
subtotal: '€8.00',
|
|
|
|
tax: '€1.60',
|
|
|
|
includesTax: true,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|