2020-02-17 12:35:01 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-17 12:34:50 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const chai = require('chai');
|
|
|
|
const should = chai.should();
|
|
|
|
const { expect } = chai;
|
|
|
|
const modulePath = "../../../../app/js/RestoreManager.js";
|
|
|
|
const SandboxedModule = require('sandboxed-module');
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-02-17 12:34:50 -05:00
|
|
|
describe("RestoreManager", function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.RestoreManager = SandboxedModule.require(modulePath, { requires: {
|
|
|
|
"logger-sharelatex": (this.logger = { log: sinon.stub(), error: sinon.stub() }),
|
|
|
|
"./DocumentUpdaterManager": (this.DocumentUpdaterManager = {}),
|
|
|
|
"./DiffManager": (this.DiffManager = {})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.callback = sinon.stub();
|
|
|
|
this.project_id = "mock-project-id";
|
|
|
|
this.doc_id = "mock-doc-id";
|
|
|
|
this.user_id = "mock-user-id";
|
|
|
|
return this.version = 42;
|
|
|
|
});
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-02-17 12:34:50 -05:00
|
|
|
return describe("restoreToBeforeVersion", function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.content = "mock content";
|
|
|
|
this.DocumentUpdaterManager.setDocument = sinon.stub().callsArg(4);
|
|
|
|
this.DiffManager.getDocumentBeforeVersion = sinon.stub().callsArgWith(3, null, this.content);
|
|
|
|
return this.RestoreManager.restoreToBeforeVersion(this.project_id, this.doc_id, this.version, this.user_id, this.callback);
|
|
|
|
});
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-02-17 12:34:50 -05:00
|
|
|
it("should get the content before the requested version", function() {
|
|
|
|
return this.DiffManager.getDocumentBeforeVersion
|
|
|
|
.calledWith(this.project_id, this.doc_id, this.version)
|
|
|
|
.should.equal(true);
|
|
|
|
});
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-02-17 12:34:50 -05:00
|
|
|
it("should set the document in the document updater", function() {
|
|
|
|
return this.DocumentUpdaterManager.setDocument
|
|
|
|
.calledWith(this.project_id, this.doc_id, this.content, this.user_id)
|
|
|
|
.should.equal(true);
|
|
|
|
});
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-02-17 12:34:50 -05:00
|
|
|
return it("should call the callback", function() {
|
|
|
|
return this.callback.called.should.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-03-10 12:58:26 -04:00
|
|
|
|