2020-02-16 09:03:03 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-16 09:03:02 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-16 09:03:09 -05:00
|
|
|
const sinon = require('sinon')
|
2020-08-24 05:01:08 -04:00
|
|
|
const { ObjectId } = require('mongodb')
|
2020-02-16 09:03:09 -05:00
|
|
|
const async = require('async')
|
|
|
|
const DocstoreApp = require('./helpers/DocstoreApp')
|
2014-04-30 08:06:12 -04:00
|
|
|
|
2020-02-16 09:03:09 -05:00
|
|
|
const DocstoreClient = require('./helpers/DocstoreClient')
|
2014-04-30 08:06:12 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('Getting all docs', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
this.project_id = ObjectId()
|
|
|
|
this.docs = [
|
|
|
|
{
|
|
|
|
_id: ObjectId(),
|
|
|
|
lines: ['one', 'two', 'three'],
|
|
|
|
ranges: { mock: 'one' },
|
2021-07-13 07:04:48 -04:00
|
|
|
rev: 2,
|
2020-02-16 09:03:09 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: ObjectId(),
|
|
|
|
lines: ['aaa', 'bbb', 'ccc'],
|
|
|
|
ranges: { mock: 'two' },
|
2021-07-13 07:04:48 -04:00
|
|
|
rev: 4,
|
2020-02-16 09:03:09 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: ObjectId(),
|
|
|
|
lines: ['111', '222', '333'],
|
|
|
|
ranges: { mock: 'three' },
|
2021-07-13 07:04:48 -04:00
|
|
|
rev: 6,
|
|
|
|
},
|
2020-02-16 09:03:09 -05:00
|
|
|
]
|
|
|
|
this.deleted_doc = {
|
|
|
|
_id: ObjectId(),
|
|
|
|
lines: ['deleted'],
|
|
|
|
ranges: { mock: 'four' },
|
2021-07-13 07:04:48 -04:00
|
|
|
rev: 8,
|
2020-02-16 09:03:09 -05:00
|
|
|
}
|
|
|
|
const version = 42
|
2021-07-13 07:04:48 -04:00
|
|
|
const jobs = Array.from(this.docs).map(doc =>
|
|
|
|
(doc => {
|
|
|
|
return callback => {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.createDoc(
|
|
|
|
this.project_id,
|
|
|
|
doc._id,
|
|
|
|
doc.lines,
|
|
|
|
version,
|
|
|
|
doc.ranges,
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})(doc)
|
|
|
|
)
|
2021-07-13 07:04:48 -04:00
|
|
|
jobs.push(cb => {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.createDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.deleted_doc._id,
|
|
|
|
this.deleted_doc.lines,
|
|
|
|
version,
|
|
|
|
this.deleted_doc.ranges,
|
2021-07-13 07:04:48 -04:00
|
|
|
err => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (err) return done(err)
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.deleteDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.deleted_doc._id,
|
|
|
|
cb
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2021-07-13 07:04:48 -04:00
|
|
|
jobs.unshift(cb => DocstoreApp.ensureRunning(cb))
|
2020-02-16 09:03:09 -05:00
|
|
|
return async.series(jobs, done)
|
|
|
|
})
|
2016-12-09 09:37:24 -05:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('getAllDocs should return all the (non-deleted) docs', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getAllDocs(this.project_id, (error, res, docs) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
docs.length.should.equal(this.docs.length)
|
|
|
|
for (let i = 0; i < docs.length; i++) {
|
|
|
|
const doc = docs[i]
|
|
|
|
doc.lines.should.deep.equal(this.docs[i].lines)
|
|
|
|
}
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
2015-01-27 12:05:07 -05:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('getAllRanges should return all the (non-deleted) doc ranges', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getAllRanges(this.project_id, (error, res, docs) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
docs.length.should.equal(this.docs.length)
|
|
|
|
for (let i = 0; i < docs.length; i++) {
|
|
|
|
const doc = docs[i]
|
|
|
|
doc.ranges.should.deep.equal(this.docs[i].ranges)
|
|
|
|
}
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|