InactiveProjectManagerTests.coffee 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. archiveProject:sinon.stub()
  14. @ProjectUpdateHandler =
  15. markAsActive:sinon.stub()
  16. markAsInactive:sinon.stub()
  17. @ProjectGetter =
  18. getProject:sinon.stub()
  19. @InactiveProjectManager = SandboxedModule.require modulePath, requires:
  20. "settings-sharelatex":@settings
  21. "logger-sharelatex":
  22. log:->
  23. err:->
  24. "../Docstore/DocstoreManager":@DocstoreManager
  25. "../Project/ProjectUpdateHandler":@ProjectUpdateHandler
  26. "../Project/ProjectGetter":@ProjectGetter
  27. @project_id = "1234"
  28. describe "reactivateProjectIfRequired", ->
  29. beforeEach ->
  30. @project = {inactive:true}
  31. @ProjectGetter.getProject.callsArgWith(2, null, @project)
  32. @ProjectUpdateHandler.markAsActive.callsArgWith(1)
  33. it "should call unarchiveProject", (done)->
  34. @DocstoreManager.unarchiveProject.callsArgWith(1)
  35. @InactiveProjectManager.reactivateProjectIfRequired @project_id, (err)=>
  36. @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal true
  37. @ProjectUpdateHandler.markAsActive.calledWith(@project_id).should.equal true
  38. done()
  39. it "should not mark project as active if error with unarchinging", (done)->
  40. @DocstoreManager.unarchiveProject.callsArgWith(1, "error")
  41. @InactiveProjectManager.reactivateProjectIfRequired @project_id, (err)=>
  42. err.should.equal "error"
  43. @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal true
  44. @ProjectUpdateHandler.markAsActive.calledWith(@project_id).should.equal false
  45. done()
  46. it "should not call unarchiveProject if it is not inactive", (done)->
  47. delete @project.inactive
  48. @DocstoreManager.unarchiveProject.callsArgWith(1)
  49. @InactiveProjectManager.reactivateProjectIfRequired @project_id, (err)=>
  50. @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal false
  51. @ProjectUpdateHandler.markAsActive.calledWith(@project_id).should.equal false
  52. done()
  53. describe "deactivateProject", ->
  54. beforeEach ->
  55. it "should call unarchiveProject and markAsInactive", (done)->
  56. @DocstoreManager.archiveProject.callsArgWith(1)
  57. @ProjectUpdateHandler.markAsInactive.callsArgWith(1)
  58. @InactiveProjectManager.deactivateProject @project_id, (err)=>
  59. @DocstoreManager.archiveProject.calledWith(@project_id).should.equal true
  60. @ProjectUpdateHandler.markAsInactive.calledWith(@project_id).should.equal true
  61. done()
  62. it "should not call markAsInactive if there was a problem unarchiving", (done)->
  63. @DocstoreManager.archiveProject.callsArgWith(1, "errorrr")
  64. @ProjectUpdateHandler.markAsInactive.callsArgWith(1)
  65. @InactiveProjectManager.deactivateProject @project_id, (err)=>
  66. err.should.equal "errorrr"
  67. @DocstoreManager.archiveProject.calledWith(@project_id).should.equal true
  68. @ProjectUpdateHandler.markAsInactive.calledWith(@project_id).should.equal false
  69. done()