/
vasya2
/
var
Обзор
Документация
Войти
/
vasya2
/
var
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
e2e/utils/request.ts
32 строки
732 B
Sem Bauke
feat: convert projects to Playwright (#54689)
21 май 2024, 18:37
Не верифицирован
21 май 2024, 18:37
c1e0494
Код
Авторство
О чём код?
import { APIRequestContext, expect } from '@playwright/test'; const ensureLeadingSlash = (endpoint: string) => endpoint[0] === '/' ? endpoint : '/' + endpoint; export const authedRequest = async ({ request, method, endpoint, data }: { request: APIRequestContext; method: 'post' | 'put'; 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[method]( process.env.API_LOCATION + ensureLeadingSlash(endpoint), { data, headers: { 'csrf-token': csrfToken! } } ); expect(res.status()).toBe(200); return res; };