PlansLocatorTests.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. })