prettier auto-format

This commit is contained in:
Tim Alby
2020-05-28 15:20:54 +02:00
parent 9712f518bd
commit c854f1f570
20 changed files with 586 additions and 579 deletions
@@ -23,8 +23,8 @@ const { ObjectId } = require('mongojs')
const Errors = require('../../../app/js/Errors')
const crypto = require('crypto')
describe('DocArchiveManager', function() {
beforeEach(function() {
describe('DocArchiveManager', function () {
beforeEach(function () {
this.settings = {
docstore: {
s3: {
@@ -135,15 +135,15 @@ describe('DocArchiveManager', function() {
}))
})
describe('archiveDoc', function() {
it('should use correct options', function(done) {
describe('archiveDoc', function () {
it('should use correct options', function (done) {
this.request.put = sinon
.stub()
.callsArgWith(1, null, { statusCode: 200, headers: { etag: '' } })
return this.DocArchiveManager.archiveDoc(
this.project_id,
this.mongoDocs[0],
err => {
(err) => {
const opts = this.request.put.args[0][0]
assert.deepEqual(opts.aws, {
key: this.settings.docstore.s3.key,
@@ -166,30 +166,27 @@ describe('DocArchiveManager', function() {
)
})
it('should return no md5 error', function(done) {
it('should return no md5 error', function (done) {
const data = JSON.stringify({
lines: this.mongoDocs[0].lines,
ranges: this.mongoDocs[0].ranges,
schema_v: 1
})
this.md5 = crypto
.createHash('md5')
.update(data)
.digest('hex')
this.md5 = crypto.createHash('md5').update(data).digest('hex')
this.request.put = sinon
.stub()
.callsArgWith(1, null, { statusCode: 200, headers: { etag: this.md5 } })
return this.DocArchiveManager.archiveDoc(
this.project_id,
this.mongoDocs[0],
err => {
(err) => {
should.not.exist(err)
return done()
}
)
})
return it('should return the error', function(done) {
return it('should return the error', function (done) {
this.request.put = sinon.stub().callsArgWith(1, this.stubbedError, {
statusCode: 400,
headers: { etag: '' }
@@ -197,7 +194,7 @@ describe('DocArchiveManager', function() {
return this.DocArchiveManager.archiveDoc(
this.project_id,
this.mongoDocs[0],
err => {
(err) => {
should.exist(err)
return done()
}
@@ -205,8 +202,8 @@ describe('DocArchiveManager', function() {
})
})
describe('unarchiveDoc', function() {
it('should use correct options', function(done) {
describe('unarchiveDoc', function () {
it('should use correct options', function (done) {
this.request.get = sinon
.stub()
.callsArgWith(1, null, { statusCode: 200 }, this.mongoDocs[0].lines)
@@ -216,7 +213,7 @@ describe('DocArchiveManager', function() {
return this.DocArchiveManager.unarchiveDoc(
this.project_id,
this.mongoDocs[0]._id,
err => {
(err) => {
const opts = this.request.get.args[0][0]
assert.deepEqual(opts.aws, {
key: this.settings.docstore.s3.key,
@@ -233,19 +230,19 @@ describe('DocArchiveManager', function() {
)
})
it('should return the error', function(done) {
it('should return the error', function (done) {
this.request.get = sinon.stub().callsArgWith(1, this.stubbedError, {}, {})
return this.DocArchiveManager.unarchiveDoc(
this.project_id,
this.mongoDocs[0],
err => {
(err) => {
should.exist(err)
return done()
}
)
})
return it('should error if the doc lines are a string not an array', function(done) {
return it('should error if the doc lines are a string not an array', function (done) {
this.request.get = sinon
.stub()
.callsArgWith(1, null, { statusCode: 200 }, 'this is a string')
@@ -253,7 +250,7 @@ describe('DocArchiveManager', function() {
return this.DocArchiveManager.unarchiveDoc(
this.project_id,
this.mongoDocs[0],
err => {
(err) => {
should.exist(err)
this.request.del.called.should.equal(false)
return done()
@@ -262,14 +259,14 @@ describe('DocArchiveManager', function() {
})
})
describe('archiveAllDocs', function() {
it('should archive all project docs which are not in s3', function(done) {
describe('archiveAllDocs', function () {
it('should archive all project docs which are not in s3', function (done) {
this.MongoManager.getProjectsDocs = sinon
.stub()
.callsArgWith(3, null, this.mongoDocs)
this.DocArchiveManager.archiveDoc = sinon.stub().callsArgWith(2, null)
return this.DocArchiveManager.archiveAllDocs(this.project_id, err => {
return this.DocArchiveManager.archiveAllDocs(this.project_id, (err) => {
this.DocArchiveManager.archiveDoc
.calledWith(this.project_id, this.mongoDocs[0])
.should.equal(true)
@@ -292,30 +289,30 @@ describe('DocArchiveManager', function() {
})
})
it('should return error if have no docs', function(done) {
it('should return error if have no docs', function (done) {
this.MongoManager.getProjectsDocs = sinon
.stub()
.callsArgWith(3, null, null)
return this.DocArchiveManager.archiveAllDocs(this.project_id, err => {
return this.DocArchiveManager.archiveAllDocs(this.project_id, (err) => {
should.exist(err)
return done()
})
})
it('should return the error', function(done) {
it('should return the error', function (done) {
this.MongoManager.getProjectsDocs = sinon
.stub()
.callsArgWith(3, this.error, null)
return this.DocArchiveManager.archiveAllDocs(this.project_id, err => {
return this.DocArchiveManager.archiveAllDocs(this.project_id, (err) => {
err.should.equal(this.error)
return done()
})
})
return describe('when most have been already put in s3', function() {
beforeEach(function() {
return describe('when most have been already put in s3', function () {
beforeEach(function () {
let numberOfDocs = 10 * 1000
this.mongoDocs = []
while (--numberOfDocs !== 0) {
@@ -330,8 +327,8 @@ describe('DocArchiveManager', function() {
.callsArgWith(2, null))
})
return it('should not throw and error', function(done) {
return this.DocArchiveManager.archiveAllDocs(this.project_id, err => {
return it('should not throw and error', function (done) {
return this.DocArchiveManager.archiveAllDocs(this.project_id, (err) => {
should.not.exist(err)
return done()
})
@@ -339,13 +336,13 @@ describe('DocArchiveManager', function() {
})
})
describe('unArchiveAllDocs', function() {
it('should unarchive all inS3 docs', function(done) {
describe('unArchiveAllDocs', function () {
it('should unarchive all inS3 docs', function (done) {
this.MongoManager.getArchivedProjectDocs = sinon
.stub()
.callsArgWith(1, null, this.archivedDocs)
this.DocArchiveManager.unarchiveDoc = sinon.stub().callsArgWith(2, null)
return this.DocArchiveManager.unArchiveAllDocs(this.project_id, err => {
return this.DocArchiveManager.unArchiveAllDocs(this.project_id, (err) => {
for (const doc of Array.from(this.archivedDocs)) {
this.DocArchiveManager.unarchiveDoc
.calledWith(this.project_id, doc._id)
@@ -356,29 +353,29 @@ describe('DocArchiveManager', function() {
})
})
it('should return error if have no docs', function(done) {
it('should return error if have no docs', function (done) {
this.MongoManager.getArchivedProjectDocs = sinon
.stub()
.callsArgWith(1, null, null)
return this.DocArchiveManager.unArchiveAllDocs(this.project_id, err => {
return this.DocArchiveManager.unArchiveAllDocs(this.project_id, (err) => {
should.exist(err)
return done()
})
})
return it('should return the error', function(done) {
return it('should return the error', function (done) {
this.MongoManager.getArchivedProjectDocs = sinon
.stub()
.callsArgWith(1, this.error, null)
return this.DocArchiveManager.unArchiveAllDocs(this.project_id, err => {
return this.DocArchiveManager.unArchiveAllDocs(this.project_id, (err) => {
err.should.equal(this.error)
return done()
})
})
})
describe('destroyAllDocs', function() {
beforeEach(function() {
describe('destroyAllDocs', function () {
beforeEach(function () {
this.request.del = sinon
.stub()
.callsArgWith(1, null, { statusCode: 204 }, {})
@@ -387,16 +384,16 @@ describe('DocArchiveManager', function() {
.callsArgWith(3, null, this.mixedDocs)
this.MongoManager.findDoc = sinon.stub().callsArgWith(3, null, null)
this.MongoManager.destroyDoc = sinon.stub().yields()
return Array.from(this.mixedDocs).map(doc =>
return Array.from(this.mixedDocs).map((doc) =>
this.MongoManager.findDoc
.withArgs(this.project_id, doc._id)
.callsArgWith(3, null, doc)
)
})
it('should destroy all the docs', function(done) {
it('should destroy all the docs', function (done) {
this.DocArchiveManager.destroyDoc = sinon.stub().callsArgWith(2, null)
return this.DocArchiveManager.destroyAllDocs(this.project_id, err => {
return this.DocArchiveManager.destroyAllDocs(this.project_id, (err) => {
for (const doc of Array.from(this.mixedDocs)) {
this.DocArchiveManager.destroyDoc
.calledWith(this.project_id, doc._id)
@@ -407,8 +404,8 @@ describe('DocArchiveManager', function() {
})
})
it('should only the s3 docs from s3', function(done) {
const docOpts = doc => {
it('should only the s3 docs from s3', function (done) {
const docOpts = (doc) => {
return JSON.parse(
JSON.stringify({
aws: {
@@ -423,7 +420,7 @@ describe('DocArchiveManager', function() {
)
}
return this.DocArchiveManager.destroyAllDocs(this.project_id, err => {
return this.DocArchiveManager.destroyAllDocs(this.project_id, (err) => {
let doc
expect(err).not.to.exist
@@ -438,8 +435,8 @@ describe('DocArchiveManager', function() {
})
})
return it('should remove the docs from mongo', function(done) {
this.DocArchiveManager.destroyAllDocs(this.project_id, err => {
return it('should remove the docs from mongo', function (done) {
this.DocArchiveManager.destroyAllDocs(this.project_id, (err) => {
return expect(err).not.to.exist
})
@@ -451,9 +448,9 @@ describe('DocArchiveManager', function() {
})
})
describe('_s3DocToMongoDoc', function() {
describe('with the old schema', function() {
return it('should return the docs lines', function(done) {
describe('_s3DocToMongoDoc', function () {
describe('with the old schema', function () {
return it('should return the docs lines', function (done) {
return this.DocArchiveManager._s3DocToMongoDoc(
['doc', 'lines'],
(error, doc) => {
@@ -466,8 +463,8 @@ describe('DocArchiveManager', function() {
})
})
describe('with the new schema', function() {
it('should return the doc lines and ranges', function(done) {
describe('with the new schema', function () {
it('should return the doc lines and ranges', function (done) {
this.RangeManager.jsonRangesToMongo = sinon
.stub()
.returns({ mongo: 'ranges' })
@@ -487,7 +484,7 @@ describe('DocArchiveManager', function() {
)
})
return it('should return just the doc lines when there are no ranges', function(done) {
return it('should return just the doc lines when there are no ranges', function (done) {
return this.DocArchiveManager._s3DocToMongoDoc(
{
lines: ['doc', 'lines'],
@@ -503,8 +500,8 @@ describe('DocArchiveManager', function() {
})
})
return describe('with an unrecognised schema', function() {
return it('should return an error', function(done) {
return describe('with an unrecognised schema', function () {
return it('should return an error', function (done) {
return this.DocArchiveManager._s3DocToMongoDoc(
{
schema_v: 2
@@ -518,9 +515,9 @@ describe('DocArchiveManager', function() {
})
})
return describe('_mongoDocToS3Doc', function() {
describe('with a valid doc', function() {
return it('should return the json version', function(done) {
return describe('_mongoDocToS3Doc', function () {
describe('with a valid doc', function () {
return it('should return the json version', function (done) {
let doc
return this.DocArchiveManager._mongoDocToS3Doc(
(doc = {
@@ -541,17 +538,17 @@ describe('DocArchiveManager', function() {
})
})
describe('with null bytes in the result', function() {
beforeEach(function() {
describe('with null bytes in the result', function () {
beforeEach(function () {
this._stringify = JSON.stringify
return (JSON.stringify = sinon.stub().returns('{"bad": "\u0000"}'))
})
afterEach(function() {
afterEach(function () {
return (JSON.stringify = this._stringify)
})
return it('should return an error', function(done) {
return it('should return an error', function (done) {
return this.DocArchiveManager._mongoDocToS3Doc(
{
lines: ['doc', 'lines'],
@@ -565,8 +562,8 @@ describe('DocArchiveManager', function() {
})
})
return describe('without doc lines', function() {
return it('should return an error', function(done) {
return describe('without doc lines', function () {
return it('should return an error', function (done) {
return this.DocArchiveManager._mongoDocToS3Doc({}, (err, s3_doc) => {
expect(err).to.exist
return done()
+106 -106
View File
@@ -22,8 +22,8 @@ const modulePath = require('path').join(__dirname, '../../../app/js/DocManager')
const { ObjectId } = require('mongojs')
const Errors = require('../../../app/js/Errors')
describe('DocManager', function() {
beforeEach(function() {
describe('DocManager', function () {
beforeEach(function () {
this.DocManager = SandboxedModule.require(modulePath, {
requires: {
'./MongoManager': (this.MongoManager = {}),
@@ -48,12 +48,12 @@ describe('DocManager', function() {
return (this.stubbedError = new Error('blew up'))
})
describe('checkDocExists', function() {
beforeEach(function() {
describe('checkDocExists', function () {
beforeEach(function () {
return (this.DocManager._getDoc = sinon.stub())
})
it('should call get doc with a quick filter', function(done) {
it('should call get doc with a quick filter', function (done) {
this.DocManager._getDoc.callsArgWith(3, null, { _id: this.doc_id })
return this.DocManager.checkDocExists(
this.project_id,
@@ -68,7 +68,7 @@ describe('DocManager', function() {
)
})
it('should return false when doc is not there', function(done) {
it('should return false when doc is not there', function (done) {
this.DocManager._getDoc.callsArgWith(3, null)
return this.DocManager.checkDocExists(
this.project_id,
@@ -80,7 +80,7 @@ describe('DocManager', function() {
)
})
return it('should return error when get doc errors', function(done) {
return it('should return error when get doc errors', function (done) {
this.DocManager._getDoc.callsArgWith(3, 'error')
return this.DocManager.checkDocExists(
this.project_id,
@@ -93,8 +93,8 @@ describe('DocManager', function() {
})
})
describe('getFullDoc', function() {
beforeEach(function() {
describe('getFullDoc', function () {
beforeEach(function () {
this.DocManager._getDoc = sinon.stub()
return (this.doc = {
_id: this.doc_id,
@@ -102,7 +102,7 @@ describe('DocManager', function() {
})
})
it('should call get doc with a quick filter', function(done) {
it('should call get doc with a quick filter', function (done) {
this.DocManager._getDoc.callsArgWith(3, null, this.doc)
return this.DocManager.getFullDoc(
this.project_id,
@@ -124,7 +124,7 @@ describe('DocManager', function() {
)
})
return it('should return error when get doc errors', function(done) {
return it('should return error when get doc errors', function (done) {
this.DocManager._getDoc.callsArgWith(3, 'error')
return this.DocManager.getFullDoc(
this.project_id,
@@ -137,13 +137,13 @@ describe('DocManager', function() {
})
})
describe('getRawDoc', function() {
beforeEach(function() {
describe('getRawDoc', function () {
beforeEach(function () {
this.DocManager._getDoc = sinon.stub()
return (this.doc = { lines: ['2134'] })
})
it('should call get doc with a quick filter', function(done) {
it('should call get doc with a quick filter', function (done) {
this.DocManager._getDoc.callsArgWith(3, null, this.doc)
return this.DocManager.getDocLines(
this.project_id,
@@ -161,7 +161,7 @@ describe('DocManager', function() {
)
})
return it('should return error when get doc errors', function(done) {
return it('should return error when get doc errors', function (done) {
this.DocManager._getDoc.callsArgWith(3, 'error')
return this.DocManager.getDocLines(
this.project_id,
@@ -174,8 +174,8 @@ describe('DocManager', function() {
})
})
describe('getDoc', function() {
beforeEach(function() {
describe('getDoc', function () {
beforeEach(function () {
this.project = { name: 'mock-project' }
this.doc = {
_id: this.doc_id,
@@ -189,29 +189,29 @@ describe('DocManager', function() {
.yields(null, this.version))
})
describe('when using a filter', function() {
beforeEach(function() {
describe('when using a filter', function () {
beforeEach(function () {
return this.MongoManager.findDoc.yields(null, this.doc)
})
it('should error if inS3 is not set to true', function(done) {
it('should error if inS3 is not set to true', function (done) {
return this.DocManager._getDoc(
this.project_id,
this.doc_id,
{ inS3: false },
err => {
(err) => {
expect(err).to.exist
return done()
}
)
})
it('should always get inS3 even when no filter is passed', function(done) {
it('should always get inS3 even when no filter is passed', function (done) {
return this.DocManager._getDoc(
this.project_id,
this.doc_id,
undefined,
err => {
(err) => {
this.MongoManager.findDoc.called.should.equal(false)
expect(err).to.exist
return done()
@@ -219,12 +219,12 @@ describe('DocManager', function() {
)
})
return it('should not error if inS3 is set to true', function(done) {
return it('should not error if inS3 is set to true', function (done) {
return this.DocManager._getDoc(
this.project_id,
this.doc_id,
{ inS3: true },
err => {
(err) => {
expect(err).to.not.exist
return done()
}
@@ -232,8 +232,8 @@ describe('DocManager', function() {
})
})
describe('when the doc is in the doc collection', function() {
beforeEach(function() {
describe('when the doc is in the doc collection', function () {
beforeEach(function () {
this.MongoManager.findDoc.yields(null, this.doc)
return this.DocManager._getDoc(
this.project_id,
@@ -243,19 +243,19 @@ describe('DocManager', function() {
)
})
it('should get the doc from the doc collection', function() {
it('should get the doc from the doc collection', function () {
return this.MongoManager.findDoc
.calledWith(this.project_id, this.doc_id)
.should.equal(true)
})
it('should get the doc version from the docOps collection', function() {
it('should get the doc version from the docOps collection', function () {
return this.MongoManager.getDocVersion
.calledWith(this.doc_id)
.should.equal(true)
})
return it('should return the callback with the doc with the version', function() {
return it('should return the callback with the doc with the version', function () {
this.callback.called.should.equal(true)
const doc = this.callback.args[0][1]
doc.lines.should.equal(this.doc.lines)
@@ -263,8 +263,8 @@ describe('DocManager', function() {
})
})
describe('without the version filter', function() {
beforeEach(function() {
describe('without the version filter', function () {
beforeEach(function () {
this.MongoManager.findDoc.yields(null, this.doc)
return this.DocManager._getDoc(
this.project_id,
@@ -274,13 +274,13 @@ describe('DocManager', function() {
)
})
return it('should not get the doc version from the docOps collection', function() {
return it('should not get the doc version from the docOps collection', function () {
return this.MongoManager.getDocVersion.called.should.equal(false)
})
})
describe('when MongoManager.findDoc errors', function() {
beforeEach(function() {
describe('when MongoManager.findDoc errors', function () {
beforeEach(function () {
this.MongoManager.findDoc.yields(this.stubbedError)
return this.DocManager._getDoc(
this.project_id,
@@ -290,13 +290,13 @@ describe('DocManager', function() {
)
})
return it('should return the error', function() {
return it('should return the error', function () {
return this.callback.calledWith(this.stubbedError).should.equal(true)
})
})
describe('when the doc is archived', function() {
beforeEach(function() {
describe('when the doc is archived', function () {
beforeEach(function () {
this.doc = {
_id: this.doc_id,
project_id: this.project_id,
@@ -321,23 +321,23 @@ describe('DocManager', function() {
)
})
it('should call the DocArchive to unarchive the doc', function() {
it('should call the DocArchive to unarchive the doc', function () {
return this.DocArchiveManager.unarchiveDoc
.calledWith(this.project_id, this.doc_id)
.should.equal(true)
})
it('should look up the doc twice', function() {
it('should look up the doc twice', function () {
return this.MongoManager.findDoc.calledTwice.should.equal(true)
})
return it('should return the doc', function() {
return it('should return the doc', function () {
return this.callback.calledWith(null, this.doc).should.equal(true)
})
})
return describe('when the doc does not exist in the docs collection', function() {
beforeEach(function() {
return describe('when the doc does not exist in the docs collection', function () {
beforeEach(function () {
this.MongoManager.findDoc = sinon.stub().yields(null, null)
return this.DocManager._getDoc(
this.project_id,
@@ -347,7 +347,7 @@ describe('DocManager', function() {
)
})
return it('should return a NotFoundError', function() {
return it('should return a NotFoundError', function () {
return this.callback
.calledWith(
sinon.match.has(
@@ -360,9 +360,9 @@ describe('DocManager', function() {
})
})
describe('getAllNonDeletedDocs', function() {
describe('when the project exists', function() {
beforeEach(function() {
describe('getAllNonDeletedDocs', function () {
describe('when the project exists', function () {
beforeEach(function () {
this.docs = [
{
_id: this.doc_id,
@@ -384,19 +384,19 @@ describe('DocManager', function() {
)
})
it('should get the project from the database', function() {
it('should get the project from the database', function () {
return this.MongoManager.getProjectsDocs
.calledWith(this.project_id, { include_deleted: false }, this.filter)
.should.equal(true)
})
return it('should return the docs', function() {
return it('should return the docs', function () {
return this.callback.calledWith(null, this.docs).should.equal(true)
})
})
return describe('when there are no docs for the project', function() {
beforeEach(function() {
return describe('when there are no docs for the project', function () {
beforeEach(function () {
this.MongoManager.getProjectsDocs = sinon
.stub()
.callsArgWith(3, null, null)
@@ -410,7 +410,7 @@ describe('DocManager', function() {
)
})
return it('should return a NotFoundError', function() {
return it('should return a NotFoundError', function () {
return this.callback
.calledWith(
sinon.match.has('message', `No docs for project ${this.project_id}`)
@@ -420,9 +420,9 @@ describe('DocManager', function() {
})
})
describe('deleteDoc', function() {
describe('when the doc exists', function() {
beforeEach(function() {
describe('deleteDoc', function () {
describe('when the doc exists', function () {
beforeEach(function () {
this.lines = ['mock', 'doc', 'lines']
this.rev = 77
this.DocManager.checkDocExists = sinon
@@ -436,25 +436,25 @@ describe('DocManager', function() {
)
})
it('should get the doc', function() {
it('should get the doc', function () {
return this.DocManager.checkDocExists
.calledWith(this.project_id, this.doc_id)
.should.equal(true)
})
it('should mark doc as deleted', function() {
it('should mark doc as deleted', function () {
return this.MongoManager.markDocAsDeleted
.calledWith(this.project_id, this.doc_id)
.should.equal(true)
})
return it('should return the callback', function() {
return it('should return the callback', function () {
return this.callback.called.should.equal(true)
})
})
return describe('when the doc does not exist', function() {
beforeEach(function() {
return describe('when the doc does not exist', function () {
beforeEach(function () {
this.DocManager.checkDocExists = sinon
.stub()
.callsArgWith(2, null, false)
@@ -465,7 +465,7 @@ describe('DocManager', function() {
)
})
return it('should return a NotFoundError', function() {
return it('should return a NotFoundError', function () {
return this.callback
.calledWith(
sinon.match.has(
@@ -478,8 +478,8 @@ describe('DocManager', function() {
})
})
return describe('updateDoc', function() {
beforeEach(function() {
return describe('updateDoc', function () {
beforeEach(function () {
this.oldDocLines = ['old', 'doc', 'lines']
this.newDocLines = ['new', 'doc', 'lines']
this.originalRanges = {
@@ -521,8 +521,8 @@ describe('DocManager', function() {
return (this.DocManager._getDoc = sinon.stub())
})
describe('when only the doc lines have changed', function() {
beforeEach(function() {
describe('when only the doc lines have changed', function () {
beforeEach(function () {
this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, this.doc)
return this.DocManager.updateDoc(
this.project_id,
@@ -534,7 +534,7 @@ describe('DocManager', function() {
)
})
it('should get the existing doc', function() {
it('should get the existing doc', function () {
return this.DocManager._getDoc
.calledWith(this.project_id, this.doc_id, {
version: true,
@@ -547,25 +547,25 @@ describe('DocManager', function() {
.should.equal(true)
})
it('should upsert the document to the doc collection', function() {
it('should upsert the document to the doc collection', function () {
return this.MongoManager.upsertIntoDocCollection
.calledWith(this.project_id, this.doc_id, { lines: this.newDocLines })
.should.equal(true)
})
it('should not update the version', function() {
it('should not update the version', function () {
return this.MongoManager.setDocVersion.called.should.equal(false)
})
return it('should return the callback with the new rev', function() {
return it('should return the callback with the new rev', function () {
return this.callback
.calledWith(null, true, this.rev + 1)
.should.equal(true)
})
})
describe('when the doc ranges have changed', function() {
beforeEach(function() {
describe('when the doc ranges have changed', function () {
beforeEach(function () {
this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, this.doc)
this.RangeManager.shouldUpdateRanges.returns(true)
return this.DocManager.updateDoc(
@@ -578,25 +578,25 @@ describe('DocManager', function() {
)
})
it('should upsert the ranges', function() {
it('should upsert the ranges', function () {
return this.MongoManager.upsertIntoDocCollection
.calledWith(this.project_id, this.doc_id, { ranges: this.newRanges })
.should.equal(true)
})
it('should not update the version', function() {
it('should not update the version', function () {
return this.MongoManager.setDocVersion.called.should.equal(false)
})
return it('should return the callback with the new rev', function() {
return it('should return the callback with the new rev', function () {
return this.callback
.calledWith(null, true, this.rev + 1)
.should.equal(true)
})
})
describe('when only the version has changed', function() {
beforeEach(function() {
describe('when only the version has changed', function () {
beforeEach(function () {
this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, this.doc)
return this.DocManager.updateDoc(
this.project_id,
@@ -608,25 +608,25 @@ describe('DocManager', function() {
)
})
it('should not change the lines or ranges', function() {
it('should not change the lines or ranges', function () {
return this.MongoManager.upsertIntoDocCollection.called.should.equal(
false
)
})
it('should update the version', function() {
it('should update the version', function () {
return this.MongoManager.setDocVersion
.calledWith(this.doc_id, this.version + 1)
.should.equal(true)
})
return it('should return the callback with the old rev', function() {
return it('should return the callback with the old rev', function () {
return this.callback.calledWith(null, true, this.rev).should.equal(true)
})
})
describe('when the doc has not changed at all', function() {
beforeEach(function() {
describe('when the doc has not changed at all', function () {
beforeEach(function () {
this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, this.doc)
return this.DocManager.updateDoc(
this.project_id,
@@ -638,25 +638,25 @@ describe('DocManager', function() {
)
})
it('should not update the ranges or lines', function() {
it('should not update the ranges or lines', function () {
return this.MongoManager.upsertIntoDocCollection.called.should.equal(
false
)
})
it('should not update the version', function() {
it('should not update the version', function () {
return this.MongoManager.setDocVersion.called.should.equal(false)
})
return it('should return the callback with the old rev and modified == false', function() {
return it('should return the callback with the old rev and modified == false', function () {
return this.callback
.calledWith(null, false, this.rev)
.should.equal(true)
})
})
describe('when the version is null', function() {
beforeEach(function() {
describe('when the version is null', function () {
beforeEach(function () {
return this.DocManager.updateDoc(
this.project_id,
this.doc_id,
@@ -667,7 +667,7 @@ describe('DocManager', function() {
)
})
return it('should return an error', function() {
return it('should return an error', function () {
return this.callback
.calledWith(
sinon.match.has('message', 'no lines, version or ranges provided')
@@ -676,8 +676,8 @@ describe('DocManager', function() {
})
})
describe('when the lines are null', function() {
beforeEach(function() {
describe('when the lines are null', function () {
beforeEach(function () {
return this.DocManager.updateDoc(
this.project_id,
this.doc_id,
@@ -688,7 +688,7 @@ describe('DocManager', function() {
)
})
return it('should return an error', function() {
return it('should return an error', function () {
return this.callback
.calledWith(
sinon.match.has('message', 'no lines, version or ranges provided')
@@ -697,8 +697,8 @@ describe('DocManager', function() {
})
})
describe('when the ranges are null', function() {
beforeEach(function() {
describe('when the ranges are null', function () {
beforeEach(function () {
return this.DocManager.updateDoc(
this.project_id,
this.doc_id,
@@ -709,7 +709,7 @@ describe('DocManager', function() {
)
})
return it('should return an error', function() {
return it('should return an error', function () {
return this.callback
.calledWith(
sinon.match.has('message', 'no lines, version or ranges provided')
@@ -718,8 +718,8 @@ describe('DocManager', function() {
})
})
describe('when there is a generic error getting the doc', function() {
beforeEach(function() {
describe('when there is a generic error getting the doc', function () {
beforeEach(function () {
this.error = new Error('doc could not be found')
this.DocManager._getDoc = sinon
.stub()
@@ -734,19 +734,19 @@ describe('DocManager', function() {
)
})
it('should not upsert the document to the doc collection', function() {
it('should not upsert the document to the doc collection', function () {
return this.MongoManager.upsertIntoDocCollection.called.should.equal(
false
)
})
return it('should return the callback with the error', function() {
return it('should return the callback with the error', function () {
return this.callback.calledWith(this.error).should.equal(true)
})
})
describe('when the doc lines have not changed', function() {
beforeEach(function() {
describe('when the doc lines have not changed', function () {
beforeEach(function () {
this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, this.doc)
return this.DocManager.updateDoc(
this.project_id,
@@ -758,21 +758,21 @@ describe('DocManager', function() {
)
})
it('should not update the doc', function() {
it('should not update the doc', function () {
return this.MongoManager.upsertIntoDocCollection.called.should.equal(
false
)
})
return it('should return the callback with the existing rev', function() {
return it('should return the callback with the existing rev', function () {
return this.callback
.calledWith(null, false, this.rev)
.should.equal(true)
})
})
return describe('when the doc does not exist', function() {
beforeEach(function() {
return describe('when the doc does not exist', function () {
beforeEach(function () {
this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, null, null)
return this.DocManager.updateDoc(
this.project_id,
@@ -784,7 +784,7 @@ describe('DocManager', function() {
)
})
it('should upsert the document to the doc collection', function() {
it('should upsert the document to the doc collection', function () {
return this.MongoManager.upsertIntoDocCollection
.calledWith(this.project_id, this.doc_id, {
lines: this.newDocLines,
@@ -793,13 +793,13 @@ describe('DocManager', function() {
.should.equal(true)
})
it('should set the version', function() {
it('should set the version', function () {
return this.MongoManager.setDocVersion
.calledWith(this.doc_id, this.version)
.should.equal(true)
})
return it('should return the callback with the new rev', function() {
return it('should return the callback with the new rev', function () {
return this.callback.calledWith(null, true, 1).should.equal(true)
})
})
@@ -21,8 +21,8 @@ const modulePath = require('path').join(
)
const { ObjectId } = require('mongojs')
describe('HttpController', function() {
beforeEach(function() {
describe('HttpController', function () {
beforeEach(function () {
this.HttpController = SandboxedModule.require(modulePath, {
requires: {
'./DocManager': (this.DocManager = {}),
@@ -60,9 +60,9 @@ describe('HttpController', function() {
})
})
describe('getDoc', function() {
describe('without deleted docs', function() {
beforeEach(function() {
describe('getDoc', function () {
describe('without deleted docs', function () {
beforeEach(function () {
this.req.params = {
project_id: this.project_id,
doc_id: this.doc_id
@@ -73,13 +73,13 @@ describe('HttpController', function() {
return this.HttpController.getDoc(this.req, this.res, this.next)
})
it('should get the document with the version (including deleted)', function() {
it('should get the document with the version (including deleted)', function () {
return this.DocManager.getFullDoc
.calledWith(this.project_id, this.doc_id)
.should.equal(true)
})
return it('should return the doc as JSON', function() {
return it('should return the doc as JSON', function () {
return this.res.json
.calledWith({
_id: this.doc_id,
@@ -91,8 +91,8 @@ describe('HttpController', function() {
})
})
return describe('which is deleted', function() {
beforeEach(function() {
return describe('which is deleted', function () {
beforeEach(function () {
this.req.params = {
project_id: this.project_id,
doc_id: this.doc_id
@@ -102,19 +102,19 @@ describe('HttpController', function() {
.callsArgWith(2, null, this.deletedDoc))
})
it('should get the doc from the doc manager', function() {
it('should get the doc from the doc manager', function () {
this.HttpController.getDoc(this.req, this.res, this.next)
return this.DocManager.getFullDoc
.calledWith(this.project_id, this.doc_id)
.should.equal(true)
})
it('should return 404 if the query string delete is not set ', function() {
it('should return 404 if the query string delete is not set ', function () {
this.HttpController.getDoc(this.req, this.res, this.next)
return this.res.send.calledWith(404).should.equal(true)
})
return it('should return the doc as JSON if include_deleted is set to true', function() {
return it('should return the doc as JSON if include_deleted is set to true', function () {
this.req.query.include_deleted = 'true'
this.HttpController.getDoc(this.req, this.res, this.next)
return this.res.json
@@ -130,8 +130,8 @@ describe('HttpController', function() {
})
})
describe('getRawDoc', function() {
beforeEach(function() {
describe('getRawDoc', function () {
beforeEach(function () {
this.req.params = {
project_id: this.project_id,
doc_id: this.doc_id
@@ -140,19 +140,19 @@ describe('HttpController', function() {
return this.HttpController.getRawDoc(this.req, this.res, this.next)
})
it('should get the document without the version', function() {
it('should get the document without the version', function () {
return this.DocManager.getDocLines
.calledWith(this.project_id, this.doc_id)
.should.equal(true)
})
it('should set the content type header', function() {
it('should set the content type header', function () {
return this.res.setHeader
.calledWith('content-type', 'text/plain')
.should.equal(true)
})
return it('should send the raw version of the doc', function() {
return it('should send the raw version of the doc', function () {
return assert.deepEqual(
this.res.send.args[0][0],
`${this.doc.lines[0]}\n${this.doc.lines[1]}\n${this.doc.lines[2]}\n${this.doc.lines[3]}\n${this.doc.lines[4]}\n${this.doc.lines[5]}`
@@ -160,9 +160,9 @@ describe('HttpController', function() {
})
})
describe('getAllDocs', function() {
describe('normally', function() {
beforeEach(function() {
describe('getAllDocs', function () {
describe('normally', function () {
beforeEach(function () {
this.req.params = { project_id: this.project_id }
this.docs = [
{
@@ -182,13 +182,13 @@ describe('HttpController', function() {
return this.HttpController.getAllDocs(this.req, this.res, this.next)
})
it('should get all the (non-deleted) docs', function() {
it('should get all the (non-deleted) docs', function () {
return this.DocManager.getAllNonDeletedDocs
.calledWith(this.project_id, { lines: true, rev: true })
.should.equal(true)
})
return it('should return the doc as JSON', function() {
return it('should return the doc as JSON', function () {
return this.res.json
.calledWith([
{
@@ -206,8 +206,8 @@ describe('HttpController', function() {
})
})
return describe('with a null doc', function() {
beforeEach(function() {
return describe('with a null doc', function () {
beforeEach(function () {
this.req.params = { project_id: this.project_id }
this.docs = [
{
@@ -228,7 +228,7 @@ describe('HttpController', function() {
return this.HttpController.getAllDocs(this.req, this.res, this.next)
})
it('should return the non null docs as JSON', function() {
it('should return the non null docs as JSON', function () {
return this.res.json
.calledWith([
{
@@ -245,7 +245,7 @@ describe('HttpController', function() {
.should.equal(true)
})
return it('should log out an error', function() {
return it('should log out an error', function () {
return this.logger.error
.calledWith(
{
@@ -259,9 +259,9 @@ describe('HttpController', function() {
})
})
describe('getAllRanges', function() {
return describe('normally', function() {
beforeEach(function() {
describe('getAllRanges', function () {
return describe('normally', function () {
beforeEach(function () {
this.req.params = { project_id: this.project_id }
this.docs = [
{
@@ -279,13 +279,13 @@ describe('HttpController', function() {
return this.HttpController.getAllRanges(this.req, this.res, this.next)
})
it('should get all the (non-deleted) doc ranges', function() {
it('should get all the (non-deleted) doc ranges', function () {
return this.DocManager.getAllNonDeletedDocs
.calledWith(this.project_id, { ranges: true })
.should.equal(true)
})
return it('should return the doc as JSON', function() {
return it('should return the doc as JSON', function () {
return this.res.json
.calledWith([
{
@@ -302,16 +302,16 @@ describe('HttpController', function() {
})
})
describe('updateDoc', function() {
beforeEach(function() {
describe('updateDoc', function () {
beforeEach(function () {
return (this.req.params = {
project_id: this.project_id,
doc_id: this.doc_id
})
})
describe('when the doc lines exist and were updated', function() {
beforeEach(function() {
describe('when the doc lines exist and were updated', function () {
beforeEach(function () {
this.req.body = {
lines: (this.lines = ['hello', 'world']),
version: (this.version = 42),
@@ -323,7 +323,7 @@ describe('HttpController', function() {
return this.HttpController.updateDoc(this.req, this.res, this.next)
})
it('should update the document', function() {
it('should update the document', function () {
return this.DocManager.updateDoc
.calledWith(
this.project_id,
@@ -335,15 +335,15 @@ describe('HttpController', function() {
.should.equal(true)
})
return it('should return a modified status', function() {
return it('should return a modified status', function () {
return this.res.json
.calledWith({ modified: true, rev: this.rev })
.should.equal(true)
})
})
describe('when the doc lines exist and were not updated', function() {
beforeEach(function() {
describe('when the doc lines exist and were not updated', function () {
beforeEach(function () {
this.req.body = {
lines: (this.lines = ['hello', 'world']),
version: (this.version = 42),
@@ -355,63 +355,63 @@ describe('HttpController', function() {
return this.HttpController.updateDoc(this.req, this.res, this.next)
})
return it('should return a modified status', function() {
return it('should return a modified status', function () {
return this.res.json
.calledWith({ modified: false, rev: this.rev })
.should.equal(true)
})
})
describe('when the doc lines are not provided', function() {
beforeEach(function() {
describe('when the doc lines are not provided', function () {
beforeEach(function () {
this.req.body = { version: 42, ranges: {} }
this.DocManager.updateDoc = sinon.stub().yields(null, false)
return this.HttpController.updateDoc(this.req, this.res, this.next)
})
it('should not update the document', function() {
it('should not update the document', function () {
return this.DocManager.updateDoc.called.should.equal(false)
})
return it('should return a 400 (bad request) response', function() {
return it('should return a 400 (bad request) response', function () {
return this.res.send.calledWith(400).should.equal(true)
})
})
describe('when the doc version are not provided', function() {
beforeEach(function() {
describe('when the doc version are not provided', function () {
beforeEach(function () {
this.req.body = { version: 42, lines: ['hello world'] }
this.DocManager.updateDoc = sinon.stub().yields(null, false)
return this.HttpController.updateDoc(this.req, this.res, this.next)
})
it('should not update the document', function() {
it('should not update the document', function () {
return this.DocManager.updateDoc.called.should.equal(false)
})
return it('should return a 400 (bad request) response', function() {
return it('should return a 400 (bad request) response', function () {
return this.res.send.calledWith(400).should.equal(true)
})
})
describe('when the doc ranges is not provided', function() {
beforeEach(function() {
describe('when the doc ranges is not provided', function () {
beforeEach(function () {
this.req.body = { lines: ['foo'], version: 42 }
this.DocManager.updateDoc = sinon.stub().yields(null, false)
return this.HttpController.updateDoc(this.req, this.res, this.next)
})
it('should not update the document', function() {
it('should not update the document', function () {
return this.DocManager.updateDoc.called.should.equal(false)
})
return it('should return a 400 (bad request) response', function() {
return it('should return a 400 (bad request) response', function () {
return this.res.send.calledWith(400).should.equal(true)
})
})
return describe('when the doc body is too large', function() {
beforeEach(function() {
return describe('when the doc body is too large', function () {
beforeEach(function () {
this.req.body = {
lines: (this.lines = Array(2049).fill('a'.repeat(1024))),
version: (this.version = 42),
@@ -420,18 +420,18 @@ describe('HttpController', function() {
return this.HttpController.updateDoc(this.req, this.res, this.next)
})
it('should return a 413 (too large) response', function() {
it('should return a 413 (too large) response', function () {
return sinon.assert.calledWith(this.res.status, 413)
})
return it('should report that the document body is too large', function() {
return it('should report that the document body is too large', function () {
return sinon.assert.calledWith(this.res.send, 'document body too large')
})
})
})
describe('deleteDoc', function() {
beforeEach(function() {
describe('deleteDoc', function () {
beforeEach(function () {
this.req.params = {
project_id: this.project_id,
doc_id: this.doc_id
@@ -440,50 +440,50 @@ describe('HttpController', function() {
return this.HttpController.deleteDoc(this.req, this.res, this.next)
})
it('should delete the document', function() {
it('should delete the document', function () {
return this.DocManager.deleteDoc
.calledWith(this.project_id, this.doc_id)
.should.equal(true)
})
return it('should return a 204 (No Content)', function() {
return it('should return a 204 (No Content)', function () {
return this.res.send.calledWith(204).should.equal(true)
})
})
describe('archiveAllDocs', function() {
beforeEach(function() {
describe('archiveAllDocs', function () {
beforeEach(function () {
this.req.params = { project_id: this.project_id }
this.DocArchiveManager.archiveAllDocs = sinon.stub().callsArg(1)
return this.HttpController.archiveAllDocs(this.req, this.res, this.next)
})
it('should archive the project', function() {
it('should archive the project', function () {
return this.DocArchiveManager.archiveAllDocs
.calledWith(this.project_id)
.should.equal(true)
})
return it('should return a 204 (No Content)', function() {
return it('should return a 204 (No Content)', function () {
return this.res.send.calledWith(204).should.equal(true)
})
})
return describe('destroyAllDocs', function() {
beforeEach(function() {
return describe('destroyAllDocs', function () {
beforeEach(function () {
this.req.params = { project_id: this.project_id }
this.DocArchiveManager.destroyAllDocs = sinon.stub().callsArg(1)
return this.HttpController.destroyAllDocs(this.req, this.res, this.next)
})
it('should destroy the docs', function() {
it('should destroy the docs', function () {
return sinon.assert.calledWith(
this.DocArchiveManager.destroyAllDocs,
this.project_id
)
})
return it('should return 204', function() {
return it('should return 204', function () {
return sinon.assert.calledWith(this.res.send, 204)
})
})
@@ -19,8 +19,8 @@ const modulePath = require('path').join(
const { ObjectId } = require('mongojs')
const { assert } = require('chai')
describe('MongoManager', function() {
beforeEach(function() {
describe('MongoManager', function () {
beforeEach(function () {
this.MongoManager = SandboxedModule.require(modulePath, {
requires: {
'./mongojs': {
@@ -37,8 +37,8 @@ describe('MongoManager', function() {
return (this.stubbedErr = new Error('hello world'))
})
describe('findDoc', function() {
beforeEach(function() {
describe('findDoc', function () {
beforeEach(function () {
this.doc = { name: 'mock-doc' }
this.db.docs.find = sinon.stub().callsArgWith(2, null, [this.doc])
this.filter = { lines: true }
@@ -50,7 +50,7 @@ describe('MongoManager', function() {
)
})
it('should find the doc', function() {
it('should find the doc', function () {
return this.db.docs.find
.calledWith(
{
@@ -62,13 +62,13 @@ describe('MongoManager', function() {
.should.equal(true)
})
return it('should call the callback with the doc', function() {
return it('should call the callback with the doc', function () {
return this.callback.calledWith(null, this.doc).should.equal(true)
})
})
describe('getProjectsDocs', function() {
beforeEach(function() {
describe('getProjectsDocs', function () {
beforeEach(function () {
this.filter = { lines: true }
this.doc1 = { name: 'mock-doc1' }
this.doc2 = { name: 'mock-doc2' }
@@ -79,8 +79,8 @@ describe('MongoManager', function() {
.callsArgWith(2, null, [this.doc, this.doc3, this.doc4]))
})
describe('with included_deleted = false', function() {
beforeEach(function() {
describe('with included_deleted = false', function () {
beforeEach(function () {
return this.MongoManager.getProjectsDocs(
this.project_id,
{ include_deleted: false },
@@ -89,7 +89,7 @@ describe('MongoManager', function() {
)
})
it('should find the non-deleted docs via the project_id', function() {
it('should find the non-deleted docs via the project_id', function () {
return this.db.docs.find
.calledWith(
{
@@ -101,15 +101,15 @@ describe('MongoManager', function() {
.should.equal(true)
})
return it('should call the callback with the docs', function() {
return it('should call the callback with the docs', function () {
return this.callback
.calledWith(null, [this.doc, this.doc3, this.doc4])
.should.equal(true)
})
})
return describe('with included_deleted = true', function() {
beforeEach(function() {
return describe('with included_deleted = true', function () {
beforeEach(function () {
return this.MongoManager.getProjectsDocs(
this.project_id,
{ include_deleted: true },
@@ -118,7 +118,7 @@ describe('MongoManager', function() {
)
})
it('should find all via the project_id', function() {
it('should find all via the project_id', function () {
return this.db.docs.find
.calledWith(
{
@@ -129,7 +129,7 @@ describe('MongoManager', function() {
.should.equal(true)
})
return it('should call the callback with the docs', function() {
return it('should call the callback with the docs', function () {
return this.callback
.calledWith(null, [this.doc, this.doc3, this.doc4])
.should.equal(true)
@@ -137,18 +137,18 @@ describe('MongoManager', function() {
})
})
describe('upsertIntoDocCollection', function() {
beforeEach(function() {
describe('upsertIntoDocCollection', function () {
beforeEach(function () {
this.db.docs.update = sinon.stub().callsArgWith(3, this.stubbedErr)
return (this.oldRev = 77)
})
it('should upsert the document', function(done) {
it('should upsert the document', function (done) {
return this.MongoManager.upsertIntoDocCollection(
this.project_id,
this.doc_id,
{ lines: this.lines },
err => {
(err) => {
const args = this.db.docs.update.args[0]
assert.deepEqual(args[0], { _id: ObjectId(this.doc_id) })
assert.equal(args[1].$set.lines, this.lines)
@@ -159,12 +159,12 @@ describe('MongoManager', function() {
)
})
return it('should return the error', function(done) {
return it('should return the error', function (done) {
return this.MongoManager.upsertIntoDocCollection(
this.project_id,
this.doc_id,
{ lines: this.lines },
err => {
(err) => {
err.should.equal(this.stubbedErr)
return done()
}
@@ -172,17 +172,17 @@ describe('MongoManager', function() {
})
})
describe('markDocAsDeleted', function() {
beforeEach(function() {
describe('markDocAsDeleted', function () {
beforeEach(function () {
this.db.docs.update = sinon.stub().callsArgWith(2, this.stubbedErr)
return (this.oldRev = 77)
})
it('should process the update', function(done) {
it('should process the update', function (done) {
return this.MongoManager.markDocAsDeleted(
this.project_id,
this.doc_id,
err => {
(err) => {
const args = this.db.docs.update.args[0]
assert.deepEqual(args[0], {
_id: ObjectId(this.doc_id),
@@ -194,11 +194,11 @@ describe('MongoManager', function() {
)
})
return it('should return the error', function(done) {
return it('should return the error', function (done) {
return this.MongoManager.markDocAsDeleted(
this.project_id,
this.doc_id,
err => {
(err) => {
err.should.equal(this.stubbedErr)
return done()
}
@@ -206,59 +206,59 @@ describe('MongoManager', function() {
})
})
describe('destroyDoc', function() {
beforeEach(function(done) {
describe('destroyDoc', function () {
beforeEach(function (done) {
this.db.docs.remove = sinon.stub().yields()
this.db.docOps.remove = sinon.stub().yields()
return this.MongoManager.destroyDoc('123456789012', done)
})
it('should destroy the doc', function() {
it('should destroy the doc', function () {
return sinon.assert.calledWith(this.db.docs.remove, {
_id: ObjectId('123456789012')
})
})
return it('should destroy the docOps', function() {
return it('should destroy the docOps', function () {
return sinon.assert.calledWith(this.db.docOps.remove, {
doc_id: ObjectId('123456789012')
})
})
})
describe('getDocVersion', function() {
describe('when the doc exists', function() {
beforeEach(function() {
describe('getDocVersion', function () {
describe('when the doc exists', function () {
beforeEach(function () {
this.doc = { version: (this.version = 42) }
this.db.docOps.find = sinon.stub().callsArgWith(2, null, [this.doc])
return this.MongoManager.getDocVersion(this.doc_id, this.callback)
})
it('should look for the doc in the database', function() {
it('should look for the doc in the database', function () {
return this.db.docOps.find
.calledWith({ doc_id: ObjectId(this.doc_id) }, { version: 1 })
.should.equal(true)
})
return it('should call the callback with the version', function() {
return it('should call the callback with the version', function () {
return this.callback.calledWith(null, this.version).should.equal(true)
})
})
return describe("when the doc doesn't exist", function() {
beforeEach(function() {
return describe("when the doc doesn't exist", function () {
beforeEach(function () {
this.db.docOps.find = sinon.stub().callsArgWith(2, null, [])
return this.MongoManager.getDocVersion(this.doc_id, this.callback)
})
return it('should call the callback with 0', function() {
return it('should call the callback with 0', function () {
return this.callback.calledWith(null, 0).should.equal(true)
})
})
})
return describe('setDocVersion', function() {
beforeEach(function() {
return describe('setDocVersion', function () {
beforeEach(function () {
this.version = 42
this.db.docOps.update = sinon.stub().callsArg(3)
return this.MongoManager.setDocVersion(
@@ -268,7 +268,7 @@ describe('MongoManager', function() {
)
})
it('should update the doc version', function() {
it('should update the doc version', function () {
return this.db.docOps.update
.calledWith(
{
@@ -286,7 +286,7 @@ describe('MongoManager', function() {
.should.equal(true)
})
return it('should call the callback', function() {
return it('should call the callback', function () {
return this.callback.called.should.equal(true)
})
})
@@ -22,8 +22,8 @@ const { ObjectId } = require('mongojs')
const { assert } = require('chai')
const _ = require('underscore')
describe('RangeManager', function() {
beforeEach(function() {
describe('RangeManager', function () {
beforeEach(function () {
return (this.RangeManager = SandboxedModule.require(modulePath, {
requires: {
'./mongojs': {
@@ -33,8 +33,8 @@ describe('RangeManager', function() {
}))
})
describe('jsonRangesToMongo', function() {
it('should convert ObjectIds and dates to proper objects', function() {
describe('jsonRangesToMongo', function () {
it('should convert ObjectIds and dates to proper objects', function () {
const change_id = ObjectId().toString()
const comment_id = ObjectId().toString()
const user_id = ObjectId().toString()
@@ -77,7 +77,7 @@ describe('RangeManager', function() {
})
})
it('should leave malformed ObjectIds as they are', function() {
it('should leave malformed ObjectIds as they are', function () {
const change_id = 'foo'
const comment_id = 'bar'
const user_id = 'baz'
@@ -112,7 +112,7 @@ describe('RangeManager', function() {
})
})
return it('should be consistent when transformed through json -> mongo -> json', function() {
return it('should be consistent when transformed through json -> mongo -> json', function () {
const change_id = ObjectId().toString()
const comment_id = ObjectId().toString()
const user_id = ObjectId().toString()
@@ -144,8 +144,8 @@ describe('RangeManager', function() {
})
})
return describe('shouldUpdateRanges', function() {
beforeEach(function() {
return describe('shouldUpdateRanges', function () {
beforeEach(function () {
this.ranges = {
changes: [
{
@@ -169,16 +169,16 @@ describe('RangeManager', function() {
))
})
describe('with a blank new range', function() {
return it('should throw an error', function() {
describe('with a blank new range', function () {
return it('should throw an error', function () {
return expect(() => {
return this.RangeManager.shouldUpdateRanges(this.ranges, null)
}).to.throw(Error)
})
})
describe('with a blank old range', function() {
return it('should treat it like {}', function() {
describe('with a blank old range', function () {
return it('should treat it like {}', function () {
this.RangeManager.shouldUpdateRanges(null, {}).should.equal(false)
return this.RangeManager.shouldUpdateRanges(
null,
@@ -187,8 +187,8 @@ describe('RangeManager', function() {
})
})
describe('with no changes', function() {
return it('should return false', function() {
describe('with no changes', function () {
return it('should return false', function () {
return this.RangeManager.shouldUpdateRanges(
this.ranges,
this.ranges_copy
@@ -196,8 +196,8 @@ describe('RangeManager', function() {
})
})
return describe('with changes', function() {
it('should return true when the change id changes', function() {
return describe('with changes', function () {
it('should return true when the change id changes', function () {
this.ranges_copy.changes[0].id = ObjectId()
return this.RangeManager.shouldUpdateRanges(
this.ranges,
@@ -205,7 +205,7 @@ describe('RangeManager', function() {
).should.equal(true)
})
it('should return true when the change user id changes', function() {
it('should return true when the change user id changes', function () {
this.ranges_copy.changes[0].metadata.user_id = ObjectId()
return this.RangeManager.shouldUpdateRanges(
this.ranges,
@@ -213,7 +213,7 @@ describe('RangeManager', function() {
).should.equal(true)
})
it('should return true when the change ts changes', function() {
it('should return true when the change ts changes', function () {
this.ranges_copy.changes[0].metadata.ts = new Date(Date.now() + 1000)
return this.RangeManager.shouldUpdateRanges(
this.ranges,
@@ -221,7 +221,7 @@ describe('RangeManager', function() {
).should.equal(true)
})
it('should return true when the change op changes', function() {
it('should return true when the change op changes', function () {
this.ranges_copy.changes[0].op.i = 'bar'
return this.RangeManager.shouldUpdateRanges(
this.ranges,
@@ -229,7 +229,7 @@ describe('RangeManager', function() {
).should.equal(true)
})
it('should return true when the comment id changes', function() {
it('should return true when the comment id changes', function () {
this.ranges_copy.comments[0].id = ObjectId()
return this.RangeManager.shouldUpdateRanges(
this.ranges,
@@ -237,7 +237,7 @@ describe('RangeManager', function() {
).should.equal(true)
})
it('should return true when the comment offset changes', function() {
it('should return true when the comment offset changes', function () {
this.ranges_copy.comments[0].op.p = 17
return this.RangeManager.shouldUpdateRanges(
this.ranges,
@@ -245,7 +245,7 @@ describe('RangeManager', function() {
).should.equal(true)
})
return it('should return true when the comment content changes', function() {
return it('should return true when the comment content changes', function () {
this.ranges_copy.comments[0].op.c = 'bar'
return this.RangeManager.shouldUpdateRanges(
this.ranges,