feat: split test routes

This commit is contained in:
DIYgod 2024-05-26 16:52:39 +08:00
parent e3f57a17e0
commit c265a0616a
No known key found for this signature in database
6 changed files with 92 additions and 19 deletions

View File

@ -0,0 +1,22 @@
import { Route } from '@/types';
import ConfigNotFoundError from '@/errors/types/config-not-found';
export const route: Route = {
path: '/config-not-found-error',
name: 'config-not-found-error',
maintainers: ['DIYgod'],
example: '/config-not-found-error',
handler,
};
function handler() {
throw new ConfigNotFoundError('Test config not found error');
return {
title: 'Title',
items: [
{
title: 'Title',
},
],
};
}

21
lib/routes/test/error.ts Normal file
View File

@ -0,0 +1,21 @@
import { Route } from '@/types';
export const route: Route = {
path: '/error',
name: 'error',
maintainers: ['DIYgod'],
example: '/error',
handler,
};
function handler() {
throw new Error('Error test');
return {
title: 'Title',
items: [
{
title: 'Title',
},
],
};
}

View File

@ -0,0 +1,25 @@
import { Route } from '@/types';
import got from '@/utils/got';
export const route: Route = {
path: '/httperror',
name: 'httperror',
maintainers: ['DIYgod'],
example: '/httperror',
handler,
};
async function handler() {
await got({
method: 'get',
url: 'https://httpbingo.org/status/404',
});
return {
title: 'Title',
items: [
{
title: 'Title',
},
],
};
}

View File

@ -1,37 +1,20 @@
import { Route, DataItem } from '@/types';
import { config } from '@/config';
import got from '@/utils/got';
import wait from '@/utils/wait';
import cache from '@/utils/cache';
import { fetchArticle } from '@/utils/wechat-mp';
import ConfigNotFoundError from '@/errors/types/config-not-found';
import InvalidParameterError from '@/errors/types/invalid-parameter';
let cacheIndex = 0;
export const route: Route = {
path: '/:id/:params?',
name: 'Unknown',
name: 'Test',
maintainers: ['DIYgod', 'NeverBehave'],
handler,
};
async function handler(ctx) {
if (ctx.req.param('id') === 'error') {
throw new Error('Error test');
}
if (ctx.req.param('id') === 'httperror') {
await got({
method: 'get',
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':

View File

@ -0,0 +1,22 @@
import { Route } from '@/types';
import InvalidParameterError from '@/errors/types/invalid-parameter';
export const route: Route = {
path: '/invalid-parameter-error',
name: 'invalid-parameter-error',
maintainers: ['DIYgod'],
example: '/invalid-parameter-error',
handler,
};
function handler() {
throw new InvalidParameterError('Test invalid parameter error');
return {
title: 'Title',
items: [
{
title: 'Title',
},
],
};
}

View File

@ -1,5 +1,5 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'Unknown',
name: 'RSSHub Test',
};