PlansLocatorTests.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. const SandboxedModule = require('sandboxed-module')
  2. const { expect } = require('chai')
  3. const modulePath = '../../../../app/src/Features/Subscription/PlansLocator'
  4. const plans = [
  5. {
  6. planCode: 'first',
  7. name: '1st',
  8. price_in_cents: 800,
  9. features: {},
  10. featureDescription: {},
  11. },
  12. {
  13. planCode: 'second',
  14. name: '2nd',
  15. price_in_cents: 1500,
  16. features: {},
  17. featureDescription: {},
  18. },
  19. {
  20. planCode: 'third',
  21. name: '3rd',
  22. price_in_cents: 3000,
  23. features: {},
  24. featureDescription: {},
  25. },
  26. ]
  27. describe('PlansLocator', function () {
  28. beforeEach(function () {
  29. this.settings = { plans }
  30. this.PlansLocator = SandboxedModule.require(modulePath, {
  31. requires: {
  32. '@overleaf/settings': this.settings,
  33. },
  34. })
  35. })
  36. describe('findLocalPlanInSettings', function () {
  37. it('should return the found plan', function () {
  38. const plan = this.PlansLocator.findLocalPlanInSettings('second')
  39. expect(plan).to.have.property('name', '2nd')
  40. expect(plan).to.have.property('price_in_cents', 1500)
  41. })
  42. it('should return null if no matching plan is found', function () {
  43. const plan = this.PlansLocator.findLocalPlanInSettings('gibberish')
  44. expect(plan).to.be.a('null')
  45. })
  46. })
  47. describe('mapRecurlyPlanCodeToStripeLookupKey', function () {
  48. it('should map "collaborator" plan code to stripe lookup keys', function () {
  49. const planCode = 'collaborator'
  50. const lookupKey =
  51. this.PlansLocator.mapRecurlyPlanCodeToStripeLookupKey(planCode)
  52. expect(lookupKey).to.equal('standard_monthly')
  53. })
  54. it('should map "collaborator_free_trial_7_days" plan code to stripe lookup keys', function () {
  55. const planCode = 'collaborator_free_trial_7_days'
  56. const lookupKey =
  57. this.PlansLocator.mapRecurlyPlanCodeToStripeLookupKey(planCode)
  58. expect(lookupKey).to.equal('standard_monthly')
  59. })
  60. it('should map "collaborator-annual" plan code to stripe lookup keys', function () {
  61. const planCode = 'collaborator-annual'
  62. const lookupKey =
  63. this.PlansLocator.mapRecurlyPlanCodeToStripeLookupKey(planCode)
  64. expect(lookupKey).to.equal('standard_annual')
  65. })
  66. it('should map "professional" plan code to stripe lookup keys', function () {
  67. const planCode = 'professional'
  68. const lookupKey =
  69. this.PlansLocator.mapRecurlyPlanCodeToStripeLookupKey(planCode)
  70. expect(lookupKey).to.equal('professional_monthly')
  71. })
  72. it('should map "professional_free_trial_7_days" plan code to stripe lookup keys', function () {
  73. const planCode = 'professional_free_trial_7_days'
  74. const lookupKey =
  75. this.PlansLocator.mapRecurlyPlanCodeToStripeLookupKey(planCode)
  76. expect(lookupKey).to.equal('professional_monthly')
  77. })
  78. it('should map "professional-annual" plan code to stripe lookup keys', function () {
  79. const planCode = 'professional-annual'
  80. const lookupKey =
  81. this.PlansLocator.mapRecurlyPlanCodeToStripeLookupKey(planCode)
  82. expect(lookupKey).to.equal('professional_annual')
  83. })
  84. it('should map "student" plan code to stripe lookup keys', function () {
  85. const planCode = 'student'
  86. const lookupKey =
  87. this.PlansLocator.mapRecurlyPlanCodeToStripeLookupKey(planCode)
  88. expect(lookupKey).to.equal('student_monthly')
  89. })
  90. it('shoult map "student_free_trial_7_days" plan code to stripe lookup keys', function () {
  91. const planCode = 'student_free_trial_7_days'
  92. const lookupKey =
  93. this.PlansLocator.mapRecurlyPlanCodeToStripeLookupKey(planCode)
  94. expect(lookupKey).to.equal('student_monthly')
  95. })
  96. it('should map "student-annual" plan code to stripe lookup keys', function () {
  97. const planCode = 'student-annual'
  98. const lookupKey =
  99. this.PlansLocator.mapRecurlyPlanCodeToStripeLookupKey(planCode)
  100. expect(lookupKey).to.equal('student_annual')
  101. })
  102. })
  103. describe('mapStripeLookupKeyToRecurlyPlanCode', function () {
  104. it('should return the recurly plan code for existing plans', function () {
  105. const planCode = 'standard_monthly'
  106. const lookupKey =
  107. this.PlansLocator.mapStripeLookupKeyToRecurlyPlanCode(planCode)
  108. expect(lookupKey).to.equal('collaborator')
  109. })
  110. it('should return undefined for unknown plans', function () {
  111. const planCode = 'foobar'
  112. const lookupKey =
  113. this.PlansLocator.mapStripeLookupKeyToRecurlyPlanCode(planCode)
  114. expect(lookupKey).to.equal(undefined)
  115. })
  116. })
  117. describe('getPlanTypeAndPeriodFromRecurlyPlanCode', function () {
  118. it('should return the plan type and period for "collaborator"', function () {
  119. const { planType, period } =
  120. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  121. 'collaborator'
  122. )
  123. expect(planType).to.equal('standard')
  124. expect(period).to.equal('monthly')
  125. })
  126. it('should return the plan type and period for "collaborator_free_trial_7_days"', function () {
  127. const { planType, period } =
  128. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  129. 'collaborator_free_trial_7_days'
  130. )
  131. expect(planType).to.equal('standard')
  132. expect(period).to.equal('monthly')
  133. })
  134. it('should return the plan type and period for "collaborator-annual"', function () {
  135. const { planType, period } =
  136. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  137. 'collaborator-annual'
  138. )
  139. expect(planType).to.equal('standard')
  140. expect(period).to.equal('annual')
  141. })
  142. it('should return the plan type and period for "professional"', function () {
  143. const { planType, period } =
  144. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  145. 'professional'
  146. )
  147. expect(planType).to.equal('professional')
  148. expect(period).to.equal('monthly')
  149. })
  150. it('should return the plan type and period for "professional_free_trial_7_days"', function () {
  151. const { planType, period } =
  152. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  153. 'professional_free_trial_7_days'
  154. )
  155. expect(planType).to.equal('professional')
  156. expect(period).to.equal('monthly')
  157. })
  158. it('should return the plan type and period for "professional-annual"', function () {
  159. const { planType, period } =
  160. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  161. 'professional-annual'
  162. )
  163. expect(planType).to.equal('professional')
  164. expect(period).to.equal('annual')
  165. })
  166. it('should return the plan type and period for "student"', function () {
  167. const { planType, period } =
  168. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode('student')
  169. expect(planType).to.equal('student')
  170. expect(period).to.equal('monthly')
  171. })
  172. it('should return the plan type and period for "student_free_trial_7_days"', function () {
  173. const { planType, period } =
  174. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  175. 'student_free_trial_7_days'
  176. )
  177. expect(planType).to.equal('student')
  178. expect(period).to.equal('monthly')
  179. })
  180. it('should return the plan type and period for "student-annual"', function () {
  181. const { planType, period } =
  182. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  183. 'student-annual'
  184. )
  185. expect(planType).to.equal('student')
  186. expect(period).to.equal('annual')
  187. })
  188. })
  189. })