mirror of
https://github.com/C4illin/ConvertX.git
synced 2026-10-28 07:44:21 +01:00
test: add unit tests after rebase
This commit is contained in:
@@ -89,6 +89,38 @@ test.each([
|
|||||||
expect(calls[0]).toEqual(["-i", "in.mkv", "-c:v", codec, "out.video"]);
|
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 () => {
|
test("does not force a codec for an unknown codec prefix", async () => {
|
||||||
await convert("in.mkv", "mkv", "vp9.webm", "out.webm", undefined, mockExecFile);
|
await convert("in.mkv", "mkv", "vp9.webm", "out.webm", undefined, mockExecFile);
|
||||||
|
|
||||||
|
|||||||
@@ -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", () => {
|
describe("GET /login", () => {
|
||||||
test("shows the login form without a register link while registration is closed", async () => {
|
test("shows the login form without a register link while registration is closed", async () => {
|
||||||
setEnv({ ACCOUNT_REGISTRATION: false });
|
setEnv({ ACCOUNT_REGISTRATION: false });
|
||||||
@@ -173,7 +179,7 @@ describe("POST /login", () => {
|
|||||||
const response = await request("/login", { form: { email: user.email, password } });
|
const response = await request("/login", { form: { email: user.email, password } });
|
||||||
|
|
||||||
expect(response.status).toBe(403);
|
expect(response.status).toBe(403);
|
||||||
expect(await response.json()).toEqual({ message: "Invalid credentials." });
|
await expectErrorPage(response, "Invalid credentials.");
|
||||||
expect(setCookie(response, "auth")).toBeUndefined();
|
expect(setCookie(response, "auth")).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -183,7 +189,17 @@ describe("POST /login", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(response.status).toBe(403);
|
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 () => {
|
test("rejects a request without a password", async () => {
|
||||||
@@ -259,7 +275,7 @@ describe("POST /account", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(response.status).toBe(403);
|
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);
|
expect(findUserById(user.id)?.email).toBe(user.email);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -296,7 +312,7 @@ describe("POST /account", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(response.status).toBe(409);
|
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);
|
expect(findUserById(user.id)?.email).toBe(user.email);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user