group-plan-pricing.test.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 = window.metaAttributesCache || new Map()
  7. window.metaAttributesCache.set('ol-groupPlans', {
  8. enterprise: {
  9. professional: {
  10. CHF: {
  11. 2: {
  12. price_in_cents: 10000,
  13. },
  14. },
  15. DKK: {
  16. 2: {
  17. price_in_cents: 20000,
  18. },
  19. },
  20. USD: {
  21. 2: {
  22. price_in_cents: 30000,
  23. },
  24. },
  25. },
  26. },
  27. })
  28. window.metaAttributesCache.set('ol-currencySymbols', {
  29. CHF: 'Fr',
  30. DKK: 'kr',
  31. USD: '$',
  32. })
  33. })
  34. afterEach(function () {
  35. window.metaAttributesCache = new Map()
  36. })
  37. describe('createLocalizedGroupPlanPrice', function () {
  38. describe('CHF currency', function () {
  39. it('should return the correct localized price', function () {
  40. const localizedGroupPlanPrice = createLocalizedGroupPlanPrice({
  41. plan: 'professional',
  42. currency: 'CHF',
  43. licenseSize: '2',
  44. usage: 'enterprise',
  45. formatCurrency: formatCurrencyLocalized,
  46. })
  47. expect(localizedGroupPlanPrice).to.deep.equal({
  48. localizedPrice: 'CHF 100',
  49. localizedPerUserPrice: 'CHF 50',
  50. })
  51. })
  52. })
  53. describe('DKK currency', function () {
  54. it('should return the correct localized price', function () {
  55. const localizedGroupPlanPrice = createLocalizedGroupPlanPrice({
  56. plan: 'professional',
  57. currency: 'DKK',
  58. licenseSize: '2',
  59. usage: 'enterprise',
  60. formatCurrency: formatCurrencyLocalized,
  61. })
  62. expect(localizedGroupPlanPrice).to.deep.equal({
  63. localizedPrice: 'kr 200',
  64. localizedPerUserPrice: 'kr 100',
  65. })
  66. })
  67. })
  68. describe('other supported currencies', function () {
  69. it('should return the correct localized price', function () {
  70. const localizedGroupPlanPrice = createLocalizedGroupPlanPrice({
  71. plan: 'professional',
  72. currency: 'USD',
  73. licenseSize: '2',
  74. usage: 'enterprise',
  75. formatCurrency: formatCurrencyLocalized,
  76. })
  77. expect(localizedGroupPlanPrice).to.deep.equal({
  78. localizedPrice: '$300',
  79. localizedPerUserPrice: '$150',
  80. })
  81. })
  82. })
  83. })
  84. })