Skip to content

Commit

Permalink
test: add invalid-parameter-error and config-not-found-error
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Apr 7, 2024
1 parent 79fcce2 commit c145a72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
26 changes: 21 additions & 5 deletions lib/errors/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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:
}
Expand Down
8 changes: 8 additions & 0 deletions lib/routes/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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':
Expand Down

0 comments on commit c145a72

Please sign in to comment.