SubscriptionLocatorTests.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. describe('Subscription Locator Tests', function() {
  21. beforeEach(function() {
  22. this.user = { _id: '5208dd34438842e2db333333' }
  23. this.subscription = { hello: 'world' }
  24. this.Subscription = {
  25. findOne: sinon.stub(),
  26. find: sinon.stub()
  27. }
  28. this.DeletedSubscription = {
  29. findOne: sinon.stub().yields(),
  30. find: sinon.stub().yields()
  31. }
  32. return (this.SubscriptionLocator = SandboxedModule.require(modulePath, {
  33. globals: {
  34. console: console
  35. },
  36. requires: {
  37. './GroupPlansData': {},
  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. })
  88. })