ProjectPersistenceManagerTests.coffee 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. SandboxedModule = require('sandboxed-module')
  2. sinon = require('sinon')
  3. require('chai').should()
  4. modulePath = require('path').join __dirname, '../../../app/js/ProjectPersistenceManager'
  5. tk = require("timekeeper")
  6. describe "ProjectPersistenceManager", ->
  7. beforeEach ->
  8. @ProjectPersistenceManager = SandboxedModule.require modulePath, requires:
  9. "./UrlCache": @UrlCache = {}
  10. "./CompileManager": @CompileManager = {}
  11. "logger-sharelatex": @logger = { log: sinon.stub() }
  12. "./db": @db = {}
  13. @callback = sinon.stub()
  14. @project_id = "project-id-123"
  15. describe "clearExpiredProjects", ->
  16. beforeEach ->
  17. @project_ids = [
  18. "project-id-1"
  19. "project-id-2"
  20. ]
  21. @ProjectPersistenceManager._findExpiredProjectIds = sinon.stub().callsArgWith(0, null, @project_ids)
  22. @ProjectPersistenceManager.clearProject = sinon.stub().callsArg(1)
  23. @ProjectPersistenceManager.clearExpiredProjects @callback
  24. it "should clear each expired project", ->
  25. for project_id in @project_ids
  26. @ProjectPersistenceManager.clearProject
  27. .calledWith(project_id)
  28. .should.equal true
  29. it "should call the callback", ->
  30. @callback.called.should.equal true
  31. describe "clearProject", ->
  32. beforeEach ->
  33. @ProjectPersistenceManager._clearProjectFromDatabase = sinon.stub().callsArg(1)
  34. @UrlCache.clearProject = sinon.stub().callsArg(1)
  35. @CompileManager.clearProject = sinon.stub().callsArg(1)
  36. @ProjectPersistenceManager.clearProject @project_id, @callback
  37. it "should clear the project from the database", ->
  38. @ProjectPersistenceManager._clearProjectFromDatabase
  39. .calledWith(@project_id)
  40. .should.equal true
  41. it "should clear all the cached Urls for the project", ->
  42. @UrlCache.clearProject
  43. .calledWith(@project_id)
  44. .should.equal true
  45. it "should clear the project compile folder", ->
  46. @CompileManager.clearProject
  47. .calledWith(@project_id)
  48. .should.equal true
  49. it "should call the callback", ->
  50. @callback.called.should.equal true