From d906d3ec94545ab59026ef9b36b02de8a08ef8bc Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 7 Nov 2017 10:49:02 -0700 Subject: [PATCH] [savedObjects/errors] add tests for EsAutoCreateIndexError --- .../client/lib/__tests__/errors.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) 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); + }); + }); + }); + }); });