Merge pull request #7246 from overleaf/ab-references-handler-unhandled-error

[web] Fix unhandled error in ReferencesHandler

GitOrigin-RevId: 1b7f2f186780b3ed79434a509ce3dc54e1c38f07
This commit is contained in:
Alexandre Bourdin
2022-04-07 08:04:03 +00:00
committed by Copybot
parent 997bffc9b1
commit b28271082c
4 changed files with 75 additions and 15 deletions
@@ -44,6 +44,7 @@ describe('ReferencesController', function () {
this.res = new MockResponse()
this.res.json = sinon.stub()
this.res.sendStatus = sinon.stub()
this.next = sinon.stub()
return (this.fakeResponseData = {
projectId: this.projectId,
keys: ['one', 'two', 'three'],
@@ -59,7 +60,7 @@ describe('ReferencesController', function () {
this.fakeResponseData
)
return (this.call = callback => {
this.controller.indexAll(this.req, this.res)
this.controller.indexAll(this.req, this.res, this.next)
return callback()
})
})
@@ -166,7 +167,7 @@ describe('ReferencesController', function () {
beforeEach(function () {
this.ReferencesHandler.indexAll.callsArgWith(1)
return (this.call = callback => {
this.controller.indexAll(this.req, this.res)
this.controller.indexAll(this.req, this.res, this.next)
return callback()
})
})
@@ -201,7 +202,7 @@ describe('ReferencesController', function () {
describe('index', function () {
beforeEach(function () {
return (this.call = callback => {
this.controller.index(this.req, this.res)
this.controller.index(this.req, this.res, this.next)
return callback()
})
})
@@ -260,8 +261,10 @@ describe('ReferencesController', function () {
it('should produce an error response', function (done) {
return this.call(() => {
this.res.sendStatus.callCount.should.equal(1)
this.res.sendStatus.calledWith(500).should.equal(true)
this.next.callCount.should.equal(1)
this.next
.calledWith(sinon.match.instanceOf(Error))
.should.equal(true)
return done()
})
})
@@ -15,6 +15,7 @@
const SandboxedModule = require('sandboxed-module')
const { assert, expect } = require('chai')
const sinon = require('sinon')
const Errors = require('../../../../app/src/Features/Errors/Errors')
const modulePath = '../../../../app/src/Features/References/ReferencesHandler'
describe('ReferencesHandler', function () {
@@ -206,6 +207,28 @@ describe('ReferencesHandler', function () {
})
})
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)
@@ -389,6 +412,28 @@ describe('ReferencesHandler', function () {
})
})
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)