test: add invalid-parameter-error and config-not-found-error
This commit is contained in:
@@ -35,6 +35,22 @@ describe('RequestInProgressError', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('config-not-found-error', () => {
|
||||
it(`config-not-found-error`, async () => {
|
||||
const response = await request.get('/test/config-not-found-error');
|
||||
expect(response.status).toBe(503);
|
||||
expect(response.text).toMatch('ConfigNotFoundError: Test config not found error');
|
||||
}, 20000);
|
||||
});
|
||||
|
||||
describe('invalid-parameter-error', () => {
|
||||
it(`invalid-parameter-error`, async () => {
|
||||
const response = await request.get('/test/invalid-parameter-error');
|
||||
expect(response.status).toBe(503);
|
||||
expect(response.text).toMatch('InvalidParameterError: Test invalid parameter error');
|
||||
}, 20000);
|
||||
});
|
||||
|
||||
describe('route throws an error', () => {
|
||||
it('route path error should have path mounted', async () => {
|
||||
await request.get('/test/error');
|
||||
@@ -47,19 +63,19 @@ describe('route throws an error', () => {
|
||||
const value = $(item).find('.debug-value').html()?.trim();
|
||||
switch (key) {
|
||||
case 'Request Amount:':
|
||||
expect(value).toBe('7');
|
||||
expect(value).toBe('9');
|
||||
break;
|
||||
case 'Hot Routes:':
|
||||
expect(value).toBe('4 /test/:id<br>');
|
||||
expect(value).toBe('6 /test/:id<br>');
|
||||
break;
|
||||
case 'Hot Paths:':
|
||||
expect(value).toBe('2 /test/error<br>2 /test/slow<br>1 /test/httperror<br>1 /thisDoesNotExist<br>1 /<br>');
|
||||
expect(value).toBe('2 /test/error<br>2 /test/slow<br>1 /test/httperror<br>1 /test/config-not-found-error<br>1 /test/invalid-parameter-error<br>1 /thisDoesNotExist<br>1 /<br>');
|
||||
break;
|
||||
case 'Hot Error Routes:':
|
||||
expect(value).toBe('3 /test/:id<br>');
|
||||
expect(value).toBe('5 /test/:id<br>');
|
||||
break;
|
||||
case 'Hot Error Paths:':
|
||||
expect(value).toBe('2 /test/error<br>1 /test/httperror<br>1 /test/slow<br>1 /thisDoesNotExist<br>');
|
||||
expect(value).toBe('2 /test/error<br>1 /test/httperror<br>1 /test/slow<br>1 /test/config-not-found-error<br>1 /test/invalid-parameter-error<br>1 /thisDoesNotExist<br>');
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import { config } from '@/config';
|
||||
import got from '@/utils/got';
|
||||
import wait from '@/utils/wait';
|
||||
import cache from '@/utils/cache';
|
||||
import ConfigNotFoundError from '@/errors/types/config-not-found';
|
||||
import InvalidParameterError from '@/errors/types/invalid-parameter';
|
||||
|
||||
let cacheIndex = 0;
|
||||
|
||||
@@ -23,6 +25,12 @@ async function handler(ctx) {
|
||||
url: 'https://httpbingo.org/status/404',
|
||||
});
|
||||
}
|
||||
if (ctx.req.param('id') === 'config-not-found-error') {
|
||||
throw new ConfigNotFoundError('Test config not found error');
|
||||
}
|
||||
if (ctx.req.param('id') === 'invalid-parameter-error') {
|
||||
throw new InvalidParameterError('Test invalid parameter error');
|
||||
}
|
||||
let item: DataItem[] = [];
|
||||
switch (ctx.req.param('id')) {
|
||||
case 'filter':
|
||||
|
||||
Reference in New Issue
Block a user