mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
decaffeinate: rename test/unit/coffee to test/unit/js
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
/* eslint-disable
|
||||
camelcase,
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS101: Remove unnecessary use of Array.from
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS206: Consider reworking classes to avoid initClass
|
||||
* 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 modulePath = "../../../../app/js/ProjectManager.js";
|
||||
const SandboxedModule = require('sandboxed-module');
|
||||
|
||||
describe("ProjectManager - flushAndDeleteProject", function() {
|
||||
beforeEach(function() {
|
||||
let Timer;
|
||||
this.ProjectManager = SandboxedModule.require(modulePath, { requires: {
|
||||
"./RedisManager": (this.RedisManager = {}),
|
||||
"./ProjectHistoryRedisManager": (this.ProjectHistoryRedisManager = {}),
|
||||
"./DocumentManager": (this.DocumentManager = {}),
|
||||
"logger-sharelatex": (this.logger = { log: sinon.stub(), error: sinon.stub() }),
|
||||
"./HistoryManager": (this.HistoryManager =
|
||||
{flushProjectChanges: sinon.stub().callsArg(2)}),
|
||||
"./Metrics": (this.Metrics = {
|
||||
Timer: (Timer = (function() {
|
||||
Timer = class Timer {
|
||||
static initClass() {
|
||||
this.prototype.done = sinon.stub();
|
||||
}
|
||||
};
|
||||
Timer.initClass();
|
||||
return Timer;
|
||||
})())
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
this.project_id = "project-id-123";
|
||||
return this.callback = sinon.stub();
|
||||
});
|
||||
|
||||
describe("successfully", function() {
|
||||
beforeEach(function(done) {
|
||||
this.doc_ids = ["doc-id-1", "doc-id-2", "doc-id-3"];
|
||||
this.RedisManager.getDocIdsInProject = sinon.stub().callsArgWith(1, null, this.doc_ids);
|
||||
this.DocumentManager.flushAndDeleteDocWithLock = sinon.stub().callsArg(3);
|
||||
return this.ProjectManager.flushAndDeleteProjectWithLocks(this.project_id, {}, error => {
|
||||
this.callback(error);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should get the doc ids in the project", function() {
|
||||
return this.RedisManager.getDocIdsInProject
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should delete each doc in the project", function() {
|
||||
return Array.from(this.doc_ids).map((doc_id) =>
|
||||
this.DocumentManager.flushAndDeleteDocWithLock
|
||||
.calledWith(this.project_id, doc_id, {})
|
||||
.should.equal(true));
|
||||
});
|
||||
|
||||
it("should flush project history", function() {
|
||||
return this.HistoryManager.flushProjectChanges
|
||||
.calledWith(this.project_id, {})
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should call the callback without error", function() {
|
||||
return this.callback.calledWith(null).should.equal(true);
|
||||
});
|
||||
|
||||
return it("should time the execution", function() {
|
||||
return this.Metrics.Timer.prototype.done.called.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
return describe("when a doc errors", function() {
|
||||
beforeEach(function(done) {
|
||||
this.doc_ids = ["doc-id-1", "doc-id-2", "doc-id-3"];
|
||||
this.RedisManager.getDocIdsInProject = sinon.stub().callsArgWith(1, null, this.doc_ids);
|
||||
this.DocumentManager.flushAndDeleteDocWithLock = sinon.spy((project_id, doc_id, options, callback) => {
|
||||
if (doc_id === "doc-id-1") {
|
||||
return callback(this.error = new Error("oops, something went wrong"));
|
||||
} else {
|
||||
return callback();
|
||||
}
|
||||
});
|
||||
return this.ProjectManager.flushAndDeleteProjectWithLocks(this.project_id, {}, error => {
|
||||
this.callback(error);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should still flush each doc in the project", function() {
|
||||
return Array.from(this.doc_ids).map((doc_id) =>
|
||||
this.DocumentManager.flushAndDeleteDocWithLock
|
||||
.calledWith(this.project_id, doc_id, {})
|
||||
.should.equal(true));
|
||||
});
|
||||
|
||||
it("should still flush project history", function() {
|
||||
return this.HistoryManager.flushProjectChanges
|
||||
.calledWith(this.project_id, {})
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should record the error", function() {
|
||||
return this.logger.error
|
||||
.calledWith({err: this.error, project_id: this.project_id, doc_id: "doc-id-1"}, "error deleting doc")
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should call the callback with an error", function() {
|
||||
return this.callback.calledWith(new Error()).should.equal(true);
|
||||
});
|
||||
|
||||
return it("should time the execution", function() {
|
||||
return this.Metrics.Timer.prototype.done.called.should.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,122 @@
|
||||
/* eslint-disable
|
||||
camelcase,
|
||||
handle-callback-err,
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS101: Remove unnecessary use of Array.from
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS206: Consider reworking classes to avoid initClass
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* 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 modulePath = "../../../../app/js/ProjectManager.js";
|
||||
const SandboxedModule = require('sandboxed-module');
|
||||
|
||||
describe("ProjectManager - flushProject", function() {
|
||||
beforeEach(function() {
|
||||
let Timer;
|
||||
this.ProjectManager = SandboxedModule.require(modulePath, { requires: {
|
||||
"./RedisManager": (this.RedisManager = {}),
|
||||
"./ProjectHistoryRedisManager": (this.ProjectHistoryRedisManager = {}),
|
||||
"./DocumentManager": (this.DocumentManager = {}),
|
||||
"logger-sharelatex": (this.logger = { log: sinon.stub(), error: sinon.stub() }),
|
||||
"./HistoryManager": (this.HistoryManager = {}),
|
||||
"./Metrics": (this.Metrics = {
|
||||
Timer: (Timer = (function() {
|
||||
Timer = class Timer {
|
||||
static initClass() {
|
||||
this.prototype.done = sinon.stub();
|
||||
}
|
||||
};
|
||||
Timer.initClass();
|
||||
return Timer;
|
||||
})())
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
this.project_id = "project-id-123";
|
||||
return this.callback = sinon.stub();
|
||||
});
|
||||
|
||||
describe("successfully", function() {
|
||||
beforeEach(function(done) {
|
||||
this.doc_ids = ["doc-id-1", "doc-id-2", "doc-id-3"];
|
||||
this.RedisManager.getDocIdsInProject = sinon.stub().callsArgWith(1, null, this.doc_ids);
|
||||
this.DocumentManager.flushDocIfLoadedWithLock = sinon.stub().callsArg(2);
|
||||
return this.ProjectManager.flushProjectWithLocks(this.project_id, error => {
|
||||
this.callback(error);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should get the doc ids in the project", function() {
|
||||
return this.RedisManager.getDocIdsInProject
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should flush each doc in the project", function() {
|
||||
return Array.from(this.doc_ids).map((doc_id) =>
|
||||
this.DocumentManager.flushDocIfLoadedWithLock
|
||||
.calledWith(this.project_id, doc_id)
|
||||
.should.equal(true));
|
||||
});
|
||||
|
||||
it("should call the callback without error", function() {
|
||||
return this.callback.calledWith(null).should.equal(true);
|
||||
});
|
||||
|
||||
return it("should time the execution", function() {
|
||||
return this.Metrics.Timer.prototype.done.called.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
return describe("when a doc errors", function() {
|
||||
beforeEach(function(done) {
|
||||
this.doc_ids = ["doc-id-1", "doc-id-2", "doc-id-3"];
|
||||
this.RedisManager.getDocIdsInProject = sinon.stub().callsArgWith(1, null, this.doc_ids);
|
||||
this.DocumentManager.flushDocIfLoadedWithLock = sinon.spy((project_id, doc_id, callback) => {
|
||||
if (callback == null) { callback = function(error) {}; }
|
||||
if (doc_id === "doc-id-1") {
|
||||
return callback(this.error = new Error("oops, something went wrong"));
|
||||
} else {
|
||||
return callback();
|
||||
}
|
||||
});
|
||||
return this.ProjectManager.flushProjectWithLocks(this.project_id, error => {
|
||||
this.callback(error);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should still flush each doc in the project", function() {
|
||||
return Array.from(this.doc_ids).map((doc_id) =>
|
||||
this.DocumentManager.flushDocIfLoadedWithLock
|
||||
.calledWith(this.project_id, doc_id)
|
||||
.should.equal(true));
|
||||
});
|
||||
|
||||
it("should record the error", function() {
|
||||
return this.logger.error
|
||||
.calledWith({err: this.error, project_id: this.project_id, doc_id: "doc-id-1"}, "error flushing doc")
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should call the callback with an error", function() {
|
||||
return this.callback.calledWith(new Error()).should.equal(true);
|
||||
});
|
||||
|
||||
return it("should time the execution", function() {
|
||||
return this.Metrics.Timer.prototype.done.called.should.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,167 @@
|
||||
/* eslint-disable
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS206: Consider reworking classes to avoid initClass
|
||||
* 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 modulePath = "../../../../app/js/ProjectManager.js";
|
||||
const SandboxedModule = require('sandboxed-module');
|
||||
const Errors = require("../../../../app/js/Errors.js");
|
||||
|
||||
describe("ProjectManager - getProjectDocsAndFlushIfOld", function() {
|
||||
beforeEach(function() {
|
||||
let Timer;
|
||||
this.ProjectManager = SandboxedModule.require(modulePath, { requires: {
|
||||
"./RedisManager": (this.RedisManager = {}),
|
||||
"./ProjectHistoryRedisManager": (this.ProjectHistoryRedisManager = {}),
|
||||
"./DocumentManager": (this.DocumentManager = {}),
|
||||
"logger-sharelatex": (this.logger = { log: sinon.stub(), error: sinon.stub() }),
|
||||
"./HistoryManager": (this.HistoryManager = {}),
|
||||
"./Metrics": (this.Metrics = {
|
||||
Timer: (Timer = (function() {
|
||||
Timer = class Timer {
|
||||
static initClass() {
|
||||
this.prototype.done = sinon.stub();
|
||||
}
|
||||
};
|
||||
Timer.initClass();
|
||||
return Timer;
|
||||
})())
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
this.project_id = "project-id-123";
|
||||
this.callback = sinon.stub();
|
||||
return this.doc_versions = [111, 222, 333];});
|
||||
|
||||
describe("successfully", function() {
|
||||
beforeEach(function(done) {
|
||||
this.doc_ids = ["doc-id-1", "doc-id-2", "doc-id-3"];
|
||||
this.doc_lines = [["aaa","aaa"],["bbb","bbb"],["ccc","ccc"]];
|
||||
this.docs = [
|
||||
{_id: this.doc_ids[0], lines: this.doc_lines[0], v: this.doc_versions[0]},
|
||||
{_id: this.doc_ids[1], lines: this.doc_lines[1], v: this.doc_versions[1]},
|
||||
{_id: this.doc_ids[2], lines: this.doc_lines[2], v: this.doc_versions[2]}
|
||||
];
|
||||
this.RedisManager.checkOrSetProjectState = sinon.stub().callsArgWith(2, null);
|
||||
this.RedisManager.getDocIdsInProject = sinon.stub().callsArgWith(1, null, this.doc_ids);
|
||||
this.DocumentManager.getDocAndFlushIfOldWithLock = sinon.stub();
|
||||
this.DocumentManager.getDocAndFlushIfOldWithLock.withArgs(this.project_id, this.doc_ids[0])
|
||||
.callsArgWith(2, null, this.doc_lines[0], this.doc_versions[0]);
|
||||
this.DocumentManager.getDocAndFlushIfOldWithLock.withArgs(this.project_id, this.doc_ids[1])
|
||||
.callsArgWith(2, null, this.doc_lines[1], this.doc_versions[1]);
|
||||
this.DocumentManager.getDocAndFlushIfOldWithLock.withArgs(this.project_id, this.doc_ids[2])
|
||||
.callsArgWith(2, null, this.doc_lines[2], this.doc_versions[2]);
|
||||
return this.ProjectManager.getProjectDocsAndFlushIfOld(this.project_id, this.projectStateHash, this.excludeVersions, (error, docs) => {
|
||||
this.callback(error, docs);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should check the project state", function() {
|
||||
return this.RedisManager.checkOrSetProjectState
|
||||
.calledWith(this.project_id, this.projectStateHash)
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should get the doc ids in the project", function() {
|
||||
return this.RedisManager.getDocIdsInProject
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should call the callback without error", function() {
|
||||
return this.callback.calledWith(null, this.docs).should.equal(true);
|
||||
});
|
||||
|
||||
return it("should time the execution", function() {
|
||||
return this.Metrics.Timer.prototype.done.called.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when the state does not match", function() {
|
||||
beforeEach(function(done) {
|
||||
this.doc_ids = ["doc-id-1", "doc-id-2", "doc-id-3"];
|
||||
this.RedisManager.checkOrSetProjectState = sinon.stub().callsArgWith(2, null, true);
|
||||
return this.ProjectManager.getProjectDocsAndFlushIfOld(this.project_id, this.projectStateHash, this.excludeVersions, (error, docs) => {
|
||||
this.callback(error, docs);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should check the project state", function() {
|
||||
return this.RedisManager.checkOrSetProjectState
|
||||
.calledWith(this.project_id, this.projectStateHash)
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should call the callback with an error", function() {
|
||||
return this.callback.calledWith(new Errors.ProjectStateChangedError("project state changed")).should.equal(true);
|
||||
});
|
||||
|
||||
return it("should time the execution", function() {
|
||||
return this.Metrics.Timer.prototype.done.called.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when a doc errors", function() {
|
||||
beforeEach(function(done) {
|
||||
this.doc_ids = ["doc-id-1", "doc-id-2", "doc-id-3"];
|
||||
this.RedisManager.checkOrSetProjectState = sinon.stub().callsArgWith(2, null);
|
||||
this.RedisManager.getDocIdsInProject = sinon.stub().callsArgWith(1, null, this.doc_ids);
|
||||
this.DocumentManager.getDocAndFlushIfOldWithLock = sinon.stub();
|
||||
this.DocumentManager.getDocAndFlushIfOldWithLock.withArgs(this.project_id, "doc-id-1")
|
||||
.callsArgWith(2, null, ["test doc content"], this.doc_versions[1]);
|
||||
this.DocumentManager.getDocAndFlushIfOldWithLock.withArgs(this.project_id, "doc-id-2")
|
||||
.callsArgWith(2, (this.error = new Error("oops"))); // trigger an error
|
||||
return this.ProjectManager.getProjectDocsAndFlushIfOld(this.project_id, this.projectStateHash, this.excludeVersions, (error, docs) => {
|
||||
this.callback(error);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should record the error", function() {
|
||||
return this.logger.error
|
||||
.calledWith({err: this.error, project_id: this.project_id, doc_id: "doc-id-2"}, "error getting project doc lines in getProjectDocsAndFlushIfOld")
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should call the callback with an error", function() {
|
||||
return this.callback.calledWith(new Error("oops")).should.equal(true);
|
||||
});
|
||||
|
||||
return it("should time the execution", function() {
|
||||
return this.Metrics.Timer.prototype.done.called.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
return describe("clearing the project state with clearProjectState", function() {
|
||||
beforeEach(function(done) {
|
||||
this.RedisManager.clearProjectState = sinon.stub().callsArg(1);
|
||||
return this.ProjectManager.clearProjectState(this.project_id, error => {
|
||||
this.callback(error);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should clear the project state", function() {
|
||||
return this.RedisManager.clearProjectState
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
return it("should call the callback", function() {
|
||||
return this.callback.called.should.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,248 @@
|
||||
/* eslint-disable
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS206: Consider reworking classes to avoid initClass
|
||||
* 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 modulePath = "../../../../app/js/ProjectManager.js";
|
||||
const SandboxedModule = require('sandboxed-module');
|
||||
const _ = require('lodash');
|
||||
|
||||
describe("ProjectManager", function() {
|
||||
beforeEach(function() {
|
||||
let Timer;
|
||||
this.ProjectManager = SandboxedModule.require(modulePath, { requires: {
|
||||
"./RedisManager": (this.RedisManager = {}),
|
||||
"./ProjectHistoryRedisManager": (this.ProjectHistoryRedisManager = {}),
|
||||
"./DocumentManager": (this.DocumentManager = {}),
|
||||
"logger-sharelatex": (this.logger = { log: sinon.stub(), error: sinon.stub() }),
|
||||
"./HistoryManager": (this.HistoryManager = {}),
|
||||
"./Metrics": (this.Metrics = {
|
||||
Timer: (Timer = (function() {
|
||||
Timer = class Timer {
|
||||
static initClass() {
|
||||
this.prototype.done = sinon.stub();
|
||||
}
|
||||
};
|
||||
Timer.initClass();
|
||||
return Timer;
|
||||
})())
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
this.project_id = "project-id-123";
|
||||
this.projectHistoryId = 'history-id-123';
|
||||
this.user_id = "user-id-123";
|
||||
this.version = 1234567;
|
||||
this.HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(false);
|
||||
this.HistoryManager.flushProjectChangesAsync = sinon.stub();
|
||||
return this.callback = sinon.stub();
|
||||
});
|
||||
|
||||
return describe("updateProjectWithLocks", function() {
|
||||
describe("rename operations", function() {
|
||||
beforeEach(function() {
|
||||
this.firstDocUpdate = {
|
||||
id: 1,
|
||||
pathname: 'foo',
|
||||
newPathname: 'foo'
|
||||
};
|
||||
this.secondDocUpdate = {
|
||||
id: 2,
|
||||
pathname: 'bar',
|
||||
newPathname: 'bar2'
|
||||
};
|
||||
this.docUpdates = [ this.firstDocUpdate, this.secondDocUpdate ];
|
||||
this.firstFileUpdate = {
|
||||
id: 2,
|
||||
pathname: 'bar',
|
||||
newPathname: 'bar2'
|
||||
};
|
||||
this.fileUpdates = [ this.firstFileUpdate ];
|
||||
this.DocumentManager.renameDocWithLock = sinon.stub().yields();
|
||||
return this.ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields();
|
||||
});
|
||||
|
||||
describe("successfully", function() {
|
||||
beforeEach(function() {
|
||||
return this.ProjectManager.updateProjectWithLocks(this.project_id, this.projectHistoryId, this.user_id, this.docUpdates, this.fileUpdates, this.version, this.callback);
|
||||
});
|
||||
|
||||
it("should rename the docs in the updates", function() {
|
||||
const firstDocUpdateWithVersion = _.extend({}, this.firstDocUpdate, {version: `${this.version}.0`});
|
||||
const secondDocUpdateWithVersion = _.extend({}, this.secondDocUpdate, {version: `${this.version}.1`});
|
||||
this.DocumentManager.renameDocWithLock
|
||||
.calledWith(this.project_id, this.firstDocUpdate.id, this.user_id, firstDocUpdateWithVersion, this.projectHistoryId)
|
||||
.should.equal(true);
|
||||
return this.DocumentManager.renameDocWithLock
|
||||
.calledWith(this.project_id, this.secondDocUpdate.id, this.user_id, secondDocUpdateWithVersion, this.projectHistoryId)
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should rename the files in the updates", function() {
|
||||
const firstFileUpdateWithVersion = _.extend({}, this.firstFileUpdate, {version: `${this.version}.2`});
|
||||
return this.ProjectHistoryRedisManager.queueRenameEntity
|
||||
.calledWith(this.project_id, this.projectHistoryId, 'file', this.firstFileUpdate.id, this.user_id, firstFileUpdateWithVersion)
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should not flush the history", function() {
|
||||
return this.HistoryManager.flushProjectChangesAsync
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(false);
|
||||
});
|
||||
|
||||
return it("should call the callback", function() {
|
||||
return this.callback.called.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when renaming a doc fails", function() {
|
||||
beforeEach(function() {
|
||||
this.error = new Error('error');
|
||||
this.DocumentManager.renameDocWithLock = sinon.stub().yields(this.error);
|
||||
return this.ProjectManager.updateProjectWithLocks(this.project_id, this.projectHistoryId, this.user_id, this.docUpdates, this.fileUpdates, this.version, this.callback);
|
||||
});
|
||||
|
||||
return it("should call the callback with the error", function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when renaming a file fails", function() {
|
||||
beforeEach(function() {
|
||||
this.error = new Error('error');
|
||||
this.ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields(this.error);
|
||||
return this.ProjectManager.updateProjectWithLocks(this.project_id, this.projectHistoryId, this.user_id, this.docUpdates, this.fileUpdates, this.version, this.callback);
|
||||
});
|
||||
|
||||
return it("should call the callback with the error", function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
return describe("with enough ops to flush", function() {
|
||||
beforeEach(function() {
|
||||
this.HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true);
|
||||
return this.ProjectManager.updateProjectWithLocks(this.project_id, this.projectHistoryId, this.user_id, this.docUpdates, this.fileUpdates, this.version, this.callback);
|
||||
});
|
||||
|
||||
return it("should flush the history", function() {
|
||||
return this.HistoryManager.flushProjectChangesAsync
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return describe("add operations", function() {
|
||||
beforeEach(function() {
|
||||
this.firstDocUpdate = {
|
||||
id: 1,
|
||||
docLines: "a\nb"
|
||||
};
|
||||
this.secondDocUpdate = {
|
||||
id: 2,
|
||||
docLines: "a\nb"
|
||||
};
|
||||
this.docUpdates = [ this.firstDocUpdate, this.secondDocUpdate ];
|
||||
this.firstFileUpdate = {
|
||||
id: 3,
|
||||
url: 'filestore.example.com/2'
|
||||
};
|
||||
this.secondFileUpdate = {
|
||||
id: 4,
|
||||
url: 'filestore.example.com/3'
|
||||
};
|
||||
this.fileUpdates = [ this.firstFileUpdate, this.secondFileUpdate ];
|
||||
return this.ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields();
|
||||
});
|
||||
|
||||
describe("successfully", function() {
|
||||
beforeEach(function() {
|
||||
return this.ProjectManager.updateProjectWithLocks(this.project_id, this.projectHistoryId, this.user_id, this.docUpdates, this.fileUpdates, this.version, this.callback);
|
||||
});
|
||||
|
||||
it("should add the docs in the updates", function() {
|
||||
const firstDocUpdateWithVersion = _.extend({}, this.firstDocUpdate, {version: `${this.version}.0`});
|
||||
const secondDocUpdateWithVersion = _.extend({}, this.secondDocUpdate, {version: `${this.version}.1`});
|
||||
this.ProjectHistoryRedisManager.queueAddEntity.getCall(0)
|
||||
.calledWith(this.project_id, this.projectHistoryId, 'doc', this.firstDocUpdate.id, this.user_id, firstDocUpdateWithVersion)
|
||||
.should.equal(true);
|
||||
return this.ProjectHistoryRedisManager.queueAddEntity.getCall(1)
|
||||
.calledWith(this.project_id, this.projectHistoryId, 'doc', this.secondDocUpdate.id, this.user_id, secondDocUpdateWithVersion)
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should add the files in the updates", function() {
|
||||
const firstFileUpdateWithVersion = _.extend({}, this.firstFileUpdate, {version: `${this.version}.2`});
|
||||
const secondFileUpdateWithVersion = _.extend({}, this.secondFileUpdate, {version: `${this.version}.3`});
|
||||
this.ProjectHistoryRedisManager.queueAddEntity.getCall(2)
|
||||
.calledWith(this.project_id, this.projectHistoryId, 'file', this.firstFileUpdate.id, this.user_id, firstFileUpdateWithVersion)
|
||||
.should.equal(true);
|
||||
return this.ProjectHistoryRedisManager.queueAddEntity.getCall(3)
|
||||
.calledWith(this.project_id, this.projectHistoryId, 'file', this.secondFileUpdate.id, this.user_id, secondFileUpdateWithVersion)
|
||||
.should.equal(true);
|
||||
});
|
||||
|
||||
it("should not flush the history", function() {
|
||||
return this.HistoryManager.flushProjectChangesAsync
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(false);
|
||||
});
|
||||
|
||||
return it("should call the callback", function() {
|
||||
return this.callback.called.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when adding a doc fails", function() {
|
||||
beforeEach(function() {
|
||||
this.error = new Error('error');
|
||||
this.ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(this.error);
|
||||
return this.ProjectManager.updateProjectWithLocks(this.project_id, this.projectHistoryId, this.user_id, this.docUpdates, this.fileUpdates, this.version, this.callback);
|
||||
});
|
||||
|
||||
return it("should call the callback with the error", function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when adding a file fails", function() {
|
||||
beforeEach(function() {
|
||||
this.error = new Error('error');
|
||||
this.ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(this.error);
|
||||
return this.ProjectManager.updateProjectWithLocks(this.project_id, this.projectHistoryId, this.user_id, this.docUpdates, this.fileUpdates, this.version, this.callback);
|
||||
});
|
||||
|
||||
return it("should call the callback with the error", function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
return describe("with enough ops to flush", function() {
|
||||
beforeEach(function() {
|
||||
this.HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true);
|
||||
return this.ProjectManager.updateProjectWithLocks(this.project_id, this.projectHistoryId, this.user_id, this.docUpdates, this.fileUpdates, this.version, this.callback);
|
||||
});
|
||||
|
||||
return it("should flush the history", function() {
|
||||
return this.HistoryManager.flushProjectChangesAsync
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user