overleaf/services/web/test/UnitTests/coffee/InactiveData/InactiveProjectManagerTests.coffee

87 lines
3.2 KiB
CoffeeScript
Raw Normal View History

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()
@InactiveProjectManager = SandboxedModule.require modulePath, requires:
"settings-sharelatex":@settings
"logger-sharelatex":
log:->
err:->
"../Docstore/DocstoreManager":@DocstoreManager
"../Project/ProjectUpdateHandler":@ProjectUpdateHandler
"../Project/ProjectGetter":@ProjectGetter
@project_id = "1234"
describe "reactivateProjectIfRequired", ->
beforeEach ->
@project = {inactive:true}
@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 not inactive", (done)->
delete @project.inactive
@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", ->
beforeEach ->
it "should call unarchiveProject and markAsInactive", (done)->
@DocstoreManager.archiveProject.callsArgWith(1)
@ProjectUpdateHandler.markAsInactive.callsArgWith(1)
@InactiveProjectManager.deactivateProject @project_id, (err)=>
@DocstoreManager.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 unarchiving", (done)->
@DocstoreManager.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()