2015-08-13 17:40:28 -04:00
|
|
|
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()
|
2015-08-13 17:51:05 -04:00
|
|
|
archiveProject:sinon.stub()
|
2015-08-13 17:40:28 -04:00
|
|
|
@ProjectUpdateHandler =
|
|
|
|
markAsActive:sinon.stub()
|
|
|
|
markAsInactive:sinon.stub()
|
|
|
|
@ProjectGetter =
|
|
|
|
getProject:sinon.stub()
|
2015-10-19 10:44:43 -04:00
|
|
|
@TrackChangesManager =
|
|
|
|
archiveProject:sinon.stub()
|
2015-08-13 17:40:28 -04:00
|
|
|
@InactiveProjectManager = SandboxedModule.require modulePath, requires:
|
|
|
|
"settings-sharelatex":@settings
|
|
|
|
"logger-sharelatex":
|
|
|
|
log:->
|
|
|
|
err:->
|
|
|
|
"../Docstore/DocstoreManager":@DocstoreManager
|
|
|
|
"../Project/ProjectUpdateHandler":@ProjectUpdateHandler
|
|
|
|
"../Project/ProjectGetter":@ProjectGetter
|
2015-10-19 10:44:43 -04:00
|
|
|
"../TrackChanges/TrackChangesManager":@TrackChangesManager
|
2015-10-19 10:48:59 -04:00
|
|
|
"../../models/Project":{}
|
2015-08-13 17:40:28 -04:00
|
|
|
@project_id = "1234"
|
|
|
|
|
|
|
|
describe "reactivateProjectIfRequired", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
2015-08-19 06:54:30 -04:00
|
|
|
@project = {active:false}
|
2015-08-13 17:40:28 -04:00
|
|
|
@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()
|
|
|
|
|
|
|
|
|
2015-08-19 06:54:30 -04:00
|
|
|
it "should not call unarchiveProject if it is active", (done)->
|
|
|
|
@project.active = true
|
2015-08-13 17:40:28 -04:00
|
|
|
@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)->
|
2015-08-13 17:51:05 -04:00
|
|
|
@DocstoreManager.archiveProject.callsArgWith(1)
|
2015-10-19 10:44:43 -04:00
|
|
|
@TrackChangesManager.archiveProject.callsArgWith(1)
|
|
|
|
|
2015-08-13 17:40:28 -04:00
|
|
|
@ProjectUpdateHandler.markAsInactive.callsArgWith(1)
|
|
|
|
|
2015-08-13 17:51:05 -04:00
|
|
|
@InactiveProjectManager.deactivateProject @project_id, (err)=>
|
|
|
|
@DocstoreManager.archiveProject.calledWith(@project_id).should.equal true
|
2015-10-20 12:36:37 -04:00
|
|
|
# @TrackChangesManager.archiveProject.calledWith(@project_id).should.equal true
|
2015-08-13 17:51:05 -04:00
|
|
|
@ProjectUpdateHandler.markAsInactive.calledWith(@project_id).should.equal true
|
2015-08-13 17:40:28 -04:00
|
|
|
done()
|
|
|
|
|
2015-10-19 10:44:43 -04:00
|
|
|
it "should not call markAsInactive if there was a problem archiving in docstore", (done)->
|
2015-08-13 17:51:05 -04:00
|
|
|
@DocstoreManager.archiveProject.callsArgWith(1, "errorrr")
|
2015-10-19 10:44:43 -04:00
|
|
|
@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()
|
|
|
|
|
|
|
|
|
2015-10-20 12:36:37 -04:00
|
|
|
# it "should not call markAsInactive if there was a problem archiving in track changes", (done)->
|
|
|
|
# @DocstoreManager.archiveProject.callsArgWith(1)
|
|
|
|
# @TrackChangesManager.archiveProject.callsArgWith(1, "errorrr")
|
2015-10-19 10:44:43 -04:00
|
|
|
|
2015-10-20 12:36:37 -04:00
|
|
|
# @ProjectUpdateHandler.markAsInactive.callsArgWith(1)
|
2015-08-13 17:40:28 -04:00
|
|
|
|
2015-10-20 12:36:37 -04:00
|
|
|
# @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()
|