From c3bae75d9cd96cfea97bc89cec27956b3c23be28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Krzeslak?= Date: Tue, 6 Oct 2026 18:12:18 +0200 Subject: [PATCH] test: add unit tests after rebase --- tests/converters/ffmpeg.test.ts | 32 ++++++++++++++++++++++++++++++++ tests/pages/user.test.ts | 24 ++++++++++++++++++++---- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/tests/converters/ffmpeg.test.ts b/tests/converters/ffmpeg.test.ts index 17a8434..8fff82e 100644 --- a/tests/converters/ffmpeg.test.ts +++ b/tests/converters/ffmpeg.test.ts @@ -89,6 +89,38 @@ test.each([ expect(calls[0]).toEqual(["-i", "in.mkv", "-c:v", codec, "out.video"]); }); +test.each(["m4a", "mp3", "flac", "ogg"])("keeps embedded cover art for %s output", async (ext) => { + await convert("in.wav", "wav", ext, `out.${ext}`, undefined, mockExecFile); + + expect(calls[0]).toEqual([ + "-i", + "in.wav", + "-map", + "0:a", + "-map", + "0:v:disp:attached_pic?", + "-c:v", + "copy", + "-disposition:v", + "attached_pic", + `out.${ext}`, + ]); +}); + +test.each(["wav", "aac"])("drops video streams for %s output", async (ext) => { + await convert("in.mp3", "mp3", ext, `out.${ext}`, undefined, mockExecFile); + + expect(calls[0]).toEqual(["-i", "in.mp3", "-vn", `out.${ext}`]); +}); + +test("places the cover art args after FFMPEG_OUTPUT_ARGS", async () => { + process.env.FFMPEG_OUTPUT_ARGS = "-b:a 192k"; + + await convert("in.wav", "wav", "mp3", "out.mp3", undefined, mockExecFile); + + expect(calls[0]?.slice(0, 5)).toEqual(["-i", "in.wav", "-b:a", "192k", "-map"]); +}); + test("does not force a codec for an unknown codec prefix", async () => { await convert("in.mkv", "mkv", "vp9.webm", "out.webm", undefined, mockExecFile); diff --git a/tests/pages/user.test.ts b/tests/pages/user.test.ts index 4848339..1be6116 100644 --- a/tests/pages/user.test.ts +++ b/tests/pages/user.test.ts @@ -114,6 +114,12 @@ describe("POST /register", () => { }); }); +const expectErrorPage = async (response: Response, message: string) => { + expect(response.headers.get("content-type")).toContain("text/html"); + const body = await response.text(); + expect(body).toContain('role="alert"'); + expect(body).toContain(message); +}; describe("GET /login", () => { test("shows the login form without a register link while registration is closed", async () => { setEnv({ ACCOUNT_REGISTRATION: false }); @@ -173,7 +179,7 @@ describe("POST /login", () => { const response = await request("/login", { form: { email: user.email, password } }); expect(response.status).toBe(403); - expect(await response.json()).toEqual({ message: "Invalid credentials." }); + await expectErrorPage(response, "Invalid credentials."); expect(setCookie(response, "auth")).toBeUndefined(); }); @@ -183,7 +189,17 @@ describe("POST /login", () => { }); expect(response.status).toBe(403); - expect(await response.json()).toEqual({ message: "Invalid credentials." }); + await expectErrorPage(response, "Invalid credentials."); + }); + + test("keeps the entered email in the form after a failed login", async () => { + const user = await createUser(); + + const response = await request("/login", { + form: { email: user.email, password: "wrong password" }, + }); + + expect(await response.text()).toContain(`value="${user.email}"`); }); test("rejects a request without a password", async () => { @@ -259,7 +275,7 @@ describe("POST /account", () => { }); expect(response.status).toBe(403); - expect(await response.json()).toEqual({ message: "Invalid credentials." }); + await expectErrorPage(response, "Invalid credentials."); expect(findUserById(user.id)?.email).toBe(user.email); }); @@ -296,7 +312,7 @@ describe("POST /account", () => { }); expect(response.status).toBe(409); - expect(await response.json()).toEqual({ message: "Email already in use." }); + await expectErrorPage(response, "Email already in use."); expect(findUserById(user.id)?.email).toBe(user.email); });