SubscriptionHelperTests.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. const SandboxedModule = require('sandboxed-module')
  2. const { expect } = require('chai')
  3. const modulePath =
  4. '../../../../app/src/Features/Subscription/SubscriptionHelper'
  5. const plans = {
  6. expensive: {
  7. planCode: 'expensive',
  8. price_in_cents: 1500,
  9. },
  10. cheaper: {
  11. planCode: 'cheaper',
  12. price_in_cents: 500,
  13. },
  14. alsoCheap: {
  15. plancode: 'also-cheap',
  16. price_in_cents: 500,
  17. },
  18. expensiveGroup: {
  19. plancode: 'group_expensive',
  20. price_in_cents: 49500,
  21. groupPlan: true,
  22. },
  23. cheapGroup: {
  24. plancode: 'group_cheap',
  25. price_in_cents: 1000,
  26. groupPlan: true,
  27. },
  28. bad: {},
  29. }
  30. describe('SubscriptionHelper', function () {
  31. beforeEach(function () {
  32. this.INITIAL_LICENSE_SIZE = 2
  33. this.settings = {
  34. groupPlanModalOptions: {
  35. currencySymbols: {
  36. USD: '$',
  37. CHF: 'Fr',
  38. DKK: 'kr',
  39. NOK: 'kr',
  40. SEK: 'kr',
  41. },
  42. },
  43. }
  44. this.GroupPlansData = {
  45. enterprise: {
  46. collaborator: {
  47. CHF: {
  48. [this.INITIAL_LICENSE_SIZE]: {
  49. price_in_cents: 1000,
  50. },
  51. },
  52. DKK: {
  53. [this.INITIAL_LICENSE_SIZE]: {
  54. price_in_cents: 2000,
  55. },
  56. },
  57. SEK: {
  58. [this.INITIAL_LICENSE_SIZE]: {
  59. price_in_cents: 3000,
  60. },
  61. },
  62. NOK: {
  63. [this.INITIAL_LICENSE_SIZE]: {
  64. price_in_cents: 4000,
  65. },
  66. },
  67. USD: {
  68. [this.INITIAL_LICENSE_SIZE]: {
  69. price_in_cents: 5000,
  70. },
  71. },
  72. },
  73. professional: {
  74. CHF: {
  75. [this.INITIAL_LICENSE_SIZE]: {
  76. price_in_cents: 10000,
  77. },
  78. },
  79. DKK: {
  80. [this.INITIAL_LICENSE_SIZE]: {
  81. price_in_cents: 20000,
  82. },
  83. },
  84. SEK: {
  85. [this.INITIAL_LICENSE_SIZE]: {
  86. price_in_cents: 30000,
  87. },
  88. },
  89. NOK: {
  90. [this.INITIAL_LICENSE_SIZE]: {
  91. price_in_cents: 40000,
  92. },
  93. },
  94. USD: {
  95. [this.INITIAL_LICENSE_SIZE]: {
  96. price_in_cents: 50000,
  97. },
  98. },
  99. },
  100. },
  101. }
  102. this.SubscriptionHelper = SandboxedModule.require(modulePath, {
  103. requires: {
  104. '@overleaf/settings': this.settings,
  105. './GroupPlansData': this.GroupPlansData,
  106. },
  107. })
  108. })
  109. describe('shouldPlanChangeAtTermEnd', function () {
  110. it('should return true if the new plan is less expensive', function () {
  111. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  112. plans.expensive,
  113. plans.cheaper
  114. )
  115. expect(changeAtTermEnd).to.be.true
  116. })
  117. it('should return false if the new plan is more exepensive', function () {
  118. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  119. plans.cheaper,
  120. plans.expensive
  121. )
  122. expect(changeAtTermEnd).to.be.false
  123. })
  124. it('should return false if the new plan is the same price', function () {
  125. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  126. plans.cheaper,
  127. plans.alsoCheap
  128. )
  129. expect(changeAtTermEnd).to.be.false
  130. })
  131. it('should return false if the change is from an individual plan to a more expensive group plan', function () {
  132. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  133. plans.expensive,
  134. plans.expensiveGroup
  135. )
  136. expect(changeAtTermEnd).to.be.false
  137. })
  138. it('should return true if the change is from an individual plan to a cheaper group plan', function () {
  139. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  140. plans.expensive,
  141. plans.cheapGroup
  142. )
  143. expect(changeAtTermEnd).to.be.true
  144. })
  145. })
  146. describe('generateInitialLocalizedGroupPrice', function () {
  147. describe('CHF currency', function () {
  148. it('should return the correct localized price for every plan', function () {
  149. const localizedPrice =
  150. this.SubscriptionHelper.generateInitialLocalizedGroupPrice('CHF')
  151. expect(localizedPrice).to.deep.equal({
  152. price: {
  153. collaborator: 'Fr 10',
  154. professional: 'Fr 100',
  155. },
  156. pricePerUser: {
  157. collaborator: 'Fr 5',
  158. professional: 'Fr 50',
  159. },
  160. })
  161. })
  162. })
  163. describe('DKK currency', function () {
  164. it('should return the correct localized price for every plan', function () {
  165. const localizedPrice =
  166. this.SubscriptionHelper.generateInitialLocalizedGroupPrice('DKK')
  167. expect(localizedPrice).to.deep.equal({
  168. price: {
  169. collaborator: '20 kr',
  170. professional: '200 kr',
  171. },
  172. pricePerUser: {
  173. collaborator: '10 kr',
  174. professional: '100 kr',
  175. },
  176. })
  177. })
  178. })
  179. describe('SEK currency', function () {
  180. it('should return the correct localized price for every plan', function () {
  181. const localizedPrice =
  182. this.SubscriptionHelper.generateInitialLocalizedGroupPrice('SEK')
  183. expect(localizedPrice).to.deep.equal({
  184. price: {
  185. collaborator: '30 kr',
  186. professional: '300 kr',
  187. },
  188. pricePerUser: {
  189. collaborator: '15 kr',
  190. professional: '150 kr',
  191. },
  192. })
  193. })
  194. })
  195. describe('NOK currency', function () {
  196. it('should return the correct localized price for every plan', function () {
  197. const localizedPrice =
  198. this.SubscriptionHelper.generateInitialLocalizedGroupPrice('NOK')
  199. expect(localizedPrice).to.deep.equal({
  200. price: {
  201. collaborator: '40 kr',
  202. professional: '400 kr',
  203. },
  204. pricePerUser: {
  205. collaborator: '20 kr',
  206. professional: '200 kr',
  207. },
  208. })
  209. })
  210. })
  211. describe('other supported currencies', function () {
  212. it('should return the correct localized price for every plan', function () {
  213. const localizedPrice =
  214. this.SubscriptionHelper.generateInitialLocalizedGroupPrice('USD')
  215. expect(localizedPrice).to.deep.equal({
  216. price: {
  217. collaborator: '$50',
  218. professional: '$500',
  219. },
  220. pricePerUser: {
  221. collaborator: '$25',
  222. professional: '$250',
  223. },
  224. })
  225. })
  226. })
  227. })
  228. })