SubscriptionLocatorTests.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. const SandboxedModule = require('sandboxed-module')
  2. const sinon = require('sinon')
  3. const modulePath =
  4. '../../../../app/src/Features/Subscription/SubscriptionLocator'
  5. describe('Subscription Locator Tests', function () {
  6. beforeEach(function () {
  7. this.user = { _id: '5208dd34438842e2db333333' }
  8. this.subscription = { hello: 'world' }
  9. this.Subscription = {
  10. findOne: sinon.stub(),
  11. find: sinon.stub(),
  12. }
  13. this.DeletedSubscription = {
  14. findOne: sinon.stub().yields(),
  15. find: sinon.stub().yields(),
  16. }
  17. this.SSOConfig = {
  18. findById: sinon.stub().yields(),
  19. }
  20. this.SubscriptionLocator = SandboxedModule.require(modulePath, {
  21. requires: {
  22. './GroupPlansData': {},
  23. '../../models/Subscription': {
  24. Subscription: this.Subscription,
  25. },
  26. '../../models/DeletedSubscription': {
  27. DeletedSubscription: this.DeletedSubscription,
  28. },
  29. '../../models/SSOConfig': {
  30. SSOConfig: this.SSOConfig,
  31. },
  32. },
  33. })
  34. })
  35. describe('finding users subscription', function () {
  36. it('should send the users features', function (done) {
  37. this.Subscription.findOne.callsArgWith(1, null, this.subscription)
  38. this.SubscriptionLocator.getUsersSubscription(
  39. this.user,
  40. (err, subscription) => {
  41. if (err) return done(err)
  42. this.Subscription.findOne
  43. .calledWith({ admin_id: this.user._id })
  44. .should.equal(true)
  45. subscription.should.equal(this.subscription)
  46. done()
  47. }
  48. )
  49. })
  50. it('should error if not found', function (done) {
  51. this.Subscription.findOne.callsArgWith(1, 'not found')
  52. this.SubscriptionLocator.getUsersSubscription(
  53. this.user,
  54. (err, subscription) => {
  55. err.should.exist
  56. done()
  57. }
  58. )
  59. })
  60. it('should take a user id rather than the user object', function (done) {
  61. this.Subscription.findOne.callsArgWith(1, null, this.subscription)
  62. this.SubscriptionLocator.getUsersSubscription(
  63. this.user._id,
  64. (err, subscription) => {
  65. if (err) return done(err)
  66. this.Subscription.findOne
  67. .calledWith({ admin_id: this.user._id })
  68. .should.equal(true)
  69. subscription.should.equal(this.subscription)
  70. done()
  71. }
  72. )
  73. })
  74. })
  75. })