2020-02-16 09:03:03 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
handle-callback-err,
|
|
|
|
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 chai = require('chai')
|
|
|
|
chai.should()
|
2020-08-24 05:01:08 -04:00
|
|
|
const { getCollection, ObjectId } = require('../../../app/js/mongodb')
|
2020-02-16 09:03:09 -05:00
|
|
|
const { expect } = chai
|
|
|
|
const DocstoreApp = require('./helpers/DocstoreApp')
|
2020-07-23 14:43:33 -04:00
|
|
|
const Errors = require('../../../app/js/Errors')
|
2014-04-29 11:36:10 -04:00
|
|
|
|
2020-02-16 09:03:09 -05:00
|
|
|
const DocstoreClient = require('./helpers/DocstoreClient')
|
2014-04-29 11:36:10 -04:00
|
|
|
|
2020-08-24 05:01:08 -04:00
|
|
|
let db
|
|
|
|
before(async function () {
|
|
|
|
db = {
|
|
|
|
docs: await getCollection('docs'),
|
|
|
|
docOps: await getCollection('docOps')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('Deleting a doc', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
this.project_id = ObjectId()
|
|
|
|
this.doc_id = ObjectId()
|
|
|
|
this.lines = ['original', 'lines']
|
|
|
|
this.version = 42
|
|
|
|
this.ranges = []
|
|
|
|
return DocstoreApp.ensureRunning(() => {
|
|
|
|
return DocstoreClient.createDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
2020-05-28 09:20:54 -04:00
|
|
|
(error) => {
|
2020-02-16 09:03:09 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2014-04-29 11:36:10 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the doc exists', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.deleteDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
(error, res, doc) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2014-04-29 11:36:10 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
afterEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return db.docs.remove({ _id: this.doc_id }, done)
|
|
|
|
})
|
2014-04-29 11:36:10 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should insert a deleted doc into the docs collection', function (done) {
|
2020-08-24 05:01:08 -04:00
|
|
|
return db.docs.find({ _id: this.doc_id }).toArray((error, docs) => {
|
2020-02-16 09:03:09 -05:00
|
|
|
docs[0]._id.should.deep.equal(this.doc_id)
|
|
|
|
docs[0].lines.should.deep.equal(this.lines)
|
|
|
|
docs[0].deleted.should.equal(true)
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-04-29 11:36:10 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return describe('when the doc does not exist', function () {
|
|
|
|
return it('should return a 404', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
const missing_doc_id = ObjectId()
|
|
|
|
return DocstoreClient.deleteDoc(
|
|
|
|
this.project_id,
|
|
|
|
missing_doc_id,
|
|
|
|
(error, res, doc) => {
|
|
|
|
res.statusCode.should.equal(404)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-04-29 11:36:10 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe("Destroying a project's documents", function () {
|
|
|
|
describe('when the doc exists', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return db.docOps.insert(
|
|
|
|
{ doc_id: ObjectId(this.doc_id), version: 1 },
|
2020-05-28 09:20:54 -04:00
|
|
|
function (err) {
|
2020-02-16 09:03:09 -05:00
|
|
|
if (err != null) {
|
|
|
|
return done(err)
|
|
|
|
}
|
|
|
|
return DocstoreClient.destroyAllDoc(this.project_id, done)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2019-07-02 07:45:54 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should remove the doc from the docs collection', function (done) {
|
2020-08-24 05:01:08 -04:00
|
|
|
return db.docs.find({ _id: this.doc_id }).toArray((err, docs) => {
|
2020-02-16 09:03:09 -05:00
|
|
|
expect(err).not.to.exist
|
|
|
|
expect(docs).to.deep.equal([])
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
2019-07-02 07:45:54 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should remove the docOps from the docOps collection', function (done) {
|
2020-08-24 05:01:08 -04:00
|
|
|
return db.docOps.find({ doc_id: this.doc_id }).toArray((err, docOps) => {
|
2020-02-16 09:03:09 -05:00
|
|
|
expect(err).not.to.exist
|
|
|
|
expect(docOps).to.deep.equal([])
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-07-02 07:45:54 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return describe('when the doc is archived', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-08-24 05:01:08 -04:00
|
|
|
return DocstoreClient.archiveAllDoc(this.project_id, (err) => {
|
2020-02-16 09:03:09 -05:00
|
|
|
if (err != null) {
|
|
|
|
return done(err)
|
|
|
|
}
|
|
|
|
return DocstoreClient.destroyAllDoc(this.project_id, done)
|
|
|
|
})
|
|
|
|
})
|
2019-07-02 07:45:54 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should remove the doc from the docs collection', function (done) {
|
2020-08-24 05:01:08 -04:00
|
|
|
return db.docs.find({ _id: this.doc_id }).toArray((err, docs) => {
|
2020-02-16 09:03:09 -05:00
|
|
|
expect(err).not.to.exist
|
|
|
|
expect(docs).to.deep.equal([])
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
2019-07-02 07:45:54 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should remove the docOps from the docOps collection', function (done) {
|
2020-08-24 05:01:08 -04:00
|
|
|
return db.docOps.find({ doc_id: this.doc_id }).toArray((err, docOps) => {
|
2020-02-16 09:03:09 -05:00
|
|
|
expect(err).not.to.exist
|
|
|
|
expect(docOps).to.deep.equal([])
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
2019-07-02 07:45:54 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should remove the doc contents from s3', function (done) {
|
2020-07-23 14:43:33 -04:00
|
|
|
return DocstoreClient.getS3Doc(this.project_id, this.doc_id, (error) => {
|
|
|
|
expect(error).to.be.instanceOf(Errors.NotFoundError)
|
|
|
|
done()
|
|
|
|
})
|
2020-02-16 09:03:09 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|