UNPKG

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

Version:

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

52 lines (42 loc) 1.91 kB
const systemUnderTest = require('../src/401-unauthorized-error'); const VError = require('verror'); describe('401-unauthorized-error.js', function () { describe('#createError', function () { const info = { description: 'Something arbitrary but highly useful!', }; const msg = 'Attempt to access resource without unauthorization.'; const responseBody = { something: 'Not authorized.', }; const error = systemUnderTest.createError(msg, info, responseBody); it('it should create a VError object', function testCreatErrorObject() { error.should.be.an.instanceOf(VError); }); it('it should set the not found error object\'s message property to the value of the message parameter.', function testMessage() { error.message.should.eql(msg); }); it('it should set the not found error object\'s name to HTTP404NotFound.', function testCreateNotFoundErrorName() { error.name.should.eql('HTTP401Unauthorized'); }); it('it should set the not found error object\'s info property to the value of the info parameter.', function testInfo() { VError.info(error).should.eql(info); }); it('it should set a response object on the error.', function testResponse() { error.httpResponse.should.eql({ status: 401, body: responseBody, }); }); }); describe('#isUnauthorizedError', 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.isUnauthorizedError(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.isUnauthorizedError(error).should.eql(true); }); }); });