UNPKG

@dannybster/coco-the-bear-http-errors

Version:

A collection of error objects that represent http response objects for CoCo The Bear.

57 lines (46 loc) 2.22 kB
const systemUnderTest = require('../src/503-service-unavailable-error'); const VError = require('verror'); describe('503-service-unavailable-error.js', function () { describe('#createError', function () { const info = { description: 'Something arbitrary but highly useful!', }; const msg = 'An external dependancy failed booooo!'; const responseBody = { something: 'Something expected failed and the service is down.', }; const cause = new Error('I\'m a teapot'); const error = systemUnderTest.createError(msg, info, responseBody, cause); it('it should create a VError object', function testCreatErrorObject() { error.should.be.an.instanceOf(VError); }); it('the service unavailable error object\'s message property should include the message parameter.', function testMessage() { error.message.should.startWith(msg); }); it('it should set the service unavailable error object\'s name to HTTP503ServiceUnavailable.', function testCreateNotFoundErrorName() { error.name.should.eql('HTTP503ServiceUnavailable'); }); it('it should set the service unavailable error object\'s info property to the value of the info parameter.', function testInfo() { VError.info(error).should.eql(info); }); it('it should set the service unavailable error object\'s cause to the cause parameter.', function testCause() { error.cause().should.eql(cause); }); it('it should set a response object on the error.', function testResponse() { error.httpResponse.should.eql({ status: 503, body: responseBody, }); }); }); describe('#isServiceUnavailableError', function () { it('it should return false if called with an error that was not created with #createError', function testFalse() { const error = new VError('Not a notFound error.'); systemUnderTest.isServiceUnavailableError(error).should.eql(false); }); it('it should return true if called with an error that was created with #createError', function testTrue() { const error = systemUnderTest.createError(''); systemUnderTest.isServiceUnavailableError(error).should.eql(true); }); }); });