recurly-pricing.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { expect } from 'chai'
  2. import { formatPriceForDisplayData } from '../../../../../frontend/js/features/subscription/util/recurly-pricing'
  3. import { formatCurrencyLocalized } from '@/shared/utils/currency'
  4. describe('formatPriceForDisplayData', function () {
  5. beforeEach(function () {
  6. window.metaAttributesCache = new Map()
  7. })
  8. afterEach(function () {
  9. window.metaAttributesCache = new Map()
  10. })
  11. it('should handle no tax rate', function () {
  12. const data = formatPriceForDisplayData(
  13. '1000',
  14. 0,
  15. 'USD',
  16. 'en',
  17. formatCurrencyLocalized
  18. )
  19. expect(data).to.deep.equal({
  20. totalForDisplay: '$1,000',
  21. totalAsNumber: 1000,
  22. subtotal: '$1,000.00',
  23. tax: '$0.00',
  24. includesTax: false,
  25. })
  26. window.metaAttributesCache = new Map()
  27. })
  28. it('should handle a tax rate', function () {
  29. const data = formatPriceForDisplayData(
  30. '380',
  31. 0.2,
  32. 'EUR',
  33. 'en',
  34. formatCurrencyLocalized
  35. )
  36. expect(data).to.deep.equal({
  37. totalForDisplay: '€456',
  38. totalAsNumber: 456,
  39. subtotal: '€380.00',
  40. tax: '€76.00',
  41. includesTax: true,
  42. })
  43. })
  44. it('should handle total with cents', function () {
  45. const data = formatPriceForDisplayData(
  46. '8',
  47. 0.2,
  48. 'EUR',
  49. 'en',
  50. formatCurrencyLocalized
  51. )
  52. expect(data).to.deep.equal({
  53. totalForDisplay: '€9.60',
  54. totalAsNumber: 9.6,
  55. subtotal: '€8.00',
  56. tax: '€1.60',
  57. includesTax: true,
  58. })
  59. })
  60. })