SubscriptionGroupControllerTests.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const SandboxedModule = require('sandboxed-module')
  14. const should = require('chai').should()
  15. const sinon = require('sinon')
  16. const { assert } = require('chai')
  17. const modulePath =
  18. '../../../../app/src/Features/Subscription/SubscriptionGroupController'
  19. const MockResponse = require('../helpers/MockResponse')
  20. describe('SubscriptionGroupController', function() {
  21. beforeEach(function() {
  22. this.user = { _id: '!@312431', email: 'user@email.com' }
  23. this.adminUserId = '123jlkj'
  24. this.subscriptionId = '123434325412'
  25. this.user_email = 'bob@gmail.com'
  26. this.req = {
  27. session: {
  28. user: {
  29. _id: this.adminUserId,
  30. email: this.user_email
  31. }
  32. },
  33. params: {
  34. subscriptionId: this.subscriptionId
  35. },
  36. query: {}
  37. }
  38. this.subscription = {
  39. _id: this.subscriptionId
  40. }
  41. this.GroupHandler = { removeUserFromGroup: sinon.stub().callsArgWith(2) }
  42. this.SubscriptionLocator = {
  43. findManagedSubscription: sinon
  44. .stub()
  45. .callsArgWith(1, null, this.subscription)
  46. }
  47. this.AuthenticationController = {
  48. getLoggedInUserId(req) {
  49. return req.session.user._id
  50. },
  51. getSessionUser(req) {
  52. return req.session.user
  53. }
  54. }
  55. return (this.Controller = SandboxedModule.require(modulePath, {
  56. globals: {
  57. console: console
  58. },
  59. requires: {
  60. './SubscriptionGroupHandler': this.GroupHandler,
  61. 'logger-sharelatex': {
  62. log() {}
  63. },
  64. './SubscriptionLocator': this.SubscriptionLocator,
  65. '../Authentication/AuthenticationController': this
  66. .AuthenticationController
  67. }
  68. }))
  69. })
  70. describe('removeUserFromGroup', () =>
  71. it('should use the subscription id for the logged in user and take the user id from the params', function(done) {
  72. const userIdToRemove = '31231'
  73. this.req.params = { user_id: userIdToRemove }
  74. this.req.entity = this.subscription
  75. const res = {
  76. send: () => {
  77. this.GroupHandler.removeUserFromGroup
  78. .calledWith(this.subscriptionId, userIdToRemove)
  79. .should.equal(true)
  80. return done()
  81. }
  82. }
  83. return this.Controller.removeUserFromGroup(this.req, res)
  84. }))
  85. })