SubscriptionLocatorTests.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. return (this.SubscriptionLocator = SandboxedModule.require(modulePath, {
  30. globals: {
  31. console: console
  32. },
  33. requires: {
  34. '../../models/Subscription': {
  35. Subscription: this.Subscription
  36. },
  37. 'logger-sharelatex': {
  38. log() {}
  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. describe('finding managed subscription', () =>
  81. it('should query the database', function(done) {
  82. this.Subscription.findOne.callsArgWith(1, null, this.subscription)
  83. return this.SubscriptionLocator.findManagedSubscription(
  84. this.user._id,
  85. (err, subscription) => {
  86. this.Subscription.findOne
  87. .calledWith({ manager_ids: this.user._id })
  88. .should.equal(true)
  89. subscription.should.equal(this.subscription)
  90. return done()
  91. }
  92. )
  93. }))
  94. })
  95. })