InactiveProjectManagerTests.coffee 4.0 KB

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