SubscriptionHelperTests.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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: 1500,
  9. },
  10. cheaper: {
  11. planCode: 'cheaper',
  12. price: 500,
  13. },
  14. alsoCheap: {
  15. plancode: 'also-cheap',
  16. price: 500,
  17. },
  18. expensiveGroup: {
  19. plancode: 'group_expensive',
  20. price: 495,
  21. groupPlan: true,
  22. },
  23. cheapGroup: {
  24. plancode: 'group_cheap',
  25. price: 10,
  26. groupPlan: true,
  27. },
  28. bad: {},
  29. }
  30. describe('SubscriptionHelper', function () {
  31. beforeEach(function () {
  32. this.SubscriptionHelper = SandboxedModule.require(modulePath)
  33. })
  34. describe('shouldPlanChangeAtTermEnd', function () {
  35. it('should return true if the new plan is less expensive', function () {
  36. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  37. plans.expensive,
  38. plans.cheaper
  39. )
  40. expect(changeAtTermEnd).to.be.true
  41. })
  42. it('should return false if the new plan is more exepensive', function () {
  43. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  44. plans.cheaper,
  45. plans.expensive
  46. )
  47. expect(changeAtTermEnd).to.be.false
  48. })
  49. it('should return false if the new plan is the same price', function () {
  50. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  51. plans.cheaper,
  52. plans.alsoCheap
  53. )
  54. expect(changeAtTermEnd).to.be.false
  55. })
  56. it('should return false if the change is from an individual plan to a more expensive group plan', function () {
  57. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  58. plans.expensive,
  59. plans.expensiveGroup
  60. )
  61. expect(changeAtTermEnd).to.be.false
  62. })
  63. it('should return true if the change is from an individual plan to a cheaper group plan', function () {
  64. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  65. plans.expensive,
  66. plans.cheapGroup
  67. )
  68. expect(changeAtTermEnd).to.be.true
  69. })
  70. })
  71. })