TutorialHandlerTests.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const SandboxedModule = require('sandboxed-module')
  2. const { expect } = require('chai')
  3. const sinon = require('sinon')
  4. const { ObjectId } = require('mongodb-legacy')
  5. const MODULE_PATH = '../../../../app/src/Features/Tutorial/TutorialHandler'
  6. describe('TutorialHandler', function () {
  7. beforeEach(function () {
  8. this.clock = sinon.useFakeTimers()
  9. this.user = {
  10. _id: new ObjectId(),
  11. completedTutorials: {
  12. 'legacy-format': new Date(Date.now() - 1000),
  13. completed: {
  14. state: 'completed',
  15. updatedAt: new Date(Date.now() - 1000),
  16. },
  17. 'postponed-recently': {
  18. state: 'postponed',
  19. updatedAt: new Date(Date.now() - 1000),
  20. },
  21. 'postponed-long-ago': {
  22. state: 'postponed',
  23. updatedAt: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
  24. },
  25. },
  26. }
  27. this.UserUpdater = {
  28. promises: {
  29. updateUser: sinon.stub().resolves(),
  30. },
  31. }
  32. this.TutorialHandler = SandboxedModule.require(MODULE_PATH, {
  33. requires: {
  34. '../User/UserUpdater': this.UserUpdater,
  35. },
  36. })
  37. })
  38. afterEach(function () {
  39. this.clock.restore()
  40. })
  41. describe('getInactiveTutorials', function () {
  42. it('returns all recorded tutorials except when they were posponed long ago', function () {
  43. const hiddenTutorials = this.TutorialHandler.getInactiveTutorials(
  44. this.user
  45. )
  46. expect(hiddenTutorials).to.have.members([
  47. 'legacy-format',
  48. 'completed',
  49. 'postponed-recently',
  50. ])
  51. })
  52. })
  53. })