recurly-pricing.test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. it('should handle no tax rate', function () {
  6. const data = formatPriceForDisplayData(
  7. '1000',
  8. 0,
  9. 'USD',
  10. 'en',
  11. formatCurrencyLocalized
  12. )
  13. expect(data).to.deep.equal({
  14. totalForDisplay: '$1,000',
  15. totalAsNumber: 1000,
  16. subtotal: '$1,000.00',
  17. tax: '$0.00',
  18. includesTax: false,
  19. })
  20. })
  21. it('should handle a tax rate', function () {
  22. const data = formatPriceForDisplayData(
  23. '380',
  24. 0.2,
  25. 'EUR',
  26. 'en',
  27. formatCurrencyLocalized
  28. )
  29. expect(data).to.deep.equal({
  30. totalForDisplay: '€456',
  31. totalAsNumber: 456,
  32. subtotal: '€380.00',
  33. tax: '€76.00',
  34. includesTax: true,
  35. })
  36. })
  37. it('should handle total with cents', function () {
  38. const data = formatPriceForDisplayData(
  39. '8',
  40. 0.2,
  41. 'EUR',
  42. 'en',
  43. formatCurrencyLocalized
  44. )
  45. expect(data).to.deep.equal({
  46. totalForDisplay: '€9.60',
  47. totalAsNumber: 9.6,
  48. subtotal: '€8.00',
  49. tax: '€1.60',
  50. includesTax: true,
  51. })
  52. })
  53. })