InactiveProjectManagerTests.coffee 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. @TrackChangesManager =
  20. archiveProject:sinon.stub()
  21. @InactiveProjectManager = SandboxedModule.require modulePath, requires:
  22. "settings-sharelatex":@settings
  23. "logger-sharelatex":
  24. log:->
  25. err:->
  26. "../Docstore/DocstoreManager":@DocstoreManager
  27. "../Project/ProjectUpdateHandler":@ProjectUpdateHandler
  28. "../Project/ProjectGetter":@ProjectGetter
  29. "../TrackChanges/TrackChangesManager":@TrackChangesManager
  30. @project_id = "1234"
  31. describe "reactivateProjectIfRequired", ->
  32. beforeEach ->
  33. @project = {active:false}
  34. @ProjectGetter.getProject.callsArgWith(2, null, @project)
  35. @ProjectUpdateHandler.markAsActive.callsArgWith(1)
  36. it "should call unarchiveProject", (done)->
  37. @DocstoreManager.unarchiveProject.callsArgWith(1)
  38. @InactiveProjectManager.reactivateProjectIfRequired @project_id, (err)=>
  39. @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal true
  40. @ProjectUpdateHandler.markAsActive.calledWith(@project_id).should.equal true
  41. done()
  42. it "should not mark project as active if error with unarchinging", (done)->
  43. @DocstoreManager.unarchiveProject.callsArgWith(1, "error")
  44. @InactiveProjectManager.reactivateProjectIfRequired @project_id, (err)=>
  45. err.should.equal "error"
  46. @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal true
  47. @ProjectUpdateHandler.markAsActive.calledWith(@project_id).should.equal false
  48. done()
  49. it "should not call unarchiveProject if it is active", (done)->
  50. @project.active = true
  51. @DocstoreManager.unarchiveProject.callsArgWith(1)
  52. @InactiveProjectManager.reactivateProjectIfRequired @project_id, (err)=>
  53. @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal false
  54. @ProjectUpdateHandler.markAsActive.calledWith(@project_id).should.equal false
  55. done()
  56. describe "deactivateProject", ->
  57. it "should call unarchiveProject and markAsInactive", (done)->
  58. @DocstoreManager.archiveProject.callsArgWith(1)
  59. @TrackChangesManager.archiveProject.callsArgWith(1)
  60. @ProjectUpdateHandler.markAsInactive.callsArgWith(1)
  61. @InactiveProjectManager.deactivateProject @project_id, (err)=>
  62. @DocstoreManager.archiveProject.calledWith(@project_id).should.equal true
  63. @TrackChangesManager.archiveProject.calledWith(@project_id).should.equal true
  64. @ProjectUpdateHandler.markAsInactive.calledWith(@project_id).should.equal true
  65. done()
  66. it "should not call markAsInactive if there was a problem archiving in docstore", (done)->
  67. @DocstoreManager.archiveProject.callsArgWith(1, "errorrr")
  68. @TrackChangesManager.archiveProject.callsArgWith(1)
  69. @ProjectUpdateHandler.markAsInactive.callsArgWith(1)
  70. @InactiveProjectManager.deactivateProject @project_id, (err)=>
  71. err.should.equal "errorrr"
  72. @DocstoreManager.archiveProject.calledWith(@project_id).should.equal true
  73. @ProjectUpdateHandler.markAsInactive.calledWith(@project_id).should.equal false
  74. done()
  75. it "should not call markAsInactive if there was a problem archiving in track changes", (done)->
  76. @DocstoreManager.archiveProject.callsArgWith(1)
  77. @TrackChangesManager.archiveProject.callsArgWith(1, "errorrr")
  78. @ProjectUpdateHandler.markAsInactive.callsArgWith(1)
  79. @InactiveProjectManager.deactivateProject @project_id, (err)=>
  80. err.should.equal "errorrr"
  81. @DocstoreManager.archiveProject.calledWith(@project_id).should.equal true
  82. @ProjectUpdateHandler.markAsInactive.calledWith(@project_id).should.equal false
  83. done()