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:
|
|
|
|
* 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 DocstoreApp = require('./helpers/DocstoreApp')
|
2014-04-29 06:49:09 -04:00
|
|
|
|
2020-02-16 09:03:09 -05:00
|
|
|
const DocstoreClient = require('./helpers/DocstoreClient')
|
2014-04-29 06:49:09 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('Getting a doc', function () {
|
|
|
|
beforeEach(function (done) {
|
2023-12-13 04:38:54 -05:00
|
|
|
this.project_id = new ObjectId()
|
|
|
|
this.doc_id = new ObjectId()
|
2020-02-16 09:03:09 -05:00
|
|
|
this.lines = ['original', 'lines']
|
|
|
|
this.version = 42
|
|
|
|
this.ranges = {
|
|
|
|
changes: [
|
|
|
|
{
|
2023-12-13 04:38:54 -05:00
|
|
|
id: new ObjectId().toString(),
|
2020-02-16 09:03:09 -05:00
|
|
|
op: { i: 'foo', p: 3 },
|
|
|
|
meta: {
|
2023-12-13 04:38:54 -05:00
|
|
|
user_id: new ObjectId().toString(),
|
2021-07-13 07:04:48 -04:00
|
|
|
ts: new Date().toString(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-02-16 09:03:09 -05:00
|
|
|
}
|
|
|
|
return DocstoreApp.ensureRunning(() => {
|
|
|
|
return DocstoreClient.createDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
2021-07-13 07:04:48 -04:00
|
|
|
error => {
|
2020-02-16 09:03:09 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2014-04-29 06:49:09 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the doc exists', function () {
|
|
|
|
return it('should get the doc lines and version', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.lines)
|
|
|
|
doc.version.should.equal(this.version)
|
|
|
|
doc.ranges.should.deep.equal(this.ranges)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2014-04-29 06:49:09 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the doc does not exist', function () {
|
|
|
|
return it('should return a 404', function (done) {
|
2023-12-13 04:38:54 -05:00
|
|
|
const missingDocId = new ObjectId()
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
2023-03-16 07:58:12 -04:00
|
|
|
missingDocId,
|
2020-02-16 09:03:09 -05:00
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
res.statusCode.should.equal(404)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2014-04-29 06:49:09 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return describe('when the doc is a deleted doc', function () {
|
|
|
|
beforeEach(function (done) {
|
2023-12-13 04:38:54 -05:00
|
|
|
this.deleted_doc_id = new ObjectId()
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.createDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.deleted_doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
2021-07-13 07:04:48 -04:00
|
|
|
error => {
|
2020-02-16 09:03:09 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
return DocstoreClient.deleteDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.deleted_doc_id,
|
|
|
|
done
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2014-06-06 07:37:42 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return the doc', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.deleted_doc_id,
|
|
|
|
{ include_deleted: true },
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.lines)
|
|
|
|
doc.version.should.equal(this.version)
|
|
|
|
doc.ranges.should.deep.equal(this.ranges)
|
|
|
|
doc.deleted.should.equal(true)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2014-06-06 07:37:42 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return a 404 when the query string is not set', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.deleted_doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
res.statusCode.should.equal(404)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|