UserMembershipsHandlerTests.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* eslint-disable
  2. n/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: new 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. requires: {
  27. '../../models/Institution': {
  28. Institution: this.Institution,
  29. },
  30. '../../models/Subscription': {
  31. Subscription: this.Subscription,
  32. },
  33. '../../models/Publisher': {
  34. Publisher: this.Publisher,
  35. },
  36. },
  37. }))
  38. })
  39. describe('remove user', function () {
  40. it('remove user from all entities', function (done) {
  41. return this.UserMembershipsHandler.removeUserFromAllEntities(
  42. this.user._id,
  43. error => {
  44. assertCalledWith(
  45. this.Institution.updateMany,
  46. {},
  47. { $pull: { managerIds: this.user._id } }
  48. )
  49. assertCalledWith(
  50. this.Subscription.updateMany,
  51. {},
  52. { $pull: { manager_ids: this.user._id } }
  53. )
  54. assertCalledWith(
  55. this.Publisher.updateMany,
  56. {},
  57. { $pull: { managerIds: this.user._id } }
  58. )
  59. return done()
  60. }
  61. )
  62. })
  63. })
  64. })