Fix tests

This commit is contained in:
Zoe Roux 2025-03-08 22:53:58 +01:00
parent fd57f506c1
commit 3f77a1bda5
No known key found for this signature in database
10 changed files with 53 additions and 22 deletions

View File

@ -102,14 +102,14 @@ export async function getShows({
isAvailable: sql<boolean>`${shows.availableCount} != 0`, isAvailable: sql<boolean>`${shows.availableCount} != 0`,
...(preferOriginal && { ...(preferOriginal && {
poster: sql<Image>`coalesce(${shows.original}->'poster', ${transQ.poster})`, poster: sql<Image>`coalesce(nullif(${shows.original}->'poster', 'null'::jsonb), ${transQ.poster})`,
thumbnail: sql<Image>`coalesce(${shows.original}->'thumbnail', ${transQ.thumbnail})`, thumbnail: sql<Image>`coalesce(nullif(${shows.original}->'thumbnail', 'null'::jsonb), ${transQ.thumbnail})`,
banner: sql<Image>`coalesce(${shows.original}->'banner', ${transQ.banner})`, banner: sql<Image>`coalesce(nullif(${shows.original}->'banner', 'null'::jsonb), ${transQ.banner})`,
logo: sql<Image>`coalesce(${shows.original}->'logo', ${transQ.logo})`, logo: sql<Image>`coalesce(nullif(${shows.original}->'logo', 'null'::jsonb), ${transQ.logo})`,
}), }),
}) })
.from(shows) .from(shows)
[fallbackLanguage ? "leftJoin" : "innerJoin"]( [fallbackLanguage ? "innerJoin" : "leftJoin"](
transQ, transQ,
eq(shows.pk, transQ.pk), eq(shows.pk, transQ.pk),
) )

View File

@ -8,6 +8,12 @@ export const bubbleVideo: Video = {
rendering: "459429fa062adeebedcc2bb04b9965de0262bfa453369783132d261be79021bd", rendering: "459429fa062adeebedcc2bb04b9965de0262bfa453369783132d261be79021bd",
part: null, part: null,
version: 1, version: 1,
guess: {
kind: "movie",
title: "bubble",
year: [2022],
from: "guessit",
},
createdAt: "2024-11-23T15:01:24.968Z", createdAt: "2024-11-23T15:01:24.968Z",
updatedAt: "2024-11-23T15:01:24.968Z", updatedAt: "2024-11-23T15:01:24.968Z",
}; };

View File

@ -8,6 +8,12 @@ export const dune1984Video: Video = {
rendering: "ea3a0f8f2f2c5b61a07f61e4e8d9f8e01b2b92bcbb6f5ed1151e1f61619c2c0f", rendering: "ea3a0f8f2f2c5b61a07f61e4e8d9f8e01b2b92bcbb6f5ed1151e1f61619c2c0f",
part: null, part: null,
version: 1, version: 1,
guess: {
kind: "movie",
title: "dune",
year: [1984],
from: "guessit",
},
createdAt: "2024-12-02T11:45:12.968Z", createdAt: "2024-12-02T11:45:12.968Z",
updatedAt: "2024-12-02T11:45:12.968Z", updatedAt: "2024-12-02T11:45:12.968Z",
}; };

View File

@ -8,6 +8,12 @@ export const duneVideo: Video = {
rendering: "f1953a4fb58247efb6c15b76468b6a9d13b4155b02094863b1a4f0c3fbb6db58", rendering: "f1953a4fb58247efb6c15b76468b6a9d13b4155b02094863b1a4f0c3fbb6db58",
part: null, part: null,
version: 1, version: 1,
guess: {
kind: "movie",
title: "dune",
year: [2021],
from: "guessit",
},
createdAt: "2024-12-02T10:10:24.968Z", createdAt: "2024-12-02T10:10:24.968Z",
updatedAt: "2024-12-02T10:10:24.968Z", updatedAt: "2024-12-02T10:10:24.968Z",
}; };

View File

@ -78,9 +78,10 @@ export const sortToSql = <
T extends string[], T extends string[],
Remap extends Partial<Record<T[number], string>>, Remap extends Partial<Record<T[number], string>>,
>( >(
sort: Sort<T, Remap>, sort: Sort<T, Remap> | undefined,
table: Table<Sort<T, Remap>["sort"][number]["key"] | "pk">, table: Table<Sort<T, Remap>["sort"][number]["key"] | "pk">,
) => { ) => {
if (!sort) return [];
if (sort.random) { if (sort.random) {
return [sql`md5(${sort.random.seed} || ${table.pk})`]; return [sql`md5(${sort.random.seed} || ${table.pk})`];
} }

View File

@ -1,6 +1,5 @@
import { beforeAll, describe, expect, it } from "bun:test"; import { beforeAll, describe, expect, it } from "bun:test";
import { expectStatus } from "tests/utils"; import { expectStatus } from "tests/utils";
import { seedMovie } from "~/controllers/seed/movies";
import { db } from "~/db"; import { db } from "~/db";
import { shows } from "~/db/schema"; import { shows } from "~/db/schema";
import { bubble } from "~/models/examples"; import { bubble } from "~/models/examples";
@ -10,7 +9,10 @@ import { app, createMovie, getMovies } from "../helpers";
beforeAll(async () => { beforeAll(async () => {
await db.delete(shows); await db.delete(shows);
for (const movie of [bubble, dune1984, dune]) await seedMovie(movie); for (const movie of [bubble, dune1984, dune]) {
const [ret, _] = await createMovie(movie);
expect(ret.status).toBe(201);
}
}); });
describe("with a null value", () => { describe("with a null value", () => {
@ -39,7 +41,7 @@ describe("with a null value", () => {
rating: null, rating: null,
runtime: null, runtime: null,
airDate: null, airDate: null,
originalLanguage: null, originalLanguage: "en",
externalId: {}, externalId: {},
studios: [], studios: [],
}); });

View File

@ -1,18 +1,19 @@
import { beforeAll, describe, expect, it } from "bun:test"; import { beforeAll, describe, expect, it } from "bun:test";
import { expectStatus } from "tests/utils"; import { expectStatus } from "tests/utils";
import { seedMovie } from "~/controllers/seed/movies";
import { db } from "~/db"; import { db } from "~/db";
import { shows } from "~/db/schema"; import { shows } from "~/db/schema";
import { bubble } from "~/models/examples"; import { bubble } from "~/models/examples";
import { dune1984 } from "~/models/examples/dune-1984"; import { dune1984 } from "~/models/examples/dune-1984";
import { dune } from "~/models/examples/dune-2021"; import { dune } from "~/models/examples/dune-2021";
import type { Movie } from "~/models/movie"; import type { Movie } from "~/models/movie";
import { isUuid } from "~/models/utils"; import { app, createMovie, getMovies } from "../helpers";
import { app, getMovies } from "../helpers";
beforeAll(async () => { beforeAll(async () => {
await db.delete(shows); await db.delete(shows);
for (const movie of [bubble, dune1984, dune]) await seedMovie(movie); for (const movie of [bubble, dune1984, dune]) {
const [ret, _] = await createMovie(movie);
expect(ret.status).toBe(201);
}
}); });
describe("Get all movies", () => { describe("Get all movies", () => {

View File

@ -1,18 +1,18 @@
import { beforeAll, describe, expect, it } from "bun:test"; import { beforeAll, describe, expect, it } from "bun:test";
import { expectStatus } from "tests/utils"; import { expectStatus } from "tests/utils";
import { seedMovie } from "~/controllers/seed/movies";
import { db } from "~/db"; import { db } from "~/db";
import { shows, videos } from "~/db/schema"; import { shows, videos } from "~/db/schema";
import { bubble, bubbleVideo } from "~/models/examples"; import { bubble, bubbleVideo } from "~/models/examples";
import { getMovie } from "../helpers"; import { createMovie, getMovie } from "../helpers";
let bubbleId = ""; let bubbleId = "";
beforeAll(async () => { beforeAll(async () => {
await db.delete(shows); await db.delete(shows);
await db.insert(videos).values(bubbleVideo); await db.insert(videos).values(bubbleVideo);
const ret = await seedMovie(bubble); const [ret, body] = await createMovie(bubble);
if (!("status" in ret)) bubbleId = ret.id; expect(ret.status).toBe(201)
bubbleId = body.id;
}); });
describe("Get movie", () => { describe("Get movie", () => {
@ -124,7 +124,7 @@ describe("Get movie", () => {
expect(body.isAvailable).toBe(true); expect(body.isAvailable).toBe(true);
}); });
it("With isAvailable=false", async () => { it("With isAvailable=false", async () => {
await seedMovie({ await createMovie({
...bubble, ...bubble,
slug: "no-video", slug: "no-video",
videos: [], videos: [],

View File

@ -168,7 +168,7 @@ describe("Movie seeding", () => {
const [resp, body] = await createMovie({ const [resp, body] = await createMovie({
...bubble, ...bubble,
slug: "casing-test", slug: "casing-test",
originalLanguage: "jp-jp", originalLanguage: "en-us",
translations: { translations: {
"en-us": { "en-us": {
name: "foo", name: "foo",
@ -191,7 +191,7 @@ describe("Movie seeding", () => {
where: eq(shows.id, body.id), where: eq(shows.id, body.id),
with: { translations: true }, with: { translations: true },
}); });
expect(ret!.originalLanguage).toBe("jp-JP"); expect(ret!.original.language).toBe("en-US");
expect(ret!.translations).toBeArrayOfSize(2); expect(ret!.translations).toBeArrayOfSize(2);
expect(ret!.translations).toEqual( expect(ret!.translations).toEqual(
expect.arrayContaining([ expect.arrayContaining([
@ -229,7 +229,10 @@ describe("Movie seeding", () => {
const [resp, body] = await createMovie({ const [resp, body] = await createMovie({
...bubble, ...bubble,
slug: "bubble-translation-test", slug: "bubble-translation-test",
translations: { "en-us": bubble.translations.en }, translations: {
"en-us": bubble.translations.en,
ja: bubble.translations.ja,
},
}); });
expectStatus(resp, body).toBe(201); expectStatus(resp, body).toBe(201);
@ -262,6 +265,7 @@ describe("Movie seeding", () => {
"en-us": bubble.translations.en, "en-us": bubble.translations.en,
"en-au": { ...bubble.translations.en, name: "australian thing" }, "en-au": { ...bubble.translations.en, name: "australian thing" },
en: { ...bubble.translations.en, name: "Generic" }, en: { ...bubble.translations.en, name: "Generic" },
ja: bubble.translations.ja,
}, },
}); });
expectStatus(resp, body).toBe(201); expectStatus(resp, body).toBe(201);
@ -304,6 +308,7 @@ describe("Movie seeding", () => {
part: null, part: null,
version: 1, version: 1,
rendering: "oeunhtoeuth", rendering: "oeunhtoeuth",
guess: { title: "bubble", from: "test" },
}); });
expectStatus(vresp, video).toBe(201); expectStatus(vresp, video).toBe(201);
@ -329,6 +334,7 @@ describe("Movie seeding", () => {
part: null, part: null,
version: 2, version: 2,
rendering: "oeunhtoeuth", rendering: "oeunhtoeuth",
guess: { title: "bubble", from: "test" },
}); });
expectStatus(vresp, video).toBe(201); expectStatus(vresp, video).toBe(201);
@ -353,6 +359,7 @@ describe("Movie seeding", () => {
part: 1, part: 1,
version: 2, version: 2,
rendering: "oaoeueunhtoeuth", rendering: "oaoeueunhtoeuth",
guess: { title: "bubble", from: "test" },
}); });
expectStatus(vresp, video).toBe(201); expectStatus(vresp, video).toBe(201);
@ -378,12 +385,14 @@ describe("Movie seeding", () => {
part: null, part: null,
version: 1, version: 1,
rendering: "oeunhtoeuth", rendering: "oeunhtoeuth",
guess: { title: "bubble", from: "test" },
}, },
{ {
path: "/video/bubble4.mkv", path: "/video/bubble4.mkv",
part: null, part: null,
version: 1, version: 1,
rendering: "aoeuaoeu", rendering: "aoeuaoeu",
guess: { title: "bubble", from: "test" },
}, },
]); ]);
expectStatus(vresp, video).toBe(201); expectStatus(vresp, video).toBe(201);

View File

@ -12,7 +12,7 @@ beforeAll(async () => {
await createSerie(madeInAbyss); await createSerie(madeInAbyss);
}); });
describe("aet series", () => { describe("Get series", () => {
it("Invalid slug", async () => { it("Invalid slug", async () => {
const [resp, body] = await getSerie("sotneuhn", { langs: "en" }); const [resp, body] = await getSerie("sotneuhn", { langs: "en" });