mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-15 11:20:36 +08:00
33 lines
888 B
TypeScript
33 lines
888 B
TypeScript
import type { Page } from "@playwright/test";
|
|
import type { RadiclePeer } from "@tests/support/peerManager.js";
|
|
|
|
// Calls a backend command directly, to set up or read back state that the UI
|
|
// test doesn't go through.
|
|
export function api(
|
|
page: Page,
|
|
peer: RadiclePeer,
|
|
command: string,
|
|
data: object,
|
|
) {
|
|
return page.request
|
|
.post(`http://127.0.0.1:${peer.httpdBaseUrl.port}/${command}`, { data })
|
|
.then(response => response.json());
|
|
}
|
|
|
|
export async function saveEmbed(
|
|
page: Page,
|
|
peer: RadiclePeer,
|
|
rid: string,
|
|
name: string,
|
|
bytes: Uint8Array,
|
|
) {
|
|
const response = await page.request.post(
|
|
`http://127.0.0.1:${peer.httpdBaseUrl.port}/save_embed_by_bytes`,
|
|
{
|
|
headers: { rid, "Content-Type": "application/octet-stream" },
|
|
data: Buffer.concat([Buffer.from(`${name}\0`), bytes]),
|
|
},
|
|
);
|
|
return (await response.json()) as string;
|
|
}
|