PlansLocatorTests.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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('getPlanTypeAndPeriodFromRecurlyPlanCode', function () {
  104. it('should return the plan type and period for "collaborator"', function () {
  105. const { planType, period } =
  106. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  107. 'collaborator'
  108. )
  109. expect(planType).to.equal('standard')
  110. expect(period).to.equal('monthly')
  111. })
  112. it('should return the plan type and period for "collaborator_free_trial_7_days"', function () {
  113. const { planType, period } =
  114. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  115. 'collaborator_free_trial_7_days'
  116. )
  117. expect(planType).to.equal('standard')
  118. expect(period).to.equal('monthly')
  119. })
  120. it('should return the plan type and period for "collaborator-annual"', function () {
  121. const { planType, period } =
  122. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  123. 'collaborator-annual'
  124. )
  125. expect(planType).to.equal('standard')
  126. expect(period).to.equal('annual')
  127. })
  128. it('should return the plan type and period for "professional"', function () {
  129. const { planType, period } =
  130. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  131. 'professional'
  132. )
  133. expect(planType).to.equal('professional')
  134. expect(period).to.equal('monthly')
  135. })
  136. it('should return the plan type and period for "professional_free_trial_7_days"', function () {
  137. const { planType, period } =
  138. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  139. 'professional_free_trial_7_days'
  140. )
  141. expect(planType).to.equal('professional')
  142. expect(period).to.equal('monthly')
  143. })
  144. it('should return the plan type and period for "professional-annual"', function () {
  145. const { planType, period } =
  146. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  147. 'professional-annual'
  148. )
  149. expect(planType).to.equal('professional')
  150. expect(period).to.equal('annual')
  151. })
  152. it('should return the plan type and period for "student"', function () {
  153. const { planType, period } =
  154. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode('student')
  155. expect(planType).to.equal('student')
  156. expect(period).to.equal('monthly')
  157. })
  158. it('should return the plan type and period for "student_free_trial_7_days"', function () {
  159. const { planType, period } =
  160. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  161. 'student_free_trial_7_days'
  162. )
  163. expect(planType).to.equal('student')
  164. expect(period).to.equal('monthly')
  165. })
  166. it('should return the plan type and period for "student-annual"', function () {
  167. const { planType, period } =
  168. this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
  169. 'student-annual'
  170. )
  171. expect(planType).to.equal('student')
  172. expect(period).to.equal('annual')
  173. })
  174. })
  175. })