');
});
test("details size and place pictures and videos from their options, and keep uploads' URLs", async () => {
const details = [
'',
'',
"",
'',
].join("\n\n");
expect((await save("details", details)).status).toBe(204);
const repo = await page("/app");
expect(repo).toContain(
'',
);
expect(repo).toContain(
'',
);
expect(repo).toContain(
'',
);
// A title that is not options stays a title, and a root path is still the repo's own file.
expect(repo).toContain('');
expect(repo).not.toContain("# app");
});
test("the preview renders as the page will", async () => {
const response = await browser.post("/admin/repos/app/preview", {
field: "details",
value: "**hi** ",
});
expect(await response.text()).toBe(
"
hi <script>x</script>
\n",
);
});
test("clearing a text brings the README's back", async () => {
await save("description", "");
await save("details", "");
const repo = await page("/app");
expect(repo).toContain("
The app project.
");
expect(repo).toContain("
app
");
});
test("refuses an unknown field, an overlong text and an unknown repo", async () => {
expect((await save("title", "x")).status).toBe(400);
expect((await save("description", "x".repeat(2001))).status).toBe(400);
expect((await browser.post("/admin/repos/nope/text", { field: "details" })).status).toBe(404);
});
test("uploads pictures and videos by what their bytes are, served as privately as the repo", async () => {
const png = await upload(PNG, "shot.txt");
expect(png.status).toBe(200);
const { url } = (await png.json()) as { url: string };
expect(url).toMatch(/^\/static\/assets\/media\/app\/[0-9a-f]{64}\.png$/);
// Kept in the bucket, in Kepr's own folder, which no sync takes for a repo.
const key = `.kepr/media/app/${url.split("/").pop()}`;
expect(await Bun.file(join(bucketDir, key)).exists()).toBe(true);
expect(await listRepos(openBucket({ kind: "folder", path: bucketDir }))).toEqual([
"app",
"shy",
]);
const served = await inst.app.request(url);
expect([served.status, served.headers.get("content-type")]).toEqual([200, "image/png"]);
const video = ((await (await upload(MP4, "demo.mp4")).json()) as { url: string }).url;
expect(video).toEndWith(".mp4");
// Bun.serve answers Range for a file response, which Safari needs to play a video.
const server = Bun.serve({ port: 0, fetch: (request) => inst.app.fetch(request) });
const range = await fetch(new URL(video, server.url), { headers: { range: "bytes=0-3" } });
expect([range.status, (await range.arrayBuffer()).byteLength]).toEqual([206, 4]);
server.stop();
expect((await upload(new TextEncoder().encode("