UserHandlerTests.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const sinon = require('sinon')
  2. const { expect } = require('chai')
  3. const modulePath = '../../../../app/src/Features/User/UserHandler.js'
  4. const SandboxedModule = require('sandboxed-module')
  5. describe('UserHandler', function () {
  6. beforeEach(function () {
  7. this.user = {
  8. _id: '12390i',
  9. email: 'bob@bob.com',
  10. remove: sinon.stub().callsArgWith(0),
  11. }
  12. this.TeamInvitesHandler = {
  13. createTeamInvitesForLegacyInvitedEmail: sinon.stub().yields(),
  14. }
  15. this.db = {
  16. users: {
  17. countDocuments: sinon.stub().resolves(2),
  18. },
  19. }
  20. this.UserHandler = SandboxedModule.require(modulePath, {
  21. requires: {
  22. '../Subscription/TeamInvitesHandler': this.TeamInvitesHandler,
  23. '../../infrastructure/mongodb': { db: this.db },
  24. },
  25. })
  26. })
  27. describe('populateTeamInvites', function () {
  28. beforeEach(function (done) {
  29. this.UserHandler.populateTeamInvites(this.user, done)
  30. })
  31. it('notifies the user about legacy team invites', function () {
  32. this.TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail
  33. .calledWith(this.user.email)
  34. .should.eq(true)
  35. })
  36. })
  37. describe('countActiveUsers', function () {
  38. it('return user count from DB lookup', async function () {
  39. expect(await this.UserHandler.promises.countActiveUsers()).to.equal(2)
  40. })
  41. })
  42. })