SubscriptionLocatorTests.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.SubscriptionLocator = SandboxedModule.require(modulePath, {
  18. requires: {
  19. './GroupPlansData': {},
  20. '../../models/Subscription': {
  21. Subscription: this.Subscription,
  22. },
  23. '../../models/DeletedSubscription': {
  24. DeletedSubscription: this.DeletedSubscription,
  25. },
  26. },
  27. })
  28. })
  29. describe('finding users subscription', function () {
  30. it('should send the users features', function (done) {
  31. this.Subscription.findOne.callsArgWith(1, null, this.subscription)
  32. this.SubscriptionLocator.getUsersSubscription(
  33. this.user,
  34. (err, subscription) => {
  35. if (err) return done(err)
  36. this.Subscription.findOne
  37. .calledWith({ admin_id: this.user._id })
  38. .should.equal(true)
  39. subscription.should.equal(this.subscription)
  40. done()
  41. }
  42. )
  43. })
  44. it('should error if not found', function (done) {
  45. this.Subscription.findOne.callsArgWith(1, 'not found')
  46. this.SubscriptionLocator.getUsersSubscription(
  47. this.user,
  48. (err, subscription) => {
  49. err.should.exist
  50. done()
  51. }
  52. )
  53. })
  54. it('should take a user id rather than the user object', function (done) {
  55. this.Subscription.findOne.callsArgWith(1, null, this.subscription)
  56. this.SubscriptionLocator.getUsersSubscription(
  57. this.user._id,
  58. (err, subscription) => {
  59. if (err) return done(err)
  60. this.Subscription.findOne
  61. .calledWith({ admin_id: this.user._id })
  62. .should.equal(true)
  63. subscription.should.equal(this.subscription)
  64. done()
  65. }
  66. )
  67. })
  68. })
  69. })