group-plan-pricing.test.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { expect } from 'chai'
  2. import { createLocalizedGroupPlanPrice } from '../../../../frontend/js/features/plans/utils/group-plan-pricing'
  3. import { formatCurrencyLocalized } from '@/shared/utils/currency'
  4. describe('group-plan-pricing', function () {
  5. beforeEach(function () {
  6. window.metaAttributesCache.set('ol-groupPlans', {
  7. enterprise: {
  8. professional: {
  9. CHF: {
  10. 2: {
  11. price_in_cents: 10000,
  12. },
  13. },
  14. DKK: {
  15. 2: {
  16. price_in_cents: 20000,
  17. },
  18. },
  19. USD: {
  20. 2: {
  21. price_in_cents: 30000,
  22. },
  23. },
  24. },
  25. },
  26. })
  27. window.metaAttributesCache.set('ol-currencySymbols', {
  28. CHF: 'Fr',
  29. DKK: 'kr',
  30. USD: '$',
  31. })
  32. window.metaAttributesCache.set('ol-i18n', { currentLangCode: 'en' })
  33. })
  34. describe('createLocalizedGroupPlanPrice', function () {
  35. describe('CHF currency', function () {
  36. it('should return the correct localized price', function () {
  37. const localizedGroupPlanPrice = createLocalizedGroupPlanPrice({
  38. plan: 'professional',
  39. currency: 'CHF',
  40. licenseSize: '2',
  41. usage: 'enterprise',
  42. formatCurrency: formatCurrencyLocalized,
  43. })
  44. expect(localizedGroupPlanPrice).to.deep.equal({
  45. localizedPrice: 'CHF 100',
  46. localizedPerUserPrice: 'CHF 50',
  47. })
  48. })
  49. })
  50. describe('DKK currency', function () {
  51. it('should return the correct localized price', function () {
  52. const localizedGroupPlanPrice = createLocalizedGroupPlanPrice({
  53. plan: 'professional',
  54. currency: 'DKK',
  55. licenseSize: '2',
  56. usage: 'enterprise',
  57. formatCurrency: formatCurrencyLocalized,
  58. })
  59. expect(localizedGroupPlanPrice).to.deep.equal({
  60. localizedPrice: 'kr 200',
  61. localizedPerUserPrice: 'kr 100',
  62. })
  63. })
  64. })
  65. describe('other supported currencies', function () {
  66. it('should return the correct localized price', function () {
  67. const localizedGroupPlanPrice = createLocalizedGroupPlanPrice({
  68. plan: 'professional',
  69. currency: 'USD',
  70. licenseSize: '2',
  71. usage: 'enterprise',
  72. formatCurrency: formatCurrencyLocalized,
  73. })
  74. expect(localizedGroupPlanPrice).to.deep.equal({
  75. localizedPrice: '$300',
  76. localizedPerUserPrice: '$150',
  77. })
  78. })
  79. })
  80. })
  81. })