diff --git a/src/server/saved_objects/client/lib/__tests__/errors.js b/src/server/saved_objects/client/lib/__tests__/errors.js index e4b7802509d3b..9dc5ff5174f1a 100644 --- a/src/server/saved_objects/client/lib/__tests__/errors.js +++ b/src/server/saved_objects/client/lib/__tests__/errors.js @@ -15,6 +15,8 @@ import { decorateEsUnavailableError, isEsUnavailableError, decorateGeneralError, + isEsAutoCreateIndexError, + createEsAutoCreateIndexError, } from '../errors'; describe('savedObjectsClient/errorTypes', () => { @@ -285,4 +287,39 @@ describe('savedObjectsClient/errorTypes', () => { }); }); }); + + describe('EsAutoCreateIndex error', () => { + describe('createEsAutoCreateIndexError', () => { + it('does not take an error argument', () => { + const error = new Error(); + expect(createEsAutoCreateIndexError(error)).to.not.be(error); + }); + + it('returns a new Error', () => { + expect(createEsAutoCreateIndexError()).to.be.a(Error); + }); + + it('makes errors identifiable as EsAutoCreateIndex errors', () => { + expect(isEsAutoCreateIndexError(createEsAutoCreateIndexError())).to.be(true); + }); + + it('returns a boom error', () => { + const error = createEsAutoCreateIndexError(); + expect(error).to.have.property('isBoom', true); + expect(error.output).to.be.an('object'); + expect(error.output.statusCode).to.be(503); + }); + + describe('error.output', () => { + it('uses "Automatic index creation failed" message', () => { + const error = createEsAutoCreateIndexError(); + expect(error.output.payload).to.have.property('message', 'Automatic index creation failed'); + }); + it('sets statusCode to 503', () => { + const error = createEsAutoCreateIndexError(); + expect(error.output).to.have.property('statusCode', 503); + }); + }); + }); + }); });