SubscriptionGroupControllerTests.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 sinon = require('sinon')
  15. const { assert } = require('chai')
  16. const modulePath =
  17. '../../../../app/src/Features/Subscription/SubscriptionGroupController'
  18. const MockResponse = require('../helpers/MockResponse')
  19. describe('SubscriptionGroupController', function () {
  20. beforeEach(function () {
  21. this.user = { _id: '!@312431', email: 'user@email.com' }
  22. this.adminUserId = '123jlkj'
  23. this.subscriptionId = '123434325412'
  24. this.user_email = 'bob@gmail.com'
  25. this.req = {
  26. session: {
  27. user: {
  28. _id: this.adminUserId,
  29. email: this.user_email,
  30. },
  31. },
  32. params: {
  33. subscriptionId: this.subscriptionId,
  34. },
  35. query: {},
  36. }
  37. this.subscription = {
  38. _id: this.subscriptionId,
  39. }
  40. this.GroupHandler = { removeUserFromGroup: sinon.stub().callsArgWith(2) }
  41. this.SubscriptionLocator = {
  42. getSubscription: sinon.stub().callsArgWith(1, null, this.subscription),
  43. }
  44. this.SessionManager = {
  45. getLoggedInUserId(session) {
  46. return session.user._id
  47. },
  48. getSessionUser(session) {
  49. return session.user
  50. },
  51. }
  52. return (this.Controller = SandboxedModule.require(modulePath, {
  53. requires: {
  54. './SubscriptionGroupHandler': this.GroupHandler,
  55. './SubscriptionLocator': this.SubscriptionLocator,
  56. '../Authentication/SessionManager': this.SessionManager,
  57. },
  58. }))
  59. })
  60. describe('removeUserFromGroup', function () {
  61. it('should use the subscription id for the logged in user and take the user id from the params', function (done) {
  62. const userIdToRemove = '31231'
  63. this.req.params = { user_id: userIdToRemove }
  64. this.req.entity = this.subscription
  65. const res = {
  66. sendStatus: () => {
  67. this.GroupHandler.removeUserFromGroup
  68. .calledWith(this.subscriptionId, userIdToRemove)
  69. .should.equal(true)
  70. return done()
  71. },
  72. }
  73. return this.Controller.removeUserFromGroup(this.req, res)
  74. })
  75. })
  76. describe('removeSelfFromGroup', function () {
  77. it('gets subscription and remove user', function (done) {
  78. const userIdToRemove = '31231'
  79. this.req.query = { subscriptionId: this.subscriptionId }
  80. const memberUserIdToremove = 123456789
  81. this.req.session.user._id = memberUserIdToremove
  82. const res = {
  83. sendStatus: () => {
  84. sinon.assert.calledWith(
  85. this.SubscriptionLocator.getSubscription,
  86. this.subscriptionId
  87. )
  88. sinon.assert.calledWith(
  89. this.GroupHandler.removeUserFromGroup,
  90. this.subscriptionId,
  91. memberUserIdToremove
  92. )
  93. return done()
  94. },
  95. }
  96. return this.Controller.removeSelfFromGroup(this.req, res)
  97. })
  98. })
  99. })