|
|
@@ -207,6 +207,23 @@ function deleteTestSuite(deleteDoc) {
|
|
|
|
|
|
describe('Delete via DELETE', function () {
|
|
|
deleteTestSuite(DocstoreClient.deleteDocLegacy)
|
|
|
+
|
|
|
+ describe('when the doc gets no name on delete', function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
+ DocstoreClient.deleteDocLegacy(this.project_id, this.doc_id, done)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should not show the doc in the deleted docs response', function (done) {
|
|
|
+ DocstoreClient.getAllDeletedDocs(
|
|
|
+ this.project_id,
|
|
|
+ (error, deletedDocs) => {
|
|
|
+ if (error) return done(error)
|
|
|
+ expect(deletedDocs).to.deep.equal([])
|
|
|
+ done()
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe('Delete via PATCH', function () {
|
|
|
@@ -292,6 +309,121 @@ describe('Delete via PATCH', function () {
|
|
|
expect(this.res.statusCode).to.equal(400)
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ DocstoreClient.deleteDoc(this.project_id, this.doc_id, done)
|
|
|
+ })
|
|
|
+
|
|
|
+ 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([
|
|
|
+ { _id: this.doc_id.toString(), name: 'main.tex' }
|
|
|
+ ])
|
|
|
+ done()
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('after deleting multiple docs', function () {
|
|
|
+ beforeEach('create doc2', function (done) {
|
|
|
+ this.doc_id2 = ObjectId()
|
|
|
+ DocstoreClient.createDoc(
|
|
|
+ this.project_id,
|
|
|
+ this.doc_id2,
|
|
|
+ this.lines,
|
|
|
+ this.version,
|
|
|
+ this.ranges,
|
|
|
+ done
|
|
|
+ )
|
|
|
+ })
|
|
|
+ beforeEach('delete doc2', function (done) {
|
|
|
+ DocstoreClient.deleteDocWithName(
|
|
|
+ this.project_id,
|
|
|
+ this.doc_id2,
|
|
|
+ 'two.tex',
|
|
|
+ done
|
|
|
+ )
|
|
|
+ })
|
|
|
+ beforeEach('create doc3', function (done) {
|
|
|
+ this.doc_id3 = ObjectId()
|
|
|
+ DocstoreClient.createDoc(
|
|
|
+ this.project_id,
|
|
|
+ this.doc_id3,
|
|
|
+ this.lines,
|
|
|
+ this.version,
|
|
|
+ this.ranges,
|
|
|
+ done
|
|
|
+ )
|
|
|
+ })
|
|
|
+ beforeEach('delete doc3', function (done) {
|
|
|
+ DocstoreClient.deleteDocWithName(
|
|
|
+ this.project_id,
|
|
|
+ this.doc_id3,
|
|
|
+ '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([
|
|
|
+ { _id: this.doc_id3.toString(), name: 'three.tex' },
|
|
|
+ { _id: this.doc_id2.toString(), name: 'two.tex' },
|
|
|
+ { _id: this.doc_id.toString(), name: 'main.tex' }
|
|
|
+ ])
|
|
|
+ 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([
|
|
|
+ { _id: this.doc_id3.toString(), name: 'three.tex' },
|
|
|
+ { _id: this.doc_id2.toString(), name: 'two.tex' }
|
|
|
+ // dropped main.tex
|
|
|
+ ])
|
|
|
+ done()
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe("Destroying a project's documents", function () {
|