ProjectPersistenceManagerTests.coffee 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. @user_id = "1234"
  16. describe "clearExpiredProjects", ->
  17. beforeEach ->
  18. @project_ids = [
  19. "project-id-1"
  20. "project-id-2"
  21. ]
  22. @ProjectPersistenceManager._findExpiredProjectIds = sinon.stub().callsArgWith(0, null, @project_ids)
  23. @ProjectPersistenceManager.clearProjectFromCache = sinon.stub().callsArg(1)
  24. @CompileManager.clearExpiredProjects = sinon.stub().callsArg(1)
  25. @ProjectPersistenceManager.clearExpiredProjects @callback
  26. it "should clear each expired project", ->
  27. for project_id in @project_ids
  28. @ProjectPersistenceManager.clearProjectFromCache
  29. .calledWith(project_id)
  30. .should.equal true
  31. it "should call the callback", ->
  32. @callback.called.should.equal true
  33. describe "clearProject", ->
  34. beforeEach ->
  35. @ProjectPersistenceManager._clearProjectFromDatabase = sinon.stub().callsArg(1)
  36. @UrlCache.clearProject = sinon.stub().callsArg(1)
  37. @CompileManager.clearProject = sinon.stub().callsArg(2)
  38. @ProjectPersistenceManager.clearProject @project_id, @user_id, @callback
  39. it "should clear the project from the database", ->
  40. @ProjectPersistenceManager._clearProjectFromDatabase
  41. .calledWith(@project_id)
  42. .should.equal true
  43. it "should clear all the cached Urls for the project", ->
  44. @UrlCache.clearProject
  45. .calledWith(@project_id)
  46. .should.equal true
  47. it "should clear the project compile folder", ->
  48. @CompileManager.clearProject
  49. .calledWith(@project_id, @user_id)
  50. .should.equal true
  51. it "should call the callback", ->
  52. @callback.called.should.equal true