test: add unit tests after rebase

This commit is contained in:
Jörg Krzeslak
2026-10-13 08:41:14 +02:00
committed by Laertes87
parent 149a1fae1d
commit c3bae75d9c
2 changed files with 52 additions and 4 deletions
+32
View File
@@ -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);
+20 -4
View File
@@ -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);
});