From 3a700a5af2fe7ef5d425509d16e84cd7ffcaee37 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Wed, 27 Jan 2016 16:03:40 +0000 Subject: [PATCH] More tests for indexAll --- .../ReferencesSearchHandlerTests.coffee | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/services/web/test/UnitTests/coffee/ReferencesSearch/ReferencesSearchHandlerTests.coffee b/services/web/test/UnitTests/coffee/ReferencesSearch/ReferencesSearchHandlerTests.coffee index 0fac15b078..bb1b2c22ea 100644 --- a/services/web/test/UnitTests/coffee/ReferencesSearch/ReferencesSearchHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/ReferencesSearch/ReferencesSearchHandlerTests.coffee @@ -234,6 +234,60 @@ describe 'ReferencesSearchHandler', -> expect(data).to.equal @fakeResponseData done() + describe 'when Project.findPopulatedById produces an error', -> + + beforeEach -> + @Project.findPopulatedById.callsArgWith(1, new Error('woops')) + + it 'should produce an error', (done) -> + @call (err, data) => + expect(err).to.not.equal null + expect(err).to.be.instanceof Error + expect(data).to.equal undefined + done() + + it 'should not send request', (done) -> + @call (err, data) => + @request.post.callCount.should.equal 0 + done() + + describe 'when _isFullIndex produces an error', -> + + beforeEach -> + @Project.findPopulatedById.callsArgWith(1, null, @fakeProject) + @handler._isFullIndex.callsArgWith(1, new Error('woops')) + + it 'should produce an error', (done) -> + @call (err, data) => + expect(err).to.not.equal null + expect(err).to.be.instanceof Error + expect(data).to.equal undefined + done() + + it 'should not send request', (done) -> + @call (err, data) => + @request.post.callCount.should.equal 0 + done() + + describe 'when flushDocToMongo produces an error', -> + + beforeEach -> + @Project.findPopulatedById.callsArgWith(1, null, @fakeProject) + @handler._isFullIndex.callsArgWith(1, false) + @DocumentUpdaterHandler.flushDocToMongo.callsArgWith(2, new Error('woops')) + + it 'should produce an error', (done) -> + @call (err, data) => + expect(err).to.not.equal null + expect(err).to.be.instanceof Error + expect(data).to.equal undefined + done() + + it 'should not send request', (done) -> + @call (err, data) => + @request.post.callCount.should.equal 0 + done() + describe '_findBibDocIds', ->