comment errors according to apidoc, add new tests and fix existing ones

This commit is contained in:
Matteo Pagliazzi
2015-11-17 19:22:47 +01:00
parent 846800ccc9
commit 2a51117d21
5 changed files with 80 additions and 28 deletions

View File

@@ -3,6 +3,7 @@ import {
NotAuthorized,
BadRequest,
InternalServerError,
NotFound,
} from '../../../../../website/src/libs/api-v3/errors';
describe('Custom Errors', () => {
@@ -21,7 +22,7 @@ describe('Custom Errors', () => {
expect(notAuthorizedError).to.be.an.instanceOf(CustomError);
});
it('it returns an http code of 400', () => {
it('it returns an http code of 401', () => {
let notAuthorizedError = new NotAuthorized();
expect(notAuthorizedError.httpCode).to.eql(401);
@@ -40,6 +41,32 @@ describe('Custom Errors', () => {
});
});
describe('NotFound', () => {
it('is an instance of CustomError', () => {
let notAuthorizedError = new NotFound();
expect(notAuthorizedError).to.be.an.instanceOf(CustomError);
});
it('it returns an http code of 404', () => {
let notAuthorizedError = new NotFound();
expect(notAuthorizedError.httpCode).to.eql(404);
});
it('returns a default message', () => {
let notAuthorizedError = new NotFound();
expect(notAuthorizedError.message).to.eql('Not found.');
});
it('allows a custom message', () => {
let notAuthorizedError = new NotFound('Custom Error Message');
expect(notAuthorizedError.message).to.eql('Custom Error Message');
});
});
describe('BadRequest', () => {
it('is an instance of CustomError', () => {
let badRequestError = new BadRequest();
@@ -82,7 +109,7 @@ describe('Custom Errors', () => {
it('returns a default message', () => {
let internalServerError = new InternalServerError();
expect(internalServerError.message).to.eql('Internal server error.');
expect(internalServerError.message).to.eql('An unexpected error occurred.');
});
it('allows a custom message', () => {