decaffeinate: Run post-processing cleanups on ApplyingUpdatesToADocTests.coffee and 14 other files

This commit is contained in:
decaffeinate 2020-05-06 12:12:36 +02:00 committed by Tim Alby
parent adffde3059
commit 24ac4d4935
15 changed files with 175 additions and 82 deletions

View file

@ -1,3 +1,9 @@
/* eslint-disable
camelcase,
handle-callback-err,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from * DS101: Remove unnecessary use of Array.from
@ -47,14 +53,14 @@ describe("Applying updates to a doc", function() {
sinon.spy(MockWebApi, "getDocument"); sinon.spy(MockWebApi, "getDocument");
this.startTime = Date.now(); this.startTime = Date.now();
MockWebApi.insertDoc(this.project_id, this.doc_id, {lines: this.lines, version: this.version}); MockWebApi.insertDoc(this.project_id, this.doc_id, {lines: this.lines, version: this.version});
DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, this.update, function(error) { DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, this.update, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
return null; return null;
}); });
after(() => MockWebApi.getDocument.restore()); after(function() { return MockWebApi.getDocument.restore(); });
it("should load the document from the web API", function() { it("should load the document from the web API", function() {
return MockWebApi.getDocument return MockWebApi.getDocument
@ -107,7 +113,7 @@ describe("Applying updates to a doc", function() {
this.timeout = 10000; this.timeout = 10000;
this.second_update = Object.create(this.update); this.second_update = Object.create(this.update);
this.second_update.v = this.version + 1; this.second_update.v = this.version + 1;
DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, this.second_update, function(error) { DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, this.second_update, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -133,7 +139,7 @@ describe("Applying updates to a doc", function() {
DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, error => { DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, error => {
if (error != null) { throw error; } if (error != null) { throw error; }
sinon.spy(MockWebApi, "getDocument"); sinon.spy(MockWebApi, "getDocument");
return DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, this.update, function(error) { return DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, this.update, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -141,9 +147,9 @@ describe("Applying updates to a doc", function() {
return null; return null;
}); });
after(() => MockWebApi.getDocument.restore()); after(function() { return MockWebApi.getDocument.restore(); });
it("should not need to call the web api", () => MockWebApi.getDocument.called.should.equal(false)); it("should not need to call the web api", function() { return MockWebApi.getDocument.called.should.equal(false); });
it("should update the doc", function(done) { it("should update the doc", function(done) {
DocUpdaterClient.getDoc(this.project_id, this.doc_id, (error, res, doc) => { DocUpdaterClient.getDoc(this.project_id, this.doc_id, (error, res, doc) => {
@ -181,7 +187,7 @@ describe("Applying updates to a doc", function() {
DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, error => { DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, error => {
if (error != null) { throw error; } if (error != null) { throw error; }
sinon.spy(MockWebApi, "getDocument"); sinon.spy(MockWebApi, "getDocument");
return DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, this.update, function(error) { return DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, this.update, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -189,7 +195,7 @@ describe("Applying updates to a doc", function() {
return null; return null;
}); });
after(() => MockWebApi.getDocument.restore()); after(function() { return MockWebApi.getDocument.restore(); });
it("should update the doc", function(done) { it("should update the doc", function(done) {
DocUpdaterClient.getDoc(this.project_id, this.doc_id, (error, res, doc) => { DocUpdaterClient.getDoc(this.project_id, this.doc_id, (error, res, doc) => {
@ -345,7 +351,7 @@ describe("Applying updates to a doc", function() {
DocUpdaterClient.subscribeToAppliedOps(this.messageCallback = sinon.stub()); DocUpdaterClient.subscribeToAppliedOps(this.messageCallback = sinon.stub());
DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, this.broken_update, function(error) { DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, this.broken_update, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -404,9 +410,9 @@ describe("Applying updates to a doc", function() {
return null; return null;
}); });
after(() => MockTrackChangesApi.flushDoc.restore()); after(function() { return MockTrackChangesApi.flushDoc.restore(); });
return it("should flush the doc twice", () => MockTrackChangesApi.flushDoc.calledTwice.should.equal(true)); return it("should flush the doc twice", function() { return MockTrackChangesApi.flushDoc.calledTwice.should.equal(true); });
}); });
describe("when there is no version in Mongo", function() { describe("when there is no version in Mongo", function() {
@ -421,7 +427,7 @@ describe("Applying updates to a doc", function() {
op: this.update.op, op: this.update.op,
v: 0 v: 0
}; };
DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, update, function(error) { DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, update, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });

View file

@ -1,3 +1,10 @@
/* eslint-disable
camelcase,
handle-callback-err,
no-return-assign,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
@ -33,7 +40,7 @@ describe("Applying updates to a project's structure", function() {
this.fileUpdates = [ this.fileUpdate ]; this.fileUpdates = [ this.fileUpdate ];
return DocUpdaterApp.ensureRunning(error => { return DocUpdaterApp.ensureRunning(error => {
if (error != null) { throw error; } if (error != null) { throw error; }
return DocUpdaterClient.sendProjectUpdate(this.project_id, this.user_id, [], this.fileUpdates, this.version, function(error) { return DocUpdaterClient.sendProjectUpdate(this.project_id, this.user_id, [], this.fileUpdates, this.version, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -70,7 +77,7 @@ describe("Applying updates to a project's structure", function() {
describe("when the document is not loaded", function() { describe("when the document is not loaded", function() {
before(function(done) { before(function(done) {
this.project_id = DocUpdaterClient.randomId(); this.project_id = DocUpdaterClient.randomId();
DocUpdaterClient.sendProjectUpdate(this.project_id, this.user_id, this.docUpdates, [], this.version, function(error) { DocUpdaterClient.sendProjectUpdate(this.project_id, this.user_id, this.docUpdates, [], this.version, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -102,7 +109,7 @@ describe("Applying updates to a project's structure", function() {
DocUpdaterClient.preloadDoc(this.project_id, this.docUpdate.id, error => { DocUpdaterClient.preloadDoc(this.project_id, this.docUpdate.id, error => {
if (error != null) { throw error; } if (error != null) { throw error; }
sinon.spy(MockWebApi, "getDocument"); sinon.spy(MockWebApi, "getDocument");
return DocUpdaterClient.sendProjectUpdate(this.project_id, this.user_id, this.docUpdates, [], this.version, function(error) { return DocUpdaterClient.sendProjectUpdate(this.project_id, this.user_id, this.docUpdates, [], this.version, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -110,7 +117,7 @@ describe("Applying updates to a project's structure", function() {
return null; return null;
}); });
after(() => MockWebApi.getDocument.restore()); after(function() { return MockWebApi.getDocument.restore(); });
it("should update the doc", function(done) { it("should update the doc", function(done) {
DocUpdaterClient.getDoc(this.project_id, this.docUpdate.id, (error, res, doc) => { DocUpdaterClient.getDoc(this.project_id, this.docUpdate.id, (error, res, doc) => {
@ -167,7 +174,7 @@ describe("Applying updates to a project's structure", function() {
return describe("when the documents are not loaded", function() { return describe("when the documents are not loaded", function() {
before(function(done) { before(function(done) {
this.project_id = DocUpdaterClient.randomId(); this.project_id = DocUpdaterClient.randomId();
DocUpdaterClient.sendProjectUpdate(this.project_id, this.user_id, this.docUpdates, this.fileUpdates, this.version, function(error) { DocUpdaterClient.sendProjectUpdate(this.project_id, this.user_id, this.docUpdates, this.fileUpdates, this.version, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -227,7 +234,7 @@ describe("Applying updates to a project's structure", function() {
url: 'filestore.example.com' url: 'filestore.example.com'
}; };
this.fileUpdates = [ this.fileUpdate ]; this.fileUpdates = [ this.fileUpdate ];
DocUpdaterClient.sendProjectUpdate(this.project_id, this.user_id, [], this.fileUpdates, this.version, function(error) { DocUpdaterClient.sendProjectUpdate(this.project_id, this.user_id, [], this.fileUpdates, this.version, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -261,7 +268,7 @@ describe("Applying updates to a project's structure", function() {
docLines: 'a\nb' docLines: 'a\nb'
}; };
this.docUpdates = [ this.docUpdate ]; this.docUpdates = [ this.docUpdate ];
DocUpdaterClient.sendProjectUpdate(this.project_id, this.user_id, this.docUpdates, [], this.version, function(error) { DocUpdaterClient.sendProjectUpdate(this.project_id, this.user_id, this.docUpdates, [], this.version, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -308,7 +315,7 @@ describe("Applying updates to a project's structure", function() {
const userId = this.project_id; const userId = this.project_id;
DocUpdaterClient.sendProjectUpdate(projectId, userId, updates.slice(0, 250), [], this.version0, function(error) { DocUpdaterClient.sendProjectUpdate(projectId, userId, updates.slice(0, 250), [], this.version0, function(error) {
if (error != null) { throw error; } if (error != null) { throw error; }
return DocUpdaterClient.sendProjectUpdate(projectId, userId, updates.slice(250), [], this.version1, function(error) { return DocUpdaterClient.sendProjectUpdate(projectId, userId, updates.slice(250), [], this.version1, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 2000); return setTimeout(done, 2000);
}); });
@ -316,7 +323,7 @@ describe("Applying updates to a project's structure", function() {
return null; return null;
}); });
after(() => MockProjectHistoryApi.flushProject.restore()); after(function() { return MockProjectHistoryApi.flushProject.restore(); });
return it("should flush project history", function() { return it("should flush project history", function() {
return MockProjectHistoryApi.flushProject.calledWith(this.project_id).should.equal(true); return MockProjectHistoryApi.flushProject.calledWith(this.project_id).should.equal(true);
@ -346,7 +353,7 @@ describe("Applying updates to a project's structure", function() {
const userId = this.project_id; const userId = this.project_id;
DocUpdaterClient.sendProjectUpdate(projectId, userId, updates.slice(0, 10), [], this.version0, function(error) { DocUpdaterClient.sendProjectUpdate(projectId, userId, updates.slice(0, 10), [], this.version0, function(error) {
if (error != null) { throw error; } if (error != null) { throw error; }
return DocUpdaterClient.sendProjectUpdate(projectId, userId, updates.slice(10), [], this.version1, function(error) { return DocUpdaterClient.sendProjectUpdate(projectId, userId, updates.slice(10), [], this.version1, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 2000); return setTimeout(done, 2000);
}); });
@ -354,7 +361,7 @@ describe("Applying updates to a project's structure", function() {
return null; return null;
}); });
after(() => MockProjectHistoryApi.flushProject.restore()); after(function() { return MockProjectHistoryApi.flushProject.restore(); });
return it("should not flush project history", function() { return it("should not flush project history", function() {
return MockProjectHistoryApi.flushProject.calledWith(this.project_id).should.equal(false); return MockProjectHistoryApi.flushProject.calledWith(this.project_id).should.equal(false);

View file

@ -1,3 +1,8 @@
/* eslint-disable
handle-callback-err,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from * DS101: Remove unnecessary use of Array.from
@ -118,7 +123,7 @@ describe("Deleting a document", function() {
return this.statusCode.should.equal(204); return this.statusCode.should.equal(204);
}); });
it("should not need to send the updated document to the web api", () => MockWebApi.setDocument.called.should.equal(false)); it("should not need to send the updated document to the web api", function() { return MockWebApi.setDocument.called.should.equal(false); });
it("should need to reload the doc if read again", function(done) { it("should need to reload the doc if read again", function(done) {
MockWebApi.getDocument.called.should.equal.false; MockWebApi.getDocument.called.should.equal.false;

View file

@ -1,3 +1,9 @@
/* eslint-disable
camelcase,
handle-callback-err,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from * DS101: Remove unnecessary use of Array.from
@ -45,7 +51,7 @@ describe("Deleting a project", function() {
}, },
updatedLines: ["four", "four and a half", "five", "six"] updatedLines: ["four", "four and a half", "five", "six"]
}]; }];
for (let doc of Array.from(this.docs)) { for (const doc of Array.from(this.docs)) {
MockWebApi.insertDoc(this.project_id, doc.id, { MockWebApi.insertDoc(this.project_id, doc.id, {
lines: doc.lines, lines: doc.lines,
version: doc.update.v version: doc.update.v
@ -110,7 +116,7 @@ describe("Deleting a project", function() {
return callback(); return callback();
}); });
}; };
}), function() { }), () => {
MockWebApi.getDocument.restore(); MockWebApi.getDocument.restore();
return done(); return done();
}); });
@ -158,11 +164,11 @@ describe("Deleting a project", function() {
return this.statusCode.should.equal(204); return this.statusCode.should.equal(204);
}); });
it("should not send any documents to the web api", () => MockWebApi.setDocument.called.should.equal(false)); it("should not send any documents to the web api", function() { return MockWebApi.setDocument.called.should.equal(false); });
it("should not flush any docs in track changes", () => MockTrackChangesApi.flushDoc.called.should.equal(false)); it("should not flush any docs in track changes", function() { return MockTrackChangesApi.flushDoc.called.should.equal(false); });
return it("should not flush to project history", () => MockProjectHistoryApi.flushProject.called.should.equal(false)); return it("should not flush to project history", function() { return MockProjectHistoryApi.flushProject.called.should.equal(false); });
}); });
return describe("with the background=true parameter from realtime and a request to flush the queue", function() { return describe("with the background=true parameter from realtime and a request to flush the queue", function() {
@ -211,7 +217,7 @@ describe("Deleting a project", function() {
MockTrackChangesApi.flushDoc.calledWith(doc.id).should.equal(true)); MockTrackChangesApi.flushDoc.calledWith(doc.id).should.equal(true));
}); });
return it("should flush to project history", () => MockProjectHistoryApi.flushProject.called.should.equal(true)); return it("should flush to project history", function() { return MockProjectHistoryApi.flushProject.called.should.equal(true); });
}); });
}); });

View file

@ -1,3 +1,9 @@
/* eslint-disable
camelcase,
handle-callback-err,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from * DS101: Remove unnecessary use of Array.from
@ -43,7 +49,7 @@ describe("Flushing a project", function() {
}, },
updatedLines: ["four", "four and a half", "five", "six"] updatedLines: ["four", "four and a half", "five", "six"]
}]; }];
for (let doc of Array.from(this.docs)) { for (const doc of Array.from(this.docs)) {
MockWebApi.insertDoc(this.project_id, doc.id, { MockWebApi.insertDoc(this.project_id, doc.id, {
lines: doc.lines, lines: doc.lines,
version: doc.update.v version: doc.update.v
@ -77,7 +83,7 @@ describe("Flushing a project", function() {
}); });
}); });
after(() => MockWebApi.setDocument.restore()); after(function() { return MockWebApi.setDocument.restore(); });
it("should return a 204 status code", function() { it("should return a 204 status code", function() {
return this.statusCode.should.equal(204); return this.statusCode.should.equal(204);

View file

@ -1,3 +1,11 @@
/* 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: * decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from * DS101: Remove unnecessary use of Array.from
@ -49,7 +57,7 @@ describe("Flushing a doc to Mongo", function() {
}); });
}); });
after(() => MockWebApi.setDocument.restore()); after(function() { return MockWebApi.setDocument.restore(); });
it("should flush the updated doc lines and version to the web api", function() { it("should flush the updated doc lines and version to the web api", function() {
return MockWebApi.setDocument return MockWebApi.setDocument
@ -76,9 +84,9 @@ describe("Flushing a doc to Mongo", function() {
return DocUpdaterClient.flushDoc(this.project_id, this.doc_id, done); return DocUpdaterClient.flushDoc(this.project_id, this.doc_id, done);
}); });
after(() => MockWebApi.setDocument.restore()); after(function() { return MockWebApi.setDocument.restore(); });
return it("should not flush the doc to the web api", () => MockWebApi.setDocument.called.should.equal(false)); return it("should not flush the doc to the web api", function() { return MockWebApi.setDocument.called.should.equal(false); });
}); });
return describe("when the web api http request takes a long time on first request", function() { return describe("when the web api http request takes a long time on first request", function() {
@ -89,7 +97,7 @@ describe("Flushing a doc to Mongo", function() {
version: this.version version: this.version
}); });
let t = 30000; let t = 30000;
sinon.stub(MockWebApi, "setDocument", function(project_id, doc_id, lines, version, ranges, lastUpdatedAt, lastUpdatedBy, callback) { sinon.stub(MockWebApi, "setDocument", (project_id, doc_id, lines, version, ranges, lastUpdatedAt, lastUpdatedBy, callback) => {
if (callback == null) { callback = function(error) {}; } if (callback == null) { callback = function(error) {}; }
setTimeout(callback, t); setTimeout(callback, t);
return t = 0; return t = 0;
@ -97,7 +105,7 @@ describe("Flushing a doc to Mongo", function() {
return DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, done); return DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, done);
}); });
after(() => MockWebApi.setDocument.restore()); after(function() { return MockWebApi.setDocument.restore(); });
return it("should still work", function(done) { return it("should still work", function(done) {
const start = Date.now(); const start = Date.now();

View file

@ -1,3 +1,9 @@
/* eslint-disable
camelcase,
handle-callback-err,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from * DS101: Remove unnecessary use of Array.from
@ -33,7 +39,7 @@ describe("Getting a document", function() {
return DocUpdaterClient.getDoc(this.project_id, this.doc_id, (error, res, returnedDoc) => { this.returnedDoc = returnedDoc; return done(); }); return DocUpdaterClient.getDoc(this.project_id, this.doc_id, (error, res, returnedDoc) => { this.returnedDoc = returnedDoc; return done(); });
}); });
after(() => MockWebApi.getDocument.restore()); after(function() { return MockWebApi.getDocument.restore(); });
it("should load the document from the web API", function() { it("should load the document from the web API", function() {
return MockWebApi.getDocument return MockWebApi.getDocument
@ -62,9 +68,9 @@ describe("Getting a document", function() {
}); });
}); });
after(() => MockWebApi.getDocument.restore()); after(function() { return MockWebApi.getDocument.restore(); });
it("should not load the document from the web API", () => MockWebApi.getDocument.called.should.equal(false)); it("should not load the document from the web API", function() { return MockWebApi.getDocument.called.should.equal(false); });
return it("should return the document lines", function() { return it("should return the document lines", function() {
return this.returnedDoc.lines.should.deep.equal(this.lines); return this.returnedDoc.lines.should.deep.equal(this.lines);
@ -91,7 +97,7 @@ describe("Getting a document", function() {
}); });
}); });
after(() => MockWebApi.getDocument.restore()); after(function() { return MockWebApi.getDocument.restore(); });
describe("when the ops are loaded", function() { describe("when the ops are loaded", function() {
before(function(done) { before(function(done) {
@ -134,7 +140,7 @@ describe("Getting a document", function() {
describe("when the web api returns an error", function() { describe("when the web api returns an error", function() {
before(function(done) { before(function(done) {
[this.project_id, this.doc_id] = Array.from([DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]); [this.project_id, this.doc_id] = Array.from([DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]);
sinon.stub(MockWebApi, "getDocument", function(project_id, doc_id, callback) { sinon.stub(MockWebApi, "getDocument", (project_id, doc_id, callback) => {
if (callback == null) { callback = function(error, doc) {}; } if (callback == null) { callback = function(error, doc) {}; }
return callback(new Error("oops")); return callback(new Error("oops"));
}); });
@ -144,7 +150,7 @@ describe("Getting a document", function() {
}); });
}); });
after(() => MockWebApi.getDocument.restore()); after(function() { return MockWebApi.getDocument.restore(); });
return it("should return 500", function() { return it("should return 500", function() {
return this.statusCode.should.equal(500); return this.statusCode.should.equal(500);
@ -155,14 +161,14 @@ describe("Getting a document", function() {
before(function(done) { before(function(done) {
this.timeout = 10000; this.timeout = 10000;
[this.project_id, this.doc_id] = Array.from([DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]); [this.project_id, this.doc_id] = Array.from([DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]);
sinon.stub(MockWebApi, "getDocument", function(project_id, doc_id, callback) { sinon.stub(MockWebApi, "getDocument", (project_id, doc_id, callback) => {
if (callback == null) { callback = function(error, doc) {}; } if (callback == null) { callback = function(error, doc) {}; }
return setTimeout(callback, 30000); return setTimeout(callback, 30000);
}); });
return done(); return done();
}); });
after(() => MockWebApi.getDocument.restore()); after(function() { return MockWebApi.getDocument.restore(); });
return it("should return quickly(ish)", function(done) { return it("should return quickly(ish)", function(done) {
const start = Date.now(); const start = Date.now();
@ -178,9 +184,9 @@ describe("Getting a document", function() {
function __range__(left, right, inclusive) { function __range__(left, right, inclusive) {
let range = []; const range = [];
let ascending = left < right; const ascending = left < right;
let end = !inclusive ? right : ascending ? right + 1 : right - 1; const end = !inclusive ? right : ascending ? right + 1 : right - 1;
for (let i = left; ascending ? i < end : i > end; ascending ? i++ : i--) { for (let i = left; ascending ? i < end : i > end; ascending ? i++ : i--) {
range.push(i); range.push(i);
} }

View file

@ -1,3 +1,9 @@
/* eslint-disable
handle-callback-err,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from * DS101: Remove unnecessary use of Array.from

View file

@ -1,3 +1,9 @@
/* eslint-disable
handle-callback-err,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from * DS101: Remove unnecessary use of Array.from
@ -19,7 +25,7 @@ const DocUpdaterClient = require("./helpers/DocUpdaterClient");
const DocUpdaterApp = require("./helpers/DocUpdaterApp"); const DocUpdaterApp = require("./helpers/DocUpdaterApp");
describe("Ranges", function() { describe("Ranges", function() {
before(done => DocUpdaterApp.ensureRunning(done)); before(function(done) { return DocUpdaterApp.ensureRunning(done); });
describe("tracking changes from ops", function() { describe("tracking changes from ops", function() {
before(function(done) { before(function(done) {
@ -51,7 +57,7 @@ describe("Ranges", function() {
version: 0 version: 0
}); });
const jobs = []; const jobs = [];
for (let update of Array.from(this.updates)) { for (const update of Array.from(this.updates)) {
(update => { (update => {
return jobs.push(callback => DocUpdaterClient.sendUpdate(this.project_id, this.doc.id, update, callback)); return jobs.push(callback => DocUpdaterClient.sendUpdate(this.project_id, this.doc.id, update, callback));
})(update); })(update);
@ -61,7 +67,7 @@ describe("Ranges", function() {
if (error != null) { throw error; } if (error != null) { throw error; }
return DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => { return DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
if (error != null) { throw error; } if (error != null) { throw error; }
return async.series(jobs, function(error) { return async.series(jobs, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return done(); return done();
}); });
@ -102,14 +108,14 @@ describe("Ranges", function() {
version: 0 version: 0
}); });
const jobs = []; const jobs = [];
for (let update of Array.from(this.updates)) { for (const update of Array.from(this.updates)) {
(update => { (update => {
return jobs.push(callback => DocUpdaterClient.sendUpdate(this.project_id, this.doc.id, update, callback)); return jobs.push(callback => DocUpdaterClient.sendUpdate(this.project_id, this.doc.id, update, callback));
})(update); })(update);
} }
return DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => { return DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
if (error != null) { throw error; } if (error != null) { throw error; }
return async.series(jobs, function(error) { return async.series(jobs, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -153,14 +159,14 @@ describe("Ranges", function() {
version: 0 version: 0
}); });
const jobs = []; const jobs = [];
for (let update of Array.from(this.updates)) { for (const update of Array.from(this.updates)) {
(update => { (update => {
return jobs.push(callback => DocUpdaterClient.sendUpdate(this.project_id, this.doc.id, update, callback)); return jobs.push(callback => DocUpdaterClient.sendUpdate(this.project_id, this.doc.id, update, callback));
})(update); })(update);
} }
return DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => { return DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
if (error != null) { throw error; } if (error != null) { throw error; }
return async.series(jobs, function(error) { return async.series(jobs, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -212,7 +218,7 @@ describe("Ranges", function() {
}); });
return DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => { return DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
if (error != null) { throw error; } if (error != null) { throw error; }
return DocUpdaterClient.sendUpdate(this.project_id, this.doc.id, this.update, function(error) { return DocUpdaterClient.sendUpdate(this.project_id, this.doc.id, this.update, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -367,14 +373,14 @@ describe("Ranges", function() {
version: 0 version: 0
}); });
const jobs = []; const jobs = [];
for (let update of Array.from(this.updates)) { for (const update of Array.from(this.updates)) {
(update => { (update => {
return jobs.push(callback => DocUpdaterClient.sendUpdate(this.project_id, this.doc.id, update, callback)); return jobs.push(callback => DocUpdaterClient.sendUpdate(this.project_id, this.doc.id, update, callback));
})(update); })(update);
} }
return DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => { return DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
if (error != null) { throw error; } if (error != null) { throw error; }
return async.series(jobs, function(error) { return async.series(jobs, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
return setTimeout(done, 200); return setTimeout(done, 200);
}); });
@ -423,7 +429,7 @@ describe("Ranges", function() {
meta: { user_id: this.user_id } meta: { user_id: this.user_id }
}]; }];
const jobs = []; const jobs = [];
for (let update of Array.from(this.updates)) { for (const update of Array.from(this.updates)) {
(update => { (update => {
return jobs.push(callback => DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, update, callback)); return jobs.push(callback => DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, update, callback));
})(update); })(update);

View file

@ -1,3 +1,10 @@
/* eslint-disable
camelcase,
handle-callback-err,
no-return-assign,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from * DS101: Remove unnecessary use of Array.from
@ -182,11 +189,11 @@ describe("Setting a document", function() {
return this.statusCode.should.equal(413); return this.statusCode.should.equal(413);
}); });
it("should not send the updated doc lines to the web api", () => MockWebApi.setDocument.called.should.equal(false)); it("should not send the updated doc lines to the web api", function() { return MockWebApi.setDocument.called.should.equal(false); });
it("should not flush track changes", () => MockTrackChangesApi.flushDoc.called.should.equal(false)); it("should not flush track changes", function() { return MockTrackChangesApi.flushDoc.called.should.equal(false); });
return it("should not flush project history", () => MockProjectHistoryApi.flushProject.called.should.equal(false)); return it("should not flush project history", function() { return MockProjectHistoryApi.flushProject.called.should.equal(false); });
}); });
describe("when the updated doc is large but under the bodyParser and HTTPController size limit", function() { describe("when the updated doc is large but under the bodyParser and HTTPController size limit", function() {

View file

@ -1,3 +1,8 @@
/* eslint-disable
handle-callback-err,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from * DS101: Remove unnecessary use of Array.from

View file

@ -1,3 +1,9 @@
/* eslint-disable
camelcase,
handle-callback-err,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from * DS101: Remove unnecessary use of Array.from
@ -30,10 +36,10 @@ module.exports = (DocUpdaterClient = {
sendUpdate(project_id, doc_id, update, callback) { sendUpdate(project_id, doc_id, update, callback) {
if (callback == null) { callback = function(error) {}; } if (callback == null) { callback = function(error) {}; }
return rclient.rpush(keys.pendingUpdates({doc_id}), JSON.stringify(update), function(error){ return rclient.rpush(keys.pendingUpdates({doc_id}), JSON.stringify(update), (error) => {
if (error != null) { return callback(error); } if (error != null) { return callback(error); }
const doc_key = `${project_id}:${doc_id}`; const doc_key = `${project_id}:${doc_id}`;
return rclient.sadd("DocsWithPendingUpdates", doc_key, function(error) { return rclient.sadd("DocsWithPendingUpdates", doc_key, (error) => {
if (error != null) { return callback(error); } if (error != null) { return callback(error); }
return rclient.rpush("pending-updates-list", doc_key, callback); return rclient.rpush("pending-updates-list", doc_key, callback);
}); });
@ -42,10 +48,10 @@ module.exports = (DocUpdaterClient = {
sendUpdates(project_id, doc_id, updates, callback) { sendUpdates(project_id, doc_id, updates, callback) {
if (callback == null) { callback = function(error) {}; } if (callback == null) { callback = function(error) {}; }
return DocUpdaterClient.preloadDoc(project_id, doc_id, function(error) { return DocUpdaterClient.preloadDoc(project_id, doc_id, (error) => {
if (error != null) { return callback(error); } if (error != null) { return callback(error); }
const jobs = []; const jobs = [];
for (let update of Array.from(updates)) { for (const update of Array.from(updates)) {
((update => jobs.push(callback => DocUpdaterClient.sendUpdate(project_id, doc_id, update, callback))))(update); ((update => jobs.push(callback => DocUpdaterClient.sendUpdate(project_id, doc_id, update, callback))))(update);
} }
return async.series(jobs, err => DocUpdaterClient.waitForPendingUpdates(project_id, doc_id, callback)); return async.series(jobs, err => DocUpdaterClient.waitForPendingUpdates(project_id, doc_id, callback));
@ -53,7 +59,7 @@ module.exports = (DocUpdaterClient = {
}, },
waitForPendingUpdates(project_id, doc_id, callback) { waitForPendingUpdates(project_id, doc_id, callback) {
return async.retry({times: 30, interval: 100}, cb => rclient.llen(keys.pendingUpdates({doc_id}), function(err, length) { return async.retry({times: 30, interval: 100}, cb => rclient.llen(keys.pendingUpdates({doc_id}), (err, length) => {
if (length > 0) { if (length > 0) {
return cb(new Error("updates still pending")); return cb(new Error("updates still pending"));
} else { } else {
@ -65,7 +71,7 @@ module.exports = (DocUpdaterClient = {
getDoc(project_id, doc_id, callback) { getDoc(project_id, doc_id, callback) {
if (callback == null) { callback = function(error, res, body) {}; } if (callback == null) { callback = function(error, res, body) {}; }
return request.get(`http://localhost:3003/project/${project_id}/doc/${doc_id}`, function(error, res, body) { return request.get(`http://localhost:3003/project/${project_id}/doc/${doc_id}`, (error, res, body) => {
if ((body != null) && (res.statusCode >= 200) && (res.statusCode < 300)) { if ((body != null) && (res.statusCode >= 200) && (res.statusCode < 300)) {
body = JSON.parse(body); body = JSON.parse(body);
} }
@ -75,7 +81,7 @@ module.exports = (DocUpdaterClient = {
getDocAndRecentOps(project_id, doc_id, fromVersion, callback) { getDocAndRecentOps(project_id, doc_id, fromVersion, callback) {
if (callback == null) { callback = function(error, res, body) {}; } if (callback == null) { callback = function(error, res, body) {}; }
return request.get(`http://localhost:3003/project/${project_id}/doc/${doc_id}?fromVersion=${fromVersion}`, function(error, res, body) { return request.get(`http://localhost:3003/project/${project_id}/doc/${doc_id}?fromVersion=${fromVersion}`, (error, res, body) => {
if ((body != null) && (res.statusCode >= 200) && (res.statusCode < 300)) { if ((body != null) && (res.statusCode >= 200) && (res.statusCode < 300)) {
body = JSON.parse(body); body = JSON.parse(body);
} }
@ -143,7 +149,7 @@ module.exports = (DocUpdaterClient = {
getProjectDocs(project_id, projectStateHash, callback) { getProjectDocs(project_id, projectStateHash, callback) {
if (callback == null) { callback = function() {}; } if (callback == null) { callback = function() {}; }
return request.get(`http://localhost:3003/project/${project_id}/doc?state=${projectStateHash}`, function(error, res, body) { return request.get(`http://localhost:3003/project/${project_id}/doc?state=${projectStateHash}`, (error, res, body) => {
if ((body != null) && (res.statusCode >= 200) && (res.statusCode < 300)) { if ((body != null) && (res.statusCode >= 200) && (res.statusCode < 300)) {
body = JSON.parse(body); body = JSON.parse(body);
} }
@ -161,9 +167,9 @@ module.exports = (DocUpdaterClient = {
}); });
function __range__(left, right, inclusive) { function __range__(left, right, inclusive) {
let range = []; const range = [];
let ascending = left < right; const ascending = left < right;
let end = !inclusive ? right : ascending ? right + 1 : right - 1; const end = !inclusive ? right : ascending ? right + 1 : right - 1;
for (let i = left; ascending ? i < end : i > end; ascending ? i++ : i--) { for (let i = left; ascending ? i < end : i > end; ascending ? i++ : i--) {
range.push(i); range.push(i);
} }

View file

@ -1,3 +1,9 @@
/* eslint-disable
camelcase,
handle-callback-err,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
@ -16,7 +22,7 @@ module.exports = (MockProjectHistoryApi = {
run() { run() {
app.post("/project/:project_id/flush", (req, res, next) => { app.post("/project/:project_id/flush", (req, res, next) => {
return this.flushProject(req.params.project_id, function(error) { return this.flushProject(req.params.project_id, (error) => {
if (error != null) { if (error != null) {
return res.sendStatus(500); return res.sendStatus(500);
} else { } else {
@ -25,7 +31,7 @@ module.exports = (MockProjectHistoryApi = {
}); });
}); });
return app.listen(3054, function(error) { return app.listen(3054, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
}); });
} }

View file

@ -1,3 +1,9 @@
/* eslint-disable
camelcase,
handle-callback-err,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
@ -16,7 +22,7 @@ module.exports = (MockTrackChangesApi = {
run() { run() {
app.post("/project/:project_id/doc/:doc_id/flush", (req, res, next) => { app.post("/project/:project_id/doc/:doc_id/flush", (req, res, next) => {
return this.flushDoc(req.params.doc_id, function(error) { return this.flushDoc(req.params.doc_id, (error) => {
if (error != null) { if (error != null) {
return res.sendStatus(500); return res.sendStatus(500);
} else { } else {
@ -25,9 +31,9 @@ module.exports = (MockTrackChangesApi = {
}); });
}); });
return app.listen(3015, function(error) { return app.listen(3015, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
}).on("error", function(error) { }).on("error", (error) => {
console.error("error starting MockTrackChangesApi:", error.message); console.error("error starting MockTrackChangesApi:", error.message);
return process.exit(1); return process.exit(1);
}); });

View file

@ -1,3 +1,10 @@
/* eslint-disable
camelcase,
handle-callback-err,
no-return-assign,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/* /*
* decaffeinate suggestions: * decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
@ -41,7 +48,7 @@ module.exports = (MockWebApi = {
run() { run() {
app.get("/project/:project_id/doc/:doc_id", (req, res, next) => { app.get("/project/:project_id/doc/:doc_id", (req, res, next) => {
return this.getDocument(req.params.project_id, req.params.doc_id, function(error, doc) { return this.getDocument(req.params.project_id, req.params.doc_id, (error, doc) => {
if (error != null) { if (error != null) {
return res.sendStatus(500); return res.sendStatus(500);
} else if (doc != null) { } else if (doc != null) {
@ -53,7 +60,7 @@ module.exports = (MockWebApi = {
}); });
app.post("/project/:project_id/doc/:doc_id", bodyParser.json({limit: MAX_REQUEST_SIZE}), (req, res, next) => { app.post("/project/:project_id/doc/:doc_id", bodyParser.json({limit: MAX_REQUEST_SIZE}), (req, res, next) => {
return MockWebApi.setDocument(req.params.project_id, req.params.doc_id, req.body.lines, req.body.version, req.body.ranges, req.body.lastUpdatedAt, req.body.lastUpdatedBy, function(error) { return MockWebApi.setDocument(req.params.project_id, req.params.doc_id, req.body.lines, req.body.version, req.body.ranges, req.body.lastUpdatedAt, req.body.lastUpdatedBy, (error) => {
if (error != null) { if (error != null) {
return res.sendStatus(500); return res.sendStatus(500);
} else { } else {
@ -62,9 +69,9 @@ module.exports = (MockWebApi = {
}); });
}); });
return app.listen(3000, function(error) { return app.listen(3000, (error) => {
if (error != null) { throw error; } if (error != null) { throw error; }
}).on("error", function(error) { }).on("error", (error) => {
console.error("error starting MockWebApi:", error.message); console.error("error starting MockWebApi:", error.message);
return process.exit(1); return process.exit(1);
}); });