mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
add tests, move CustomError to common, fix casting
This commit is contained in:
@@ -9,6 +9,7 @@ import responseMiddleware from '../../../../../website/src/middlewares/api-v3/re
|
||||
import getUserLanguage from '../../../../../website/src/middlewares/api-v3/getUserLanguage';
|
||||
|
||||
import { BadRequest } from '../../../../../website/src/libs/api-v3/errors';
|
||||
import { NotAuthorized as NotAuthorizedShared } from '../../../../../common/script/api-v3/errors';
|
||||
import logger from '../../../../../website/src/libs/api-v3/logger';
|
||||
|
||||
describe('errorHandler', () => {
|
||||
@@ -86,6 +87,21 @@ describe('errorHandler', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('handle CustomError(s) from shared code', () => {
|
||||
let error = new NotAuthorizedShared();
|
||||
|
||||
errorHandler(error, req, res, next);
|
||||
|
||||
expect(res.status).to.be.calledOnce;
|
||||
expect(res.json).to.be.calledOnce;
|
||||
|
||||
expect(res.status).to.be.calledWith(400);
|
||||
expect(res.json).to.be.calledWith({
|
||||
error: 'NotAuthorized',
|
||||
message: 'Not authorized.',
|
||||
});
|
||||
});
|
||||
|
||||
it('handle http-errors errors', () => {
|
||||
let error = new Error('custom message');
|
||||
error.statusCode = 422;
|
||||
|
||||
Reference in New Issue
Block a user