|
|
@@ -80,246 +80,6 @@ describe('ReferencesHandler', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('index', function () {
|
|
|
- beforeEach(function () {
|
|
|
- sinon.stub(this.handler, '_findBibDocIds')
|
|
|
- sinon.stub(this.handler, '_findBibFileIds')
|
|
|
- sinon.stub(this.handler, '_isFullIndex').callsArgWith(1, null, true)
|
|
|
- this.request.post.callsArgWith(
|
|
|
- 1,
|
|
|
- null,
|
|
|
- { statusCode: 200 },
|
|
|
- this.fakeResponseData
|
|
|
- )
|
|
|
- return (this.call = callback => {
|
|
|
- return this.handler.index(this.projectId, this.docIds, callback)
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('when references feature is disabled', function () {
|
|
|
- beforeEach(function () {
|
|
|
- this.Features.hasFeature.withArgs('references').returns(false)
|
|
|
- })
|
|
|
-
|
|
|
- it('should not try to retrieve any user information', function (done) {
|
|
|
- this.call(() => {
|
|
|
- this.UserGetter.getUser.callCount.should.equal(0)
|
|
|
- done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should not produce an error', function (done) {
|
|
|
- return this.call(err => {
|
|
|
- expect(err).to.equal(undefined)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('with docIds as an array', function () {
|
|
|
- beforeEach(function () {
|
|
|
- return (this.docIds = ['aaa', 'ccc'])
|
|
|
- })
|
|
|
-
|
|
|
- it('should not call _findBibDocIds', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- this.handler._findBibDocIds.callCount.should.equal(0)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should call ProjectGetter.getProject', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- this.ProjectGetter.getProject.callCount.should.equal(1)
|
|
|
- this.ProjectGetter.getProject
|
|
|
- .calledWith(this.projectId)
|
|
|
- .should.equal(true)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should not call _findBibDocIds', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- this.handler._findBibDocIds.callCount.should.equal(0)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should call DocumentUpdaterHandler.flushDocToMongo', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- this.DocumentUpdaterHandler.flushDocToMongo.callCount.should.equal(2)
|
|
|
- this.docIds.forEach(docId => {
|
|
|
- return this.DocumentUpdaterHandler.flushDocToMongo
|
|
|
- .calledWith(this.projectId, docId)
|
|
|
- .should.equal(true)
|
|
|
- })
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should make a request to references service', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- this.request.post.callCount.should.equal(1)
|
|
|
- const arg = this.request.post.firstCall.args[0]
|
|
|
- expect(arg.json).to.have.all.keys('docUrls', 'fullIndex')
|
|
|
- expect(arg.json.docUrls.length).to.equal(2)
|
|
|
- expect(arg.json.fullIndex).to.equal(true)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should not produce an error', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- expect(err).to.equal(null)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should return data', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- expect(data).to.not.equal(null)
|
|
|
- expect(data).to.not.equal(undefined)
|
|
|
- expect(data).to.equal(this.fakeResponseData)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('when ProjectGetter.getProject produces an error', function () {
|
|
|
- beforeEach(function () {
|
|
|
- return this.ProjectGetter.getProject.callsArgWith(2, new Error('woops'))
|
|
|
- })
|
|
|
-
|
|
|
- it('should produce an error', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- expect(err).to.not.equal(null)
|
|
|
- expect(err).to.be.instanceof(Error)
|
|
|
- expect(data).to.equal(undefined)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should not send request', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- this.request.post.callCount.should.equal(0)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('when ProjectGetter.getProject returns null', function () {
|
|
|
- beforeEach(function () {
|
|
|
- return this.ProjectGetter.getProject.callsArgWith(2, null)
|
|
|
- })
|
|
|
-
|
|
|
- it('should produce an error', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- expect(err).to.not.equal(null)
|
|
|
- expect(err).to.be.instanceof(Errors.NotFoundError)
|
|
|
- expect(data).to.equal(undefined)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should not send request', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- this.request.post.callCount.should.equal(0)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('when _isFullIndex produces an error', function () {
|
|
|
- beforeEach(function () {
|
|
|
- this.ProjectGetter.getProject.callsArgWith(2, null, this.fakeProject)
|
|
|
- return this.handler._isFullIndex.callsArgWith(1, new Error('woops'))
|
|
|
- })
|
|
|
-
|
|
|
- it('should produce an error', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- expect(err).to.not.equal(null)
|
|
|
- expect(err).to.be.instanceof(Error)
|
|
|
- expect(data).to.equal(undefined)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should not send request', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- this.request.post.callCount.should.equal(0)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('when flushDocToMongo produces an error', function () {
|
|
|
- beforeEach(function () {
|
|
|
- this.ProjectGetter.getProject.callsArgWith(2, null, this.fakeProject)
|
|
|
- this.handler._isFullIndex.callsArgWith(1, false)
|
|
|
- return this.DocumentUpdaterHandler.flushDocToMongo.callsArgWith(
|
|
|
- 2,
|
|
|
- new Error('woops')
|
|
|
- )
|
|
|
- })
|
|
|
-
|
|
|
- it('should produce an error', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- expect(err).to.not.equal(null)
|
|
|
- expect(err).to.be.instanceof(Error)
|
|
|
- expect(data).to.equal(undefined)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should not send request', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- this.request.post.callCount.should.equal(0)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('when request produces an error', function () {
|
|
|
- beforeEach(function () {
|
|
|
- this.ProjectGetter.getProject.callsArgWith(2, null, this.fakeProject)
|
|
|
- this.handler._isFullIndex.callsArgWith(1, null, false)
|
|
|
- this.DocumentUpdaterHandler.flushDocToMongo.callsArgWith(2, null)
|
|
|
- return this.request.post.callsArgWith(1, new Error('woops'))
|
|
|
- })
|
|
|
-
|
|
|
- it('should produce an error', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- expect(err).to.not.equal(null)
|
|
|
- expect(err).to.be.instanceof(Error)
|
|
|
- expect(data).to.equal(undefined)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('when request responds with error status', function () {
|
|
|
- beforeEach(function () {
|
|
|
- this.ProjectGetter.getProject.callsArgWith(2, null, this.fakeProject)
|
|
|
- this.handler._isFullIndex.callsArgWith(1, null, false)
|
|
|
- return this.request.post.callsArgWith(
|
|
|
- 1,
|
|
|
- null,
|
|
|
- { statusCode: 500 },
|
|
|
- null
|
|
|
- )
|
|
|
- })
|
|
|
-
|
|
|
- it('should produce an error', function (done) {
|
|
|
- return this.call((err, data) => {
|
|
|
- expect(err).to.not.equal(null)
|
|
|
- expect(err).to.be.instanceof(Error)
|
|
|
- expect(data).to.equal(undefined)
|
|
|
- return done()
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
describe('indexAll', function () {
|
|
|
beforeEach(function () {
|
|
|
sinon.stub(this.handler, '_findBibDocIds').returns(['aaa', 'ccc'])
|