UserHandlerTests.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. find: sinon.stub().returns({
  18. count: sinon.stub().resolves(2),
  19. }),
  20. },
  21. }
  22. this.UserHandler = SandboxedModule.require(modulePath, {
  23. requires: {
  24. '../Subscription/TeamInvitesHandler': this.TeamInvitesHandler,
  25. '../../infrastructure/mongodb': { db: this.db },
  26. },
  27. })
  28. })
  29. describe('populateTeamInvites', function () {
  30. beforeEach(function (done) {
  31. this.UserHandler.populateTeamInvites(this.user, done)
  32. })
  33. it('notifies the user about legacy team invites', function () {
  34. this.TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail
  35. .calledWith(this.user.email)
  36. .should.eq(true)
  37. })
  38. })
  39. describe('countActiveUsers', function () {
  40. it('return user count from DB lookup', async function () {
  41. expect(await this.UserHandler.promises.countActiveUsers()).to.equal(2)
  42. })
  43. })
  44. })