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() @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.unarchiveProject.callsArgWith(1) @ProjectUpdateHandler.markAsInactive.callsArgWith(1) @InactiveProjectManager.deactivateProject @project_id, (err)-> @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal true @ProjectUpdateHandler.markAsInactive.callsArgWith(@project_id).should.equal true done() it "should not call markAsInactive if there was a problem unarchiving", (done)-> @DocstoreManager.unarchiveProject.callsArgWith(1, "errorrr") @ProjectUpdateHandler.markAsInactive.callsArgWith(1) @InactiveProjectManager.deactivateProject @project_id, (err)-> err.should.equal "errorrr" @DocstoreManager.unarchiveProject.calledWith(@project_id).should.equal true @ProjectUpdateHandler.markAsInactive.callsArgWith(@project_id).should.equal false done()