Merge pull request #6256 from HabitRPG/api-v3-apidoc
API v3 - apidoc wip
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('errorHandler', () => {
|
||||
expect(res.status).to.be.calledWith(500);
|
||||
expect(res.json).to.be.calledWith({
|
||||
error: 'InternalServerError',
|
||||
message: 'Internal server error.',
|
||||
message: 'An unexpected error occurred.',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -63,7 +63,7 @@ describe('errorHandler', () => {
|
||||
expect(res.status).to.be.calledWith(500);
|
||||
expect(res.json).to.be.calledWith({
|
||||
error: 'InternalServerError',
|
||||
message: 'Internal server error.',
|
||||
message: 'An unexpected error occurred.',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -88,7 +88,7 @@ describe('errorHandler', () => {
|
||||
errorHandler(error, req, res, next);
|
||||
|
||||
expect(logger.error).to.be.calledOnce;
|
||||
expect(logger.error).to.be.calledWith(error.stack, {
|
||||
expect(logger.error).to.be.calledWithExactly(error.stack, {
|
||||
originalUrl: req.originalUrl,
|
||||
headers: req.headers,
|
||||
body: req.body,
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { requester } from '../../../../helpers/api-integration.helper';
|
||||
|
||||
describe('notFound Middleware', () => {
|
||||
it('returns a 404 error when the resource is not found', () => {
|
||||
let request = requester().get('/api/v3/dummy-url');
|
||||
|
||||
return request.then((errBody) => {
|
||||
expect(errBody.error).to.equal('NotFound');
|
||||
expect(errBody.message).to.equal('Not found.');
|
||||
}).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user