mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
test: ensure shortcuts enabled before testing (#54635)
This commit is contained in:
committed by
GitHub
parent
e0bb313aed
commit
2e270a552d
@@ -0,0 +1,26 @@
|
||||
import { APIRequestContext, expect } from '@playwright/test';
|
||||
|
||||
const ensureLeadingSlash = (endpoint: string) =>
|
||||
endpoint[0] === '/' ? endpoint : '/' + endpoint;
|
||||
|
||||
export const authedPut = async (
|
||||
request: APIRequestContext,
|
||||
endpoint: string,
|
||||
data: Record<string, unknown>
|
||||
) => {
|
||||
const csrfToken = (await request.storageState()).cookies.find(
|
||||
c => c.name === 'csrf_token'
|
||||
)?.value;
|
||||
|
||||
expect(csrfToken).toBeTruthy();
|
||||
|
||||
const res = await request.put(
|
||||
process.env.API_LOCATION + ensureLeadingSlash(endpoint),
|
||||
{
|
||||
data,
|
||||
headers: { 'csrf-token': csrfToken! }
|
||||
}
|
||||
);
|
||||
expect(res.status()).toBe(200);
|
||||
return res;
|
||||
};
|
||||
Reference in New Issue
Block a user