test: minor fix to how cookies are passed around (#55259)

This commit is contained in:
Oliver Eyton-Williams
2024-06-21 17:36:46 +02:00
committed by GitHub
parent dda9c929b0
commit fd1bf0dd5a
2 changed files with 24 additions and 2 deletions
+8 -1
View File
@@ -34,6 +34,13 @@ export const getCsrfToken = (setCookies: string[]): string | undefined => {
export const ORIGIN = 'https://www.freecodecamp.org';
export const getCookies = (setCookies: string[]): string => {
for (const cookie of setCookies) {
expect(cookie).toMatch(/.*=.*/);
}
return setCookies.map(cookie => cookie.split(';')[0]).join('; ');
};
export function superRequest(
resource: string,
config: {
@@ -48,7 +55,7 @@ export function superRequest(
const req = requests[method](resource).set('Origin', ORIGIN);
if (setCookies) {
void req.set('Cookie', setCookies);
void req.set('Cookie', getCookies(setCookies));
}
const csrfToken = (setCookies && getCsrfToken(setCookies)) ?? '';