UserMembershipsHandlerTests.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* eslint-disable
  2. node/handle-callback-err,
  3. max-len,
  4. no-return-assign,
  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 sinon = require('sinon')
  14. const assertCalledWith = sinon.assert.calledWith
  15. const { ObjectId } = require('mongodb')
  16. const modulePath =
  17. '../../../../app/src/Features/UserMembership/UserMembershipsHandler'
  18. const SandboxedModule = require('sandboxed-module')
  19. describe('UserMembershipsHandler', function() {
  20. beforeEach(function() {
  21. this.user = { _id: ObjectId() }
  22. this.Institution = { updateMany: sinon.stub().yields(null) }
  23. this.Subscription = { updateMany: sinon.stub().yields(null) }
  24. this.Publisher = { updateMany: sinon.stub().yields(null) }
  25. return (this.UserMembershipsHandler = SandboxedModule.require(modulePath, {
  26. globals: {
  27. console: console
  28. },
  29. requires: {
  30. '../../models/Institution': {
  31. Institution: this.Institution
  32. },
  33. '../../models/Subscription': {
  34. Subscription: this.Subscription
  35. },
  36. '../../models/Publisher': {
  37. Publisher: this.Publisher
  38. }
  39. }
  40. }))
  41. })
  42. describe('remove user', function() {
  43. it('remove user from all entities', function(done) {
  44. return this.UserMembershipsHandler.removeUserFromAllEntities(
  45. this.user._id,
  46. error => {
  47. assertCalledWith(
  48. this.Institution.updateMany,
  49. {},
  50. { $pull: { managerIds: this.user._id } }
  51. )
  52. assertCalledWith(
  53. this.Subscription.updateMany,
  54. {},
  55. { $pull: { manager_ids: this.user._id } }
  56. )
  57. assertCalledWith(
  58. this.Publisher.updateMany,
  59. {},
  60. { $pull: { managerIds: this.user._id } }
  61. )
  62. return done()
  63. }
  64. )
  65. })
  66. })
  67. })