recurly-pricing.test.ts 1.1 KB

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