fix tests, move most errors to shared code
This commit is contained in:
@@ -68,7 +68,7 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
it('returns an error if user doesn\'t own the spell', async () => {
|
||||
await expect(user.post(`/user/class/cast/snowball`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 400,
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('spellNotOwned'),
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// TODO move to shared tests
|
||||
import { CustomError } from '../../../../../common/script/api-v3/errors';
|
||||
import {
|
||||
CustomError,
|
||||
NotAuthorized,
|
||||
BadRequest,
|
||||
InternalServerError,
|
||||
|
||||
@@ -9,7 +9,6 @@ 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', () => {
|
||||
@@ -87,21 +86,6 @@ 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