MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / authedRequest

Function authedRequest

e2e/utils/request.ts:6–32  ·  view source on GitHub ↗
({
  request,
  method,
  endpoint,
  data
}: {
  request: APIRequestContext;
  method: 'post' | 'put';
  endpoint: string;
  data: Record<string, unknown>;
})

Source from the content-addressed store, hash-verified

4 endpoint[0] === '/' ? endpoint : '/' + endpoint;
5
6export const authedRequest = async ({
7 request,
8 method,
9 endpoint,
10 data
11}: {
12 request: APIRequestContext;
13 method: 'post' | 'put';
14 endpoint: string;
15 data: Record<string, unknown>;
16}) => {
17 const csrfToken = (await request.storageState()).cookies.find(
18 c => c.name === 'csrf_token'
19 )?.value;
20
21 expect(csrfToken).toBeTruthy();
22
23 const res = await request[method](
24 process.env.API_LOCATION + ensureLeadingSlash(endpoint),
25 {
26 data,
27 headers: { 'csrf-token': csrfToken! }
28 }
29 );
30 expect(res.status()).toBe(200);
31 return res;
32};

Callers 6

setThemeFunction · 0.90
enableKeyboardShortcutsFunction · 0.90
projects.spec.tsFile · 0.90
hotkeys.spec.tsFile · 0.90

Calls 1

ensureLeadingSlashFunction · 0.85

Tested by 2

setThemeFunction · 0.72
enableKeyboardShortcutsFunction · 0.72