SubscriptionHelperTests.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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: 15,
  9. },
  10. cheaper: {
  11. planCode: 'cheaper',
  12. price: 5,
  13. },
  14. alsoCheap: {
  15. plancode: 'also-cheap',
  16. price: 5,
  17. },
  18. bad: {},
  19. }
  20. describe('SubscriptionHelper', function () {
  21. beforeEach(function () {
  22. this.SubscriptionHelper = SandboxedModule.require(modulePath)
  23. })
  24. describe('shouldPlanChangeAtTermEnd', function () {
  25. it('should return true if the new plan is less expensive', function () {
  26. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  27. plans.expensive,
  28. plans.cheaper
  29. )
  30. expect(changeAtTermEnd).to.be.true
  31. })
  32. it('should return false if the new plan is more exepensive', function () {
  33. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  34. plans.cheaper,
  35. plans.expensive
  36. )
  37. expect(changeAtTermEnd).to.be.false
  38. })
  39. it('should return false if the new plan is the same price', function () {
  40. const changeAtTermEnd = this.SubscriptionHelper.shouldPlanChangeAtTermEnd(
  41. plans.cheaper,
  42. plans.alsoCheap
  43. )
  44. expect(changeAtTermEnd).to.be.false
  45. })
  46. })
  47. })