SubscriptionGroupControllerTests.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. getSubscription: sinon.stub().callsArgWith(1, null, this.subscription)
  44. }
  45. this.AuthenticationController = {
  46. getLoggedInUserId(req) {
  47. return req.session.user._id
  48. },
  49. getSessionUser(req) {
  50. return req.session.user
  51. }
  52. }
  53. return (this.Controller = SandboxedModule.require(modulePath, {
  54. globals: {
  55. console: console
  56. },
  57. requires: {
  58. './SubscriptionGroupHandler': this.GroupHandler,
  59. 'logger-sharelatex': {
  60. log() {}
  61. },
  62. './SubscriptionLocator': this.SubscriptionLocator,
  63. '../Authentication/AuthenticationController': this
  64. .AuthenticationController
  65. }
  66. }))
  67. })
  68. describe('removeUserFromGroup', function() {
  69. it('should use the subscription id for the logged in user and take the user id from the params', function(done) {
  70. const userIdToRemove = '31231'
  71. this.req.params = { user_id: userIdToRemove }
  72. this.req.entity = this.subscription
  73. const res = {
  74. sendStatus: () => {
  75. this.GroupHandler.removeUserFromGroup
  76. .calledWith(this.subscriptionId, userIdToRemove)
  77. .should.equal(true)
  78. return done()
  79. }
  80. }
  81. return this.Controller.removeUserFromGroup(this.req, res)
  82. })
  83. })
  84. describe('removeSelfFromGroup', function() {
  85. it('gets subscription and remove user', function(done) {
  86. const userIdToRemove = '31231'
  87. this.req.query = { subscriptionId: this.subscriptionId }
  88. const memberUserIdToremove = 123456789
  89. this.req.session.user._id = memberUserIdToremove
  90. const res = {
  91. sendStatus: () => {
  92. sinon.assert.calledWith(
  93. this.SubscriptionLocator.getSubscription,
  94. this.subscriptionId
  95. )
  96. sinon.assert.calledWith(
  97. this.GroupHandler.removeUserFromGroup,
  98. this.subscriptionId,
  99. memberUserIdToremove
  100. )
  101. return done()
  102. }
  103. }
  104. return this.Controller.removeSelfFromGroup(this.req, res)
  105. })
  106. })
  107. })