SubscriptionLocatorTests.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* eslint-disable
  2. node/handle-callback-err,
  3. max-len,
  4. no-return-assign,
  5. no-unused-vars,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const SandboxedModule = require('sandboxed-module')
  15. const sinon = require('sinon')
  16. const modulePath =
  17. '../../../../app/src/Features/Subscription/SubscriptionLocator'
  18. const { assert } = require('chai')
  19. describe('Subscription Locator Tests', function () {
  20. beforeEach(function () {
  21. this.user = { _id: '5208dd34438842e2db333333' }
  22. this.subscription = { hello: 'world' }
  23. this.Subscription = {
  24. findOne: sinon.stub(),
  25. find: sinon.stub(),
  26. }
  27. this.DeletedSubscription = {
  28. findOne: sinon.stub().yields(),
  29. find: sinon.stub().yields(),
  30. }
  31. return (this.SubscriptionLocator = SandboxedModule.require(modulePath, {
  32. requires: {
  33. './GroupPlansData': {},
  34. '../../models/Subscription': {
  35. Subscription: this.Subscription,
  36. },
  37. '../../models/DeletedSubscription': {
  38. DeletedSubscription: this.DeletedSubscription,
  39. },
  40. },
  41. }))
  42. })
  43. describe('finding users subscription', function () {
  44. it('should send the users features', function (done) {
  45. this.Subscription.findOne.callsArgWith(1, null, this.subscription)
  46. return this.SubscriptionLocator.getUsersSubscription(
  47. this.user,
  48. (err, subscription) => {
  49. this.Subscription.findOne
  50. .calledWith({ admin_id: this.user._id })
  51. .should.equal(true)
  52. subscription.should.equal(this.subscription)
  53. return done()
  54. }
  55. )
  56. })
  57. it('should error if not found', function (done) {
  58. this.Subscription.findOne.callsArgWith(1, 'not found')
  59. return this.SubscriptionLocator.getUsersSubscription(
  60. this.user,
  61. (err, subscription) => {
  62. err.should.exist
  63. return done()
  64. }
  65. )
  66. })
  67. it('should take a user id rather than the user object', function (done) {
  68. this.Subscription.findOne.callsArgWith(1, null, this.subscription)
  69. return this.SubscriptionLocator.getUsersSubscription(
  70. this.user._id,
  71. (err, subscription) => {
  72. this.Subscription.findOne
  73. .calledWith({ admin_id: this.user._id })
  74. .should.equal(true)
  75. subscription.should.equal(this.subscription)
  76. return done()
  77. }
  78. )
  79. })
  80. })
  81. })