2020-08-28 08:13:19 -04:00
|
|
|
const { db, ObjectId } = require('../../../app/js/mongodb')
|
2021-03-12 17:16:01 -05:00
|
|
|
const { expect } = require('chai')
|
2020-02-16 09:03:09 -05:00
|
|
|
const DocstoreApp = require('./helpers/DocstoreApp')
|
2020-07-23 14:43:33 -04:00
|
|
|
const Errors = require('../../../app/js/Errors')
|
2021-07-12 12:47:20 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2023-07-21 07:04:10 -04:00
|
|
|
const { Storage } = require('@google-cloud/storage')
|
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
|
|
|
|
2021-02-15 08:13:48 -05:00
|
|
|
function deleteTestSuite(deleteDoc) {
|
2023-07-21 07:04:10 -04:00
|
|
|
before(async function () {
|
|
|
|
// Create buckets needed by the archiving part of these tests
|
|
|
|
const storage = new Storage(Settings.docstore.gcs.endpoint)
|
|
|
|
await storage.createBucket(Settings.docstore.bucket)
|
|
|
|
await storage.createBucket(`${Settings.docstore.bucket}-deleted`)
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
// Tear down the buckets created above
|
|
|
|
const storage = new Storage(Settings.docstore.gcs.endpoint)
|
|
|
|
await storage.bucket(Settings.docstore.bucket).deleteFiles()
|
|
|
|
await storage.bucket(Settings.docstore.bucket).delete()
|
|
|
|
await storage.bucket(`${Settings.docstore.bucket}-deleted`).deleteFiles()
|
|
|
|
await storage.bucket(`${Settings.docstore.bucket}-deleted`).delete()
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
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 = []
|
2022-04-26 07:16:36 -04:00
|
|
|
DocstoreApp.ensureRunning(() => {
|
|
|
|
DocstoreClient.createDoc(
|
2020-02-16 09:03:09 -05:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
2021-07-13 07:04:48 -04:00
|
|
|
error => {
|
2022-04-26 07:16:36 -04:00
|
|
|
if (error) {
|
2020-02-16 09:03:09 -05:00
|
|
|
throw error
|
|
|
|
}
|
2022-04-26 07:16:36 -04:00
|
|
|
done()
|
2020-02-16 09:03:09 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2014-04-29 11:36:10 -04:00
|
|
|
|
2021-01-12 12:29:06 -05:00
|
|
|
it('should show as not deleted on /deleted', function (done) {
|
|
|
|
DocstoreClient.isDocDeleted(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
(error, res, body) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
expect(res.statusCode).to.equal(200)
|
|
|
|
expect(body).to.have.property('deleted').to.equal(false)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the doc exists', function () {
|
|
|
|
beforeEach(function (done) {
|
2021-02-15 08:13:48 -05:00
|
|
|
deleteDoc(this.project_id, this.doc_id, (error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2021-02-15 08:13:48 -05:00
|
|
|
this.res = res
|
2022-04-26 07:16:36 -04:00
|
|
|
done()
|
2021-02-15 08:13:48 -05:00
|
|
|
})
|
2020-02-16 09:03:09 -05:00
|
|
|
})
|
2014-04-29 11:36:10 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
afterEach(function (done) {
|
2023-12-13 04:38:54 -05:00
|
|
|
db.docs.deleteOne({ _id: this.doc_id }, done)
|
2020-02-16 09:03:09 -05:00
|
|
|
})
|
2014-04-29 11:36:10 -04:00
|
|
|
|
2021-01-12 12:29:06 -05:00
|
|
|
it('should mark the doc as deleted on /deleted', function (done) {
|
|
|
|
DocstoreClient.isDocDeleted(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
(error, res, body) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
expect(res.statusCode).to.equal(200)
|
|
|
|
expect(body).to.have.property('deleted').to.equal(true)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-01-04 08:36:19 -05:00
|
|
|
it('should insert a deleted doc into the docs collection', function (done) {
|
2022-04-26 07:16:36 -04:00
|
|
|
db.docs.find({ _id: this.doc_id }).toArray((error, docs) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
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)
|
2022-04-26 07:16:36 -04:00
|
|
|
done()
|
2020-02-16 09:03:09 -05:00
|
|
|
})
|
|
|
|
})
|
2021-01-04 08:36:19 -05:00
|
|
|
|
|
|
|
it('should not export the doc to s3', function (done) {
|
|
|
|
setTimeout(() => {
|
2021-07-13 07:04:48 -04:00
|
|
|
DocstoreClient.getS3Doc(this.project_id, this.doc_id, error => {
|
2021-01-04 08:36:19 -05:00
|
|
|
expect(error).to.be.instanceOf(Errors.NotFoundError)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
}, 1000)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when archiveOnSoftDelete is enabled', function () {
|
|
|
|
let archiveOnSoftDelete
|
2021-02-15 08:13:48 -05:00
|
|
|
beforeEach('overwrite settings', function () {
|
2021-01-04 08:36:19 -05:00
|
|
|
archiveOnSoftDelete = Settings.docstore.archiveOnSoftDelete
|
|
|
|
Settings.docstore.archiveOnSoftDelete = true
|
|
|
|
})
|
2021-02-15 08:13:48 -05:00
|
|
|
afterEach('restore settings', function () {
|
2021-01-04 08:36:19 -05:00
|
|
|
Settings.docstore.archiveOnSoftDelete = archiveOnSoftDelete
|
|
|
|
})
|
|
|
|
|
2021-02-15 08:13:48 -05:00
|
|
|
beforeEach('delete Doc', function (done) {
|
|
|
|
deleteDoc(this.project_id, this.doc_id, (error, res) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2021-01-04 08:36:19 -05:00
|
|
|
this.res = res
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
beforeEach(function waitForBackgroundFlush(done) {
|
|
|
|
setTimeout(done, 500)
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function cleanupDoc(done) {
|
2023-12-13 04:38:54 -05:00
|
|
|
db.docs.deleteOne({ _id: this.doc_id }, done)
|
2021-01-04 08:36:19 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should set the deleted flag in the doc', function (done) {
|
|
|
|
db.docs.findOne({ _id: this.doc_id }, (error, doc) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
expect(doc.deleted).to.equal(true)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should set inS3 and unset lines and ranges in the doc', function (done) {
|
|
|
|
db.docs.findOne({ _id: this.doc_id }, (error, doc) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
expect(doc.lines).to.not.exist
|
|
|
|
expect(doc.ranges).to.not.exist
|
|
|
|
expect(doc.inS3).to.equal(true)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should set the doc in s3 correctly', function (done) {
|
2022-04-26 07:16:36 -04:00
|
|
|
DocstoreClient.getS3Doc(this.project_id, this.doc_id, (error, s3doc) => {
|
2021-01-04 08:36:19 -05:00
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
2022-04-26 07:16:36 -04:00
|
|
|
expect(s3doc.lines).to.deep.equal(this.lines)
|
|
|
|
expect(s3doc.ranges).to.deep.equal(this.ranges)
|
2021-01-04 08:36:19 -05:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2020-02-16 09:03:09 -05:00
|
|
|
})
|
2014-04-29 11:36:10 -04:00
|
|
|
|
2021-01-12 12:29:06 -05:00
|
|
|
describe('when the doc exists in another project', function () {
|
2023-12-13 04:38:54 -05:00
|
|
|
const otherProjectId = new ObjectId()
|
2021-01-12 12:29:06 -05:00
|
|
|
|
|
|
|
it('should show as not existing on /deleted', function (done) {
|
|
|
|
DocstoreClient.isDocDeleted(otherProjectId, this.doc_id, (error, res) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
expect(res.statusCode).to.equal(404)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return a 404 when trying to delete', function (done) {
|
2021-02-15 08:13:48 -05:00
|
|
|
deleteDoc(otherProjectId, this.doc_id, (error, res) => {
|
2021-01-12 12:29:06 -05:00
|
|
|
if (error) return done(error)
|
|
|
|
expect(res.statusCode).to.equal(404)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-04-26 07:16:36 -04:00
|
|
|
describe('when the doc does not exist', function () {
|
2021-01-12 12:29:06 -05:00
|
|
|
it('should show as not existing on /deleted', function (done) {
|
2023-12-13 04:38:54 -05:00
|
|
|
const missingDocId = new ObjectId()
|
2021-01-12 12:29:06 -05:00
|
|
|
DocstoreClient.isDocDeleted(
|
|
|
|
this.project_id,
|
2022-04-26 07:16:36 -04:00
|
|
|
missingDocId,
|
2021-01-12 12:29:06 -05:00
|
|
|
(error, res) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
expect(res.statusCode).to.equal(404)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2022-04-26 07:16:36 -04:00
|
|
|
it('should return a 404', function (done) {
|
2023-12-13 04:38:54 -05:00
|
|
|
const missingDocId = new ObjectId()
|
2022-04-26 07:16:36 -04:00
|
|
|
deleteDoc(this.project_id, missingDocId, (error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2021-02-15 08:13:48 -05:00
|
|
|
res.statusCode.should.equal(404)
|
2022-04-26 07:16:36 -04:00
|
|
|
done()
|
2021-02-15 08:13:48 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Delete via PATCH', function () {
|
|
|
|
deleteTestSuite(DocstoreClient.deleteDoc)
|
|
|
|
|
|
|
|
describe('when providing a custom doc name in the delete request', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
DocstoreClient.deleteDocWithName(
|
2020-02-16 09:03:09 -05:00
|
|
|
this.project_id,
|
2021-02-15 08:13:48 -05:00
|
|
|
this.doc_id,
|
|
|
|
'wombat.tex',
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should insert the doc name into the docs collection', function (done) {
|
|
|
|
db.docs.find({ _id: this.doc_id }).toArray((error, docs) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
expect(docs[0].name).to.equal('wombat.tex')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when providing a custom deletedAt date in the delete request', function () {
|
|
|
|
beforeEach('record date and delay', function (done) {
|
|
|
|
this.deletedAt = new Date()
|
|
|
|
setTimeout(done, 5)
|
|
|
|
})
|
|
|
|
|
|
|
|
beforeEach('perform deletion with past date', function (done) {
|
|
|
|
DocstoreClient.deleteDocWithDate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.deletedAt,
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should insert the date into the docs collection', function (done) {
|
|
|
|
db.docs.find({ _id: this.doc_id }).toArray((error, docs) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
expect(docs[0].deletedAt.toISOString()).to.equal(
|
|
|
|
this.deletedAt.toISOString()
|
|
|
|
)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when providing no doc name in the delete request', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
DocstoreClient.deleteDocWithName(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
'',
|
|
|
|
(error, res) => {
|
|
|
|
this.res = res
|
|
|
|
done(error)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should reject the request', function () {
|
|
|
|
expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when providing no date in the delete request', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
DocstoreClient.deleteDocWithDate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
'',
|
|
|
|
(error, res) => {
|
|
|
|
this.res = res
|
|
|
|
done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2021-02-15 08:13:48 -05:00
|
|
|
|
|
|
|
it('should reject the request', function () {
|
|
|
|
expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
2020-02-16 09:03:09 -05:00
|
|
|
})
|
2021-02-18 05:10:14 -05:00
|
|
|
|
|
|
|
describe('before deleting anything', function () {
|
|
|
|
it('should show nothing in deleted docs response', function (done) {
|
|
|
|
DocstoreClient.getAllDeletedDocs(
|
|
|
|
this.project_id,
|
|
|
|
(error, deletedDocs) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
expect(deletedDocs).to.deep.equal([])
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the doc gets a name on delete', function () {
|
|
|
|
beforeEach(function (done) {
|
2021-10-26 09:32:01 -04:00
|
|
|
this.deletedAt = new Date()
|
|
|
|
DocstoreClient.deleteDocWithDate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.deletedAt,
|
|
|
|
done
|
|
|
|
)
|
2021-02-18 05:10:14 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should show the doc in deleted docs response', function (done) {
|
|
|
|
DocstoreClient.getAllDeletedDocs(
|
|
|
|
this.project_id,
|
|
|
|
(error, deletedDocs) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
expect(deletedDocs).to.deep.equal([
|
2021-10-26 09:32:01 -04:00
|
|
|
{
|
|
|
|
_id: this.doc_id.toString(),
|
|
|
|
name: 'main.tex',
|
|
|
|
deletedAt: this.deletedAt.toISOString(),
|
|
|
|
},
|
2021-02-18 05:10:14 -05:00
|
|
|
])
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('after deleting multiple docs', function () {
|
|
|
|
beforeEach('create doc2', function (done) {
|
2023-12-13 04:38:54 -05:00
|
|
|
this.doc_id2 = new ObjectId()
|
2021-02-18 05:10:14 -05:00
|
|
|
DocstoreClient.createDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id2,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
beforeEach('delete doc2', function (done) {
|
2021-10-26 09:32:01 -04:00
|
|
|
this.deletedAt2 = new Date()
|
|
|
|
DocstoreClient.deleteDocWithDateAndName(
|
2021-02-18 05:10:14 -05:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id2,
|
2021-10-26 09:32:01 -04:00
|
|
|
this.deletedAt2,
|
2021-02-18 05:10:14 -05:00
|
|
|
'two.tex',
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
beforeEach('create doc3', function (done) {
|
2023-12-13 04:38:54 -05:00
|
|
|
this.doc_id3 = new ObjectId()
|
2021-02-18 05:10:14 -05:00
|
|
|
DocstoreClient.createDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id3,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
beforeEach('delete doc3', function (done) {
|
2021-10-26 09:32:01 -04:00
|
|
|
this.deletedAt3 = new Date()
|
|
|
|
DocstoreClient.deleteDocWithDateAndName(
|
2021-02-18 05:10:14 -05:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id3,
|
2021-10-26 09:32:01 -04:00
|
|
|
this.deletedAt3,
|
2021-02-18 05:10:14 -05:00
|
|
|
'three.tex',
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
it('should show all the docs as deleted', function (done) {
|
|
|
|
DocstoreClient.getAllDeletedDocs(
|
|
|
|
this.project_id,
|
|
|
|
(error, deletedDocs) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
|
|
|
|
expect(deletedDocs).to.deep.equal([
|
2021-10-26 09:32:01 -04:00
|
|
|
{
|
|
|
|
_id: this.doc_id3.toString(),
|
|
|
|
name: 'three.tex',
|
|
|
|
deletedAt: this.deletedAt3.toISOString(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: this.doc_id2.toString(),
|
|
|
|
name: 'two.tex',
|
|
|
|
deletedAt: this.deletedAt2.toISOString(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: this.doc_id.toString(),
|
|
|
|
name: 'main.tex',
|
|
|
|
deletedAt: this.deletedAt.toISOString(),
|
|
|
|
},
|
2021-02-18 05:10:14 -05:00
|
|
|
])
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with one more than max_deleted_docs permits', function () {
|
|
|
|
let maxDeletedDocsBefore
|
|
|
|
beforeEach(function () {
|
|
|
|
maxDeletedDocsBefore = Settings.max_deleted_docs
|
|
|
|
Settings.max_deleted_docs = 2
|
|
|
|
})
|
|
|
|
afterEach(function () {
|
|
|
|
Settings.max_deleted_docs = maxDeletedDocsBefore
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should omit the first deleted doc', function (done) {
|
|
|
|
DocstoreClient.getAllDeletedDocs(
|
|
|
|
this.project_id,
|
|
|
|
(error, deletedDocs) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
|
|
|
|
expect(deletedDocs).to.deep.equal([
|
2021-10-26 09:32:01 -04:00
|
|
|
{
|
|
|
|
_id: this.doc_id3.toString(),
|
|
|
|
name: 'three.tex',
|
|
|
|
deletedAt: this.deletedAt3.toISOString(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: this.doc_id2.toString(),
|
|
|
|
name: 'two.tex',
|
|
|
|
deletedAt: this.deletedAt2.toISOString(),
|
|
|
|
},
|
2021-02-18 05:10:14 -05:00
|
|
|
// dropped main.tex
|
|
|
|
])
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-02-16 09:03:09 -05:00
|
|
|
})
|
2014-04-29 11:36:10 -04:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe("Destroying a project's documents", function () {
|
2022-04-26 07:16:36 -04:00
|
|
|
beforeEach(function (done) {
|
2023-12-13 04:38:54 -05:00
|
|
|
this.project_id = new ObjectId()
|
|
|
|
this.doc_id = new ObjectId()
|
2022-04-26 07:16:36 -04:00
|
|
|
this.lines = ['original', 'lines']
|
|
|
|
this.version = 42
|
|
|
|
this.ranges = []
|
|
|
|
DocstoreApp.ensureRunning(() => {
|
|
|
|
DocstoreClient.createDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
error => {
|
|
|
|
if (error) {
|
|
|
|
throw error
|
2020-02-16 09:03:09 -05:00
|
|
|
}
|
2022-04-26 07:16:36 -04:00
|
|
|
done()
|
2020-02-16 09:03:09 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2022-04-26 07:16:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the doc exists', function () {
|
|
|
|
beforeEach(function (done) {
|
2024-01-22 09:45:18 -05:00
|
|
|
DocstoreClient.destroyAllDoc(this.project_id, done)
|
2022-04-26 07:16:36 -04:00
|
|
|
})
|
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) {
|
2022-04-26 07:16:36 -04:00
|
|
|
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([])
|
2022-04-26 07:16:36 -04:00
|
|
|
done()
|
2020-02-16 09:03:09 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-07-02 07:45:54 -04:00
|
|
|
|
2022-04-26 07:16:36 -04:00
|
|
|
describe('when the doc is archived', function () {
|
2020-05-28 09:20:54 -04:00
|
|
|
beforeEach(function (done) {
|
2022-04-26 07:16:36 -04:00
|
|
|
DocstoreClient.archiveAllDoc(this.project_id, err => {
|
|
|
|
if (err) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return done(err)
|
|
|
|
}
|
2022-04-26 07:16:36 -04:00
|
|
|
DocstoreClient.destroyAllDoc(this.project_id, done)
|
2020-02-16 09:03:09 -05:00
|
|
|
})
|
|
|
|
})
|
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) {
|
2022-04-26 07:16:36 -04:00
|
|
|
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([])
|
2022-04-26 07:16:36 -04:00
|
|
|
done()
|
2020-02-16 09:03:09 -05:00
|
|
|
})
|
|
|
|
})
|
2019-07-02 07:45:54 -04:00
|
|
|
|
2022-04-26 07:16:36 -04:00
|
|
|
it('should remove the doc contents from s3', function (done) {
|
|
|
|
DocstoreClient.getS3Doc(this.project_id, this.doc_id, error => {
|
2020-07-23 14:43:33 -04:00
|
|
|
expect(error).to.be.instanceOf(Errors.NotFoundError)
|
|
|
|
done()
|
|
|
|
})
|
2020-02-16 09:03:09 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|