MCPcopy
hub / github.com/Unleash/unleash / testServerRoute

Function testServerRoute

frontend/src/utils/testServer.ts:21–51  ·  view source on GitHub ↗
(
    server: SetupServer,
    path: string,
    json: object | boolean | string | number,
    method: 'get' | 'post' | 'put' | 'delete' = 'get',
    status: number = 200,
    searchParams?: Record<string, string>,
)

Source from the content-addressed store, hash-verified

19};
20
21export const testServerRoute = (
22 server: SetupServer,
23 path: string,
24 json: object | boolean | string | number,
25 method: 'get' | 'post' | 'put' | 'delete' = 'get',
26 status: number = 200,
27 searchParams?: Record<string, string>,
28) => {
29 const requests: unknown[] = [];
30 server.use(
31 http[method](path, async ({ request }) => {
32 if (searchParams) {
33 const url = new URL(request.url);
34 const matches = Object.entries(searchParams).every(
35 ([key, value]) => url.searchParams.get(key) === value,
36 );
37 // Fall through to other handlers for this path when the
38 // search params don't match.
39 if (!matches) return undefined;
40 }
41 if (method === 'post' || method === 'put') {
42 const body = await request.json().catch(() => undefined);
43 if (body !== undefined) {
44 requests.push(body);
45 }
46 }
47 return HttpResponse.json(json, { status });
48 }),
49 );
50 return { requests };
51};

Callers 15

setupLoggedInFunction · 0.90
setupLoggedOutFunction · 0.90
setupApiFunction · 0.90
setupApiFunction · 0.90
mockUserFunction · 0.90
mockActivityCountFunction · 0.90
setupApiFunction · 0.90
setupLongRunningProjectFunction · 0.90
setupNewProjectFunction · 0.90

Calls 2

useMethod · 0.80
getMethod · 0.65

Tested by 15

setupLoggedInFunction · 0.72
setupLoggedOutFunction · 0.72
setupApiFunction · 0.72
setupApiFunction · 0.72
mockUserFunction · 0.72
mockActivityCountFunction · 0.72
setupApiFunction · 0.72
setupLongRunningProjectFunction · 0.72
setupNewProjectFunction · 0.72
setupApiFunction · 0.72
testSSOAuthOptionFunction · 0.72
setupSubscribeApiFunction · 0.72