recurly-pricing.test.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { expect } from 'chai'
  2. import { formatPriceForDisplayData } from '../../../../../frontend/js/features/subscription/util/recurly-pricing'
  3. describe('formatPriceForDisplayData', function () {
  4. beforeEach(function () {
  5. window.metaAttributesCache = new Map()
  6. })
  7. afterEach(function () {
  8. window.metaAttributesCache = new Map()
  9. })
  10. it('should handle no tax rate', function () {
  11. const data = formatPriceForDisplayData('1000', 0, 'USD')
  12. expect(data).to.deep.equal({
  13. totalForDisplay: '$1000',
  14. totalAsNumber: 1000,
  15. subtotal: '$1000.00',
  16. tax: '$0.00',
  17. includesTax: false,
  18. })
  19. window.metaAttributesCache = new Map()
  20. })
  21. it('should handle a tax rate', function () {
  22. const data = formatPriceForDisplayData('380', 0.2, 'EUR')
  23. expect(data).to.deep.equal({
  24. totalForDisplay: '€456',
  25. totalAsNumber: 456,
  26. subtotal: '€380.00',
  27. tax: '€76.00',
  28. includesTax: true,
  29. })
  30. })
  31. it('should handle total with cents', function () {
  32. const data = formatPriceForDisplayData('8', 0.2, 'EUR')
  33. expect(data).to.deep.equal({
  34. totalForDisplay: '€9.60',
  35. totalAsNumber: 9.6,
  36. subtotal: '€8.00',
  37. tax: '€1.60',
  38. includesTax: true,
  39. })
  40. })
  41. })