mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-18 14:29:01 +08:00
a7faf80497
Since the namespace prefix was added in #14800, function targets were stringified into the rules built from the route modules (build:routes and the dev API), e.g. /81params=>{...}. Production loads routes from JSON, where functions are already dropped and the route path is used, so do the same in both producers.
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
import { getRadarRules } from '@/api/radar/rules/utils';
|
|
|
|
// The dev registry holds the route modules themselves, so function targets are still functions here
|
|
vi.mock('@/registry', () => ({
|
|
ensureAllLoaded: () => Promise.resolve(),
|
|
namespaces: {
|
|
example: {
|
|
name: 'Example',
|
|
routes: {
|
|
'/item/:id': {
|
|
name: 'Item',
|
|
radar: [{ source: ['example.com/item/:id'], target: (params) => `/example/item/${params.id}` }],
|
|
},
|
|
'/list/:id': {
|
|
name: 'List',
|
|
radar: [{ source: ['example.com/list/:id'], target: '/list/:id' }],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}));
|
|
|
|
describe('api/radar/rules/utils', () => {
|
|
it('falls back to the route path for function targets', async () => {
|
|
const rules = await getRadarRules();
|
|
expect(rules['example.com']['.'].map((rule) => rule.target)).toEqual(['/example/item/:id', '/example/list/:id']);
|
|
});
|
|
});
|