prettier: convert test/unit decaffeinated files to Prettier format

This commit is contained in:
Tim Alby
2020-05-06 12:11:36 +02:00
parent bb20394243
commit 9a2f8ecbd4
24 changed files with 7979 additions and 5902 deletions
@@ -12,121 +12,146 @@
* 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 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('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();
});
});
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 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 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 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);
});
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 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();
});
});
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 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 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 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);
});
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);
});
});
});
return it('should time the execution', function () {
return this.Metrics.Timer.prototype.done.called.should.equal(true)
})
})
})