| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- should = require('chai').should()
- SandboxedModule = require('sandboxed-module')
- assert = require('assert')
- path = require('path')
- sinon = require('sinon')
- modulePath = path.join __dirname, "../../../../app/js/Features/InactiveData/InactiveProjectManager"
- expect = require("chai").expect
- describe "InactiveProjectManager", ->
- beforeEach ->
- @settings = {}
- @DocstoreManager =
- unarchiveProject:sinon.stub()
- archiveProject:sinon.stub()
- @ProjectUpdateHandler =
- markAsActive:sinon.stub()
- markAsInactive:sinon.stub()
- @ProjectGetter =
- getProject:sinon.stub()
- @TrackChangesManager =
- archiveProject:sinon.stub()
- @InactiveProjectManager = SandboxedModule.require modulePath, requires:
- "settings-sharelatex":@settings
- "logger-sharelatex":
- log:->
- err:->
- "../Docstore/DocstoreManager":@DocstoreManager
- "../Project/ProjectUpdateHandler":@ProjectUpdateHandler
- "../Project/ProjectGetter":@ProjectGetter
- "../TrackChanges/TrackChangesManager":@TrackChangesManager
- "../../models/Project":{}
- @project_id = "1234"
- describe "reactivateProjectIfRequired", ->
- beforeEach ->
- @project = {active:false}
- @ProjectGetter.getProject.callsArgWith(2, null, @project)
- @ProjectUpdateHandler.markAsActive.callsArgWith(1)
- it "should call unarchiveProject", (done)->
- @DocstoreManager.unarchiveProject.callsArgWith(1)
- @InactiveProjectManager.reactivateProjectIfRequired @project_id, (err)=>
- @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal true
- @ProjectUpdateHandler.markAsActive.calledWith(@project_id).should.equal true
- done()
- it "should not mark project as active if error with unarchinging", (done)->
- @DocstoreManager.unarchiveProject.callsArgWith(1, "error")
- @InactiveProjectManager.reactivateProjectIfRequired @project_id, (err)=>
- err.should.equal "error"
- @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal true
- @ProjectUpdateHandler.markAsActive.calledWith(@project_id).should.equal false
- done()
- it "should not call unarchiveProject if it is active", (done)->
- @project.active = true
- @DocstoreManager.unarchiveProject.callsArgWith(1)
- @InactiveProjectManager.reactivateProjectIfRequired @project_id, (err)=>
- @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal false
- @ProjectUpdateHandler.markAsActive.calledWith(@project_id).should.equal false
- done()
- describe "deactivateProject", ->
- it "should call unarchiveProject and markAsInactive", (done)->
- @DocstoreManager.archiveProject.callsArgWith(1)
- @TrackChangesManager.archiveProject.callsArgWith(1)
- @ProjectUpdateHandler.markAsInactive.callsArgWith(1)
- @InactiveProjectManager.deactivateProject @project_id, (err)=>
- @DocstoreManager.archiveProject.calledWith(@project_id).should.equal true
- # @TrackChangesManager.archiveProject.calledWith(@project_id).should.equal true
- @ProjectUpdateHandler.markAsInactive.calledWith(@project_id).should.equal true
- done()
- it "should not call markAsInactive if there was a problem archiving in docstore", (done)->
- @DocstoreManager.archiveProject.callsArgWith(1, "errorrr")
- @TrackChangesManager.archiveProject.callsArgWith(1)
- @ProjectUpdateHandler.markAsInactive.callsArgWith(1)
- @InactiveProjectManager.deactivateProject @project_id, (err)=>
- err.should.equal "errorrr"
- @DocstoreManager.archiveProject.calledWith(@project_id).should.equal true
- @ProjectUpdateHandler.markAsInactive.calledWith(@project_id).should.equal false
- done()
- # it "should not call markAsInactive if there was a problem archiving in track changes", (done)->
- # @DocstoreManager.archiveProject.callsArgWith(1)
- # @TrackChangesManager.archiveProject.callsArgWith(1, "errorrr")
- # @ProjectUpdateHandler.markAsInactive.callsArgWith(1)
- # @InactiveProjectManager.deactivateProject @project_id, (err)=>
- # err.should.equal "errorrr"
- # @DocstoreManager.archiveProject.calledWith(@project_id).should.equal true
- # @ProjectUpdateHandler.markAsInactive.calledWith(@project_id).should.equal false
- # done()
|