SubscriptionLocatorTests.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* eslint-disable
  2. 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 should = require('chai').should()
  16. const sinon = require('sinon')
  17. const modulePath =
  18. '../../../../app/src/Features/Subscription/SubscriptionLocator'
  19. const { assert } = require('chai')
  20. const { ObjectId } = require('mongoose').Types
  21. describe('Subscription Locator Tests', function() {
  22. beforeEach(function() {
  23. this.user = { _id: '5208dd34438842e2db333333' }
  24. this.subscription = { hello: 'world' }
  25. this.Subscription = {
  26. findOne: sinon.stub(),
  27. find: sinon.stub()
  28. }
  29. this.DeletedSubscription = {
  30. findOne: sinon.stub().yields(),
  31. find: sinon.stub().yields()
  32. }
  33. return (this.SubscriptionLocator = SandboxedModule.require(modulePath, {
  34. globals: {
  35. console: console
  36. },
  37. requires: {
  38. '../../models/Subscription': {
  39. Subscription: this.Subscription
  40. },
  41. '../../models/DeletedSubscription': {
  42. DeletedSubscription: this.DeletedSubscription
  43. },
  44. 'logger-sharelatex': {
  45. log() {}
  46. }
  47. }
  48. }))
  49. })
  50. describe('finding users subscription', function() {
  51. it('should send the users features', function(done) {
  52. this.Subscription.findOne.callsArgWith(1, null, this.subscription)
  53. return this.SubscriptionLocator.getUsersSubscription(
  54. this.user,
  55. (err, subscription) => {
  56. this.Subscription.findOne
  57. .calledWith({ admin_id: this.user._id })
  58. .should.equal(true)
  59. subscription.should.equal(this.subscription)
  60. return done()
  61. }
  62. )
  63. })
  64. it('should error if not found', function(done) {
  65. this.Subscription.findOne.callsArgWith(1, 'not found')
  66. return this.SubscriptionLocator.getUsersSubscription(
  67. this.user,
  68. (err, subscription) => {
  69. err.should.exist
  70. return done()
  71. }
  72. )
  73. })
  74. it('should take a user id rather than the user object', function(done) {
  75. this.Subscription.findOne.callsArgWith(1, null, this.subscription)
  76. return this.SubscriptionLocator.getUsersSubscription(
  77. this.user._id,
  78. (err, subscription) => {
  79. this.Subscription.findOne
  80. .calledWith({ admin_id: this.user._id })
  81. .should.equal(true)
  82. subscription.should.equal(this.subscription)
  83. return done()
  84. }
  85. )
  86. })
  87. describe('finding managed subscription', function() {
  88. it('should query the database', function(done) {
  89. this.Subscription.findOne.callsArgWith(1, null, this.subscription)
  90. return this.SubscriptionLocator.findManagedSubscription(
  91. this.user._id,
  92. (err, subscription) => {
  93. this.Subscription.findOne
  94. .calledWith({ manager_ids: this.user._id })
  95. .should.equal(true)
  96. subscription.should.equal(this.subscription)
  97. return done()
  98. }
  99. )
  100. })
  101. })
  102. })
  103. })