Files
wehub-resource-sync 3a28426bf4
Lint and Format Check / lint-and-format (push) Failing after 0s
Check Migrations / Check for duplicate migration numbers (push) Failing after 1s
CI Pre-merge Check / CI Pre-merge Check (push) Failing after 2m17s
chore: import upstream snapshot with attribution
2026-07-13 12:23:40 +08:00

52 lines
1.7 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
vi.hoisted(() => {
process.env.JWT_SECRET = 'test-secret-long-enough-for-signing-32chars';
});
import { schedulesRouter } from '../../src/api/routes/schedules/index.routes';
describe('schedules route wiring', () => {
const routeEntries = (
schedulesRouter as unknown as {
stack: Array<{
route?: {
path: string;
methods: Record<string, boolean>;
};
}>;
}
).stack
.filter((layer) => layer.route)
.map((layer) => ({
path: layer.route!.path,
methods: Object.keys(layer.route!.methods).sort(),
}));
const routeIndex = (path: string, method: string) =>
routeEntries.findIndex(
(entry) => entry.path === path && entry.methods.includes(method.toLowerCase())
);
it('registers explicit config routes before dynamic schedule id routes', () => {
const getConfigIndex = routeIndex('/config', 'get');
const patchConfigIndex = routeIndex('/config', 'patch');
const getByIdIndex = routeIndex('/:id', 'get');
const getLogsIndex = routeIndex('/:id/logs', 'get');
const patchByIdIndex = routeIndex('/:id', 'patch');
const deleteByIdIndex = routeIndex('/:id', 'delete');
expect(getConfigIndex).toBeGreaterThan(-1);
expect(patchConfigIndex).toBeGreaterThan(-1);
expect(getByIdIndex).toBeGreaterThan(-1);
expect(getLogsIndex).toBeGreaterThan(-1);
expect(patchByIdIndex).toBeGreaterThan(-1);
expect(deleteByIdIndex).toBeGreaterThan(-1);
expect(getConfigIndex).toBeLessThan(getByIdIndex);
expect(patchConfigIndex).toBeLessThan(getByIdIndex);
expect(getConfigIndex).toBeLessThan(patchByIdIndex);
expect(patchConfigIndex).toBeLessThan(deleteByIdIndex);
});
});