mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-30 16:50:47 +08:00
This fixture is simil to the way Playwright handles fixtures, which are being setup and teardown for each test. Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
25 lines
689 B
TypeScript
25 lines
689 B
TypeScript
import type { HttpdClient } from "@httpd-client";
|
|
import type { RadiclePeer } from "@tests/support/peerManager.js";
|
|
|
|
import { sessionPayloadSchema } from "@httpd-client/lib/session.js";
|
|
|
|
export async function authenticate(
|
|
api: HttpdClient,
|
|
peer: RadiclePeer,
|
|
): Promise<string> {
|
|
const { stdout } = await peer.rad(["web", "--backend", api.url, "--json"]);
|
|
const session = sessionPayloadSchema.safeParse(JSON.parse(stdout));
|
|
|
|
if (!session.success) {
|
|
throw new Error("Failed to parse session payload");
|
|
}
|
|
|
|
const { sessionId, signature, publicKey } = session.data;
|
|
await api.session.update(sessionId, {
|
|
sig: signature,
|
|
pk: publicKey,
|
|
});
|
|
|
|
return sessionId;
|
|
}
|