InactiveProjectManagerTests.coffee 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. should = require('chai').should()
  2. SandboxedModule = require('sandboxed-module')
  3. assert = require('assert')
  4. path = require('path')
  5. sinon = require('sinon')
  6. modulePath = path.join __dirname, "../../../../app/js/Features/InactiveData/InactiveProjectManager"
  7. expect = require("chai").expect
  8. describe "InactiveProjectManager", ->
  9. beforeEach ->
  10. @settings = {}
  11. @DocstoreManager =
  12. unarchiveProject:sinon.stub()
  13. @ProjectUpdateHandler =
  14. markAsActive:sinon.stub()
  15. markAsInactive:sinon.stub()
  16. @ProjectGetter =
  17. getProject:sinon.stub()
  18. @InactiveProjectManager = SandboxedModule.require modulePath, requires:
  19. "settings-sharelatex":@settings
  20. "logger-sharelatex":
  21. log:->
  22. err:->
  23. "../Docstore/DocstoreManager":@DocstoreManager
  24. "../Project/ProjectUpdateHandler":@ProjectUpdateHandler
  25. "../Project/ProjectGetter":@ProjectGetter
  26. @project_id = "1234"
  27. describe "reactivateProjectIfRequired", ->
  28. beforeEach ->
  29. @project = {inactive:true}
  30. @ProjectGetter.getProject.callsArgWith(2, null, @project)
  31. @ProjectUpdateHandler.markAsActive.callsArgWith(1)
  32. it "should call unarchiveProject", (done)->
  33. @DocstoreManager.unarchiveProject.callsArgWith(1)
  34. @InactiveProjectManager.reactivateProjectIfRequired @project_id, (err)=>
  35. @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal true
  36. @ProjectUpdateHandler.markAsActive.calledWith(@project_id).should.equal true
  37. done()
  38. it "should not mark project as active if error with unarchinging", (done)->
  39. @DocstoreManager.unarchiveProject.callsArgWith(1, "error")
  40. @InactiveProjectManager.reactivateProjectIfRequired @project_id, (err)=>
  41. err.should.equal "error"
  42. @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal true
  43. @ProjectUpdateHandler.markAsActive.calledWith(@project_id).should.equal false
  44. done()
  45. it "should not call unarchiveProject if it is not inactive", (done)->
  46. delete @project.inactive
  47. @DocstoreManager.unarchiveProject.callsArgWith(1)
  48. @InactiveProjectManager.reactivateProjectIfRequired @project_id, (err)=>
  49. @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal false
  50. @ProjectUpdateHandler.markAsActive.calledWith(@project_id).should.equal false
  51. done()
  52. describe "deactivateProject", ->
  53. beforeEach ->
  54. it "should call unarchiveProject and markAsInactive", (done)->
  55. @DocstoreManager.unarchiveProject.callsArgWith(1)
  56. @ProjectUpdateHandler.markAsInactive.callsArgWith(1)
  57. @InactiveProjectManager.deactivateProject @project_id, (err)->
  58. @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal true
  59. @ProjectUpdateHandler.markAsInactive.callsArgWith(@project_id).should.equal true
  60. done()
  61. it "should not call markAsInactive if there was a problem unarchiving", (done)->
  62. @DocstoreManager.unarchiveProject.callsArgWith(1, "errorrr")
  63. @ProjectUpdateHandler.markAsInactive.callsArgWith(1)
  64. @InactiveProjectManager.deactivateProject @project_id, (err)->
  65. err.should.equal "errorrr"
  66. @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal true
  67. @ProjectUpdateHandler.markAsInactive.callsArgWith(@project_id).should.equal false
  68. done()