66 lines
3.6 KiB
TypeScript
66 lines
3.6 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import {
|
|
isApiPath,
|
|
shouldReturnNotFoundAtServerBoundary,
|
|
} from '@/lib/config/server-request-boundary';
|
|
import type { DeploymentRole } from '@/lib/config/deployment-role';
|
|
|
|
describe('server request boundary policy', () => {
|
|
test.each([
|
|
['/', false],
|
|
['/courses', false],
|
|
['/api', true],
|
|
['/api/health', true],
|
|
])('classifies %s as API=%s', (pathname, expected) => {
|
|
expect(isApiPath(pathname)).toBe(expected);
|
|
});
|
|
|
|
test.each<{
|
|
role: DeploymentRole;
|
|
pathname: string;
|
|
method?: string;
|
|
notFound: boolean;
|
|
}>([
|
|
{ role: 'server', pathname: '/', notFound: true },
|
|
{ role: 'server', pathname: '/learn', notFound: true },
|
|
{ role: 'server', pathname: '/classroom/example', notFound: true },
|
|
{ role: 'server', pathname: '/courses', notFound: true },
|
|
{ role: 'server', pathname: '/api/courses', notFound: true },
|
|
{ role: 'server', pathname: '/api/courses/course-1/publish', notFound: true },
|
|
{ role: 'server', pathname: '/api/ops', notFound: true },
|
|
{ role: 'server', pathname: '/api/ops/jobs', notFound: true },
|
|
{ role: 'server', pathname: '/api/access-code', notFound: true },
|
|
{ role: 'server', pathname: '/api/access-code/verify', notFound: true },
|
|
{ role: 'server', pathname: '/api/proxy-media', notFound: true },
|
|
{ role: 'server', pathname: '/api/usage', notFound: true },
|
|
{ role: 'server', pathname: '/api/provider/probe-models', notFound: true },
|
|
{ role: 'server', pathname: '/api/azure-voices', notFound: true },
|
|
{ role: 'server', pathname: '/api/verify-model', notFound: true },
|
|
{ role: 'server', pathname: '/api/verify-image-provider', notFound: true },
|
|
{ role: 'server', pathname: '/api/verify-video-provider', notFound: true },
|
|
{ role: 'server', pathname: '/api/verify-pdf-provider', notFound: true },
|
|
{ role: 'server', pathname: '/api/export-video/render', notFound: true },
|
|
{ role: 'server', pathname: '/api/persistence/documents', notFound: true },
|
|
{ role: 'server', pathname: '/api/generate-classroom', method: 'GET', notFound: true },
|
|
{ role: 'server', pathname: '/api/generate-classroom', method: 'HEAD', notFound: true },
|
|
{ role: 'server', pathname: '/api/generate-classroom/', method: 'HEAD', notFound: true },
|
|
{ role: 'server', pathname: '/api/generate-classroom', method: 'POST', notFound: true },
|
|
{ role: 'server', pathname: '/api/generate-classroom/', method: 'POST', notFound: true },
|
|
{ role: 'server', pathname: '/api/internal/course-publish', method: 'GET', notFound: true },
|
|
{ role: 'server', pathname: '/api/internal/course-publish/', method: 'GET', notFound: true },
|
|
{ role: 'server', pathname: '/api/internal/course-publish', method: 'POST', notFound: false },
|
|
{ role: 'server', pathname: '/api/internal/course-publish/', method: 'POST', notFound: false },
|
|
{ role: 'server', pathname: '/api/chat', notFound: true },
|
|
{ role: 'server', pathname: '/api/coursewares', notFound: true },
|
|
{ role: 'server', pathname: '/api/courses-public', notFound: true },
|
|
{ role: 'server', pathname: '/api/runtime/v1/health/live', notFound: false },
|
|
{ role: 'server', pathname: '/api/runtime/v1/courses/generate', method: 'POST', notFound: false },
|
|
{ role: 'learner', pathname: '/', notFound: false },
|
|
{ role: 'learner', pathname: '/api/courses', notFound: false },
|
|
{ role: 'ops', pathname: '/courses', notFound: false },
|
|
{ role: 'all', pathname: '/api/access-code/verify', notFound: false },
|
|
])('$role $pathname => notFound=$notFound', ({ role, pathname, method, notFound }) => {
|
|
expect(shouldReturnNotFoundAtServerBoundary(role, pathname, method)).toBe(notFound);
|
|
});
|
|
});
|