|
@@ -42,51 +42,6 @@ describe('DocManager', function () {
|
|
|
return (this.stubbedError = new Error('blew up'))
|
|
return (this.stubbedError = new Error('blew up'))
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('checkDocExists', function () {
|
|
|
|
|
- beforeEach(function () {
|
|
|
|
|
- return (this.DocManager._getDoc = sinon.stub())
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should call get doc with a quick filter', function (done) {
|
|
|
|
|
- this.DocManager._getDoc.callsArgWith(3, null, { _id: this.doc_id })
|
|
|
|
|
- return this.DocManager.checkDocExists(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- this.doc_id,
|
|
|
|
|
- (err, exist) => {
|
|
|
|
|
- exist.should.equal(true)
|
|
|
|
|
- this.DocManager._getDoc
|
|
|
|
|
- .calledWith(this.project_id, this.doc_id, { _id: 1, inS3: true })
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should return false when doc is not there', function (done) {
|
|
|
|
|
- this.DocManager._getDoc.callsArgWith(3, null)
|
|
|
|
|
- return this.DocManager.checkDocExists(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- this.doc_id,
|
|
|
|
|
- (err, exist) => {
|
|
|
|
|
- exist.should.equal(false)
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- return it('should return error when get doc errors', function (done) {
|
|
|
|
|
- this.DocManager._getDoc.callsArgWith(3, 'error')
|
|
|
|
|
- return this.DocManager.checkDocExists(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- this.doc_id,
|
|
|
|
|
- (err, exist) => {
|
|
|
|
|
- err.should.equal('error')
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
describe('getFullDoc', function () {
|
|
describe('getFullDoc', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
this.DocManager._getDoc = sinon.stub()
|
|
this.DocManager._getDoc = sinon.stub()
|
|
@@ -414,127 +369,6 @@ describe('DocManager', function () {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('deleteDoc', function () {
|
|
|
|
|
- describe('when the doc exists', function () {
|
|
|
|
|
- beforeEach(function (done) {
|
|
|
|
|
- this.callback = sinon.stub().callsFake(done)
|
|
|
|
|
- this.lines = ['mock', 'doc', 'lines']
|
|
|
|
|
- this.rev = 77
|
|
|
|
|
- this.DocManager.checkDocExists = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .callsArgWith(2, null, true)
|
|
|
|
|
- this.MongoManager.markDocAsDeleted = sinon.stub().yields(null)
|
|
|
|
|
- this.DocArchiveManager.archiveDocById = sinon.stub().yields(null)
|
|
|
|
|
- return this.DocManager.deleteDoc(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- this.doc_id,
|
|
|
|
|
- this.callback
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should get the doc', function () {
|
|
|
|
|
- return this.DocManager.checkDocExists
|
|
|
|
|
- .calledWith(this.project_id, this.doc_id)
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should mark doc as deleted', function () {
|
|
|
|
|
- return this.MongoManager.markDocAsDeleted
|
|
|
|
|
- .calledWith(this.project_id, this.doc_id)
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should return the callback', function () {
|
|
|
|
|
- return this.callback.called.should.equal(true)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- describe('background flush disabled', function () {
|
|
|
|
|
- beforeEach(function () {
|
|
|
|
|
- this.settings.docstore.archiveOnSoftDelete = false
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should not flush the doc out of mongo', function () {
|
|
|
|
|
- this.DocArchiveManager.archiveDocById.should.not.have.been.called
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- describe('background flush enabled', function () {
|
|
|
|
|
- beforeEach(function (done) {
|
|
|
|
|
- this.settings.docstore.archiveOnSoftDelete = true
|
|
|
|
|
- this.callback = sinon.stub().callsFake(done)
|
|
|
|
|
- this.DocManager.deleteDoc(this.project_id, this.doc_id, this.callback)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should not fail the delete process', function () {
|
|
|
|
|
- this.callback.should.have.been.calledWith(null)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should flush the doc out of mongo', function () {
|
|
|
|
|
- this.DocArchiveManager.archiveDocById.should.have.been.calledWith(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- this.doc_id
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- describe('when the background flush fails', function () {
|
|
|
|
|
- beforeEach(function (done) {
|
|
|
|
|
- this.err = new Error('foo')
|
|
|
|
|
- this.DocManager.checkDocExists = sinon.stub().yields(null, true)
|
|
|
|
|
- this.MongoManager.markDocAsDeleted = sinon.stub().yields(null)
|
|
|
|
|
- this.DocArchiveManager.archiveDocById = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .yields(this.err)
|
|
|
|
|
- this.callback = sinon.stub().callsFake(done)
|
|
|
|
|
- this.DocManager.deleteDoc(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- this.doc_id,
|
|
|
|
|
- this.callback
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should log a warning', function () {
|
|
|
|
|
- this.logger.warn.should.have.been.calledWith(
|
|
|
|
|
- sinon.match({
|
|
|
|
|
- project_id: this.project_id,
|
|
|
|
|
- doc_id: this.doc_id,
|
|
|
|
|
- err: this.err
|
|
|
|
|
- }),
|
|
|
|
|
- 'archiving a single doc in the background failed'
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should not fail the delete process', function () {
|
|
|
|
|
- this.callback.should.have.been.calledWith(null)
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- return describe('when the doc does not exist', function () {
|
|
|
|
|
- beforeEach(function () {
|
|
|
|
|
- this.DocManager.checkDocExists = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .callsArgWith(2, null, false)
|
|
|
|
|
- return this.DocManager.deleteDoc(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- this.doc_id,
|
|
|
|
|
- this.callback
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- return it('should return a NotFoundError', function () {
|
|
|
|
|
- return this.callback
|
|
|
|
|
- .calledWith(
|
|
|
|
|
- sinon.match.has(
|
|
|
|
|
- 'message',
|
|
|
|
|
- `No such project/doc to delete: ${this.project_id}/${this.doc_id}`
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
describe('patchDoc', function () {
|
|
describe('patchDoc', function () {
|
|
|
describe('when the doc exists', function () {
|
|
describe('when the doc exists', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|