UserHandler.test.mjs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { vi, expect } from 'vitest'
  2. import sinon from 'sinon'
  3. const modulePath = '../../../../app/src/Features/User/UserHandler.mjs'
  4. describe('UserHandler', function () {
  5. beforeEach(async function (ctx) {
  6. ctx.user = {
  7. _id: '12390i',
  8. email: 'bob@bob.com',
  9. remove: sinon.stub().callsArgWith(0),
  10. }
  11. ctx.TeamInvitesHandler = {
  12. promises: {
  13. createTeamInvitesForLegacyInvitedEmail: sinon.stub().resolves(),
  14. },
  15. }
  16. ctx.db = {
  17. users: {
  18. countDocuments: sinon.stub().resolves(2),
  19. },
  20. }
  21. vi.doMock(
  22. '../../../../app/src/Features/Subscription/TeamInvitesHandler',
  23. () => ({
  24. default: ctx.TeamInvitesHandler,
  25. })
  26. )
  27. vi.doMock('../../../../app/src/infrastructure/mongodb', () => ({
  28. db: ctx.db,
  29. READ_PREFERENCE_SECONDARY: 'read-preference-secondary',
  30. }))
  31. ctx.UserHandler = (await import(modulePath)).default
  32. })
  33. describe('populateTeamInvites', function () {
  34. beforeEach(async function (ctx) {
  35. await ctx.UserHandler.promises.populateTeamInvites(ctx.user)
  36. })
  37. it('notifies the user about legacy team invites', function (ctx) {
  38. ctx.TeamInvitesHandler.promises.createTeamInvitesForLegacyInvitedEmail
  39. .calledWith(ctx.user.email)
  40. .should.eq(true)
  41. })
  42. })
  43. describe('countActiveUsers', function () {
  44. it('return user count from DB lookup', async function (ctx) {
  45. expect(await ctx.UserHandler.promises.countActiveUsers()).to.equal(2)
  46. })
  47. })
  48. })