ProjectPersistenceManagerTests.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* eslint-disable
  2. camelcase,
  3. no-return-assign,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS101: Remove unnecessary use of Array.from
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const SandboxedModule = require('sandboxed-module')
  15. const sinon = require('sinon')
  16. require('chai').should()
  17. const modulePath = require('path').join(
  18. __dirname,
  19. '../../../app/js/ProjectPersistenceManager'
  20. )
  21. const tk = require('timekeeper')
  22. describe('ProjectPersistenceManager', function() {
  23. beforeEach(function() {
  24. this.ProjectPersistenceManager = SandboxedModule.require(modulePath, {
  25. requires: {
  26. './UrlCache': (this.UrlCache = {}),
  27. './CompileManager': (this.CompileManager = {}),
  28. 'logger-sharelatex': (this.logger = { log: sinon.stub() }),
  29. './db': (this.db = {})
  30. }
  31. })
  32. this.callback = sinon.stub()
  33. this.project_id = 'project-id-123'
  34. return (this.user_id = '1234')
  35. })
  36. describe('clearExpiredProjects', function() {
  37. beforeEach(function() {
  38. this.project_ids = ['project-id-1', 'project-id-2']
  39. this.ProjectPersistenceManager._findExpiredProjectIds = sinon
  40. .stub()
  41. .callsArgWith(0, null, this.project_ids)
  42. this.ProjectPersistenceManager.clearProjectFromCache = sinon
  43. .stub()
  44. .callsArg(1)
  45. this.CompileManager.clearExpiredProjects = sinon.stub().callsArg(1)
  46. return this.ProjectPersistenceManager.clearExpiredProjects(this.callback)
  47. })
  48. it('should clear each expired project', function() {
  49. return Array.from(this.project_ids).map(project_id =>
  50. this.ProjectPersistenceManager.clearProjectFromCache
  51. .calledWith(project_id)
  52. .should.equal(true)
  53. )
  54. })
  55. return it('should call the callback', function() {
  56. return this.callback.called.should.equal(true)
  57. })
  58. })
  59. return describe('clearProject', function() {
  60. beforeEach(function() {
  61. this.ProjectPersistenceManager._clearProjectFromDatabase = sinon
  62. .stub()
  63. .callsArg(1)
  64. this.UrlCache.clearProject = sinon.stub().callsArg(1)
  65. this.CompileManager.clearProject = sinon.stub().callsArg(2)
  66. return this.ProjectPersistenceManager.clearProject(
  67. this.project_id,
  68. this.user_id,
  69. this.callback
  70. )
  71. })
  72. it('should clear the project from the database', function() {
  73. return this.ProjectPersistenceManager._clearProjectFromDatabase
  74. .calledWith(this.project_id)
  75. .should.equal(true)
  76. })
  77. it('should clear all the cached Urls for the project', function() {
  78. return this.UrlCache.clearProject
  79. .calledWith(this.project_id)
  80. .should.equal(true)
  81. })
  82. it('should clear the project compile folder', function() {
  83. return this.CompileManager.clearProject
  84. .calledWith(this.project_id, this.user_id)
  85. .should.equal(true)
  86. })
  87. return it('should call the callback', function() {
  88. return this.callback.called.should.equal(true)
  89. })
  90. })
  91. })