haiku-atelier-2024/tests/playwright/utils.ts
gcch d50de6d534 2026-04-10
- corvée: met à jour les deps
- corvée: formate
2026-04-10 23:54:12 +02:00

24 lines
714 B
TypeScript

import { Option, pipe } from "effect";
import type { Page } from "playwright/test";
export type BackendHeaders = {
authString: string;
nonce: string;
};
/**
* @throws Lève une exception si la balise du JSON est introuvable.
*/
export const getBackendHeadersFromHtml = async (page: Page): Promise<BackendHeaders> => {
const backendHeaders: BackendHeaders | undefined = pipe(
Option.fromNullishOr(await page.locator("#injection-v2").textContent()),
Option.andThen(j => JSON.parse(j) as BackendHeaders),
Option.getOrUndefined,
);
if (backendHeaders === undefined) {
throw new Error("The JSON of the backend headers in the page's HTML can't be null.");
}
return backendHeaders;
};