diff --git a/api/src/controllers/shows/logic.ts b/api/src/controllers/shows/logic.ts index f12cc139..d8548fd8 100644 --- a/api/src/controllers/shows/logic.ts +++ b/api/src/controllers/shows/logic.ts @@ -102,14 +102,14 @@ export async function getShows({ isAvailable: sql`${shows.availableCount} != 0`, ...(preferOriginal && { - poster: sql`coalesce(${shows.original}->'poster', ${transQ.poster})`, - thumbnail: sql`coalesce(${shows.original}->'thumbnail', ${transQ.thumbnail})`, - banner: sql`coalesce(${shows.original}->'banner', ${transQ.banner})`, - logo: sql`coalesce(${shows.original}->'logo', ${transQ.logo})`, + poster: sql`coalesce(nullif(${shows.original}->'poster', 'null'::jsonb), ${transQ.poster})`, + thumbnail: sql`coalesce(nullif(${shows.original}->'thumbnail', 'null'::jsonb), ${transQ.thumbnail})`, + banner: sql`coalesce(nullif(${shows.original}->'banner', 'null'::jsonb), ${transQ.banner})`, + logo: sql`coalesce(nullif(${shows.original}->'logo', 'null'::jsonb), ${transQ.logo})`, }), }) .from(shows) - [fallbackLanguage ? "leftJoin" : "innerJoin"]( + [fallbackLanguage ? "innerJoin" : "leftJoin"]( transQ, eq(shows.pk, transQ.pk), ) diff --git a/api/src/models/examples/bubble.ts b/api/src/models/examples/bubble.ts index 9f66f701..1326f7b4 100644 --- a/api/src/models/examples/bubble.ts +++ b/api/src/models/examples/bubble.ts @@ -8,6 +8,12 @@ export const bubbleVideo: Video = { rendering: "459429fa062adeebedcc2bb04b9965de0262bfa453369783132d261be79021bd", part: null, version: 1, + guess: { + kind: "movie", + title: "bubble", + year: [2022], + from: "guessit", + }, createdAt: "2024-11-23T15:01:24.968Z", updatedAt: "2024-11-23T15:01:24.968Z", }; diff --git a/api/src/models/examples/dune-1984.ts b/api/src/models/examples/dune-1984.ts index d12b94e1..34084f77 100644 --- a/api/src/models/examples/dune-1984.ts +++ b/api/src/models/examples/dune-1984.ts @@ -8,6 +8,12 @@ export const dune1984Video: Video = { rendering: "ea3a0f8f2f2c5b61a07f61e4e8d9f8e01b2b92bcbb6f5ed1151e1f61619c2c0f", part: null, version: 1, + guess: { + kind: "movie", + title: "dune", + year: [1984], + from: "guessit", + }, createdAt: "2024-12-02T11:45:12.968Z", updatedAt: "2024-12-02T11:45:12.968Z", }; diff --git a/api/src/models/examples/dune-2021.ts b/api/src/models/examples/dune-2021.ts index d3b7b59f..08cb3499 100644 --- a/api/src/models/examples/dune-2021.ts +++ b/api/src/models/examples/dune-2021.ts @@ -8,6 +8,12 @@ export const duneVideo: Video = { rendering: "f1953a4fb58247efb6c15b76468b6a9d13b4155b02094863b1a4f0c3fbb6db58", part: null, version: 1, + guess: { + kind: "movie", + title: "dune", + year: [2021], + from: "guessit", + }, createdAt: "2024-12-02T10:10:24.968Z", updatedAt: "2024-12-02T10:10:24.968Z", }; diff --git a/api/src/models/utils/sort.ts b/api/src/models/utils/sort.ts index d9a4c177..1a302325 100644 --- a/api/src/models/utils/sort.ts +++ b/api/src/models/utils/sort.ts @@ -78,9 +78,10 @@ export const sortToSql = < T extends string[], Remap extends Partial>, >( - sort: Sort, + sort: Sort | undefined, table: Table["sort"][number]["key"] | "pk">, ) => { + if (!sort) return []; if (sort.random) { return [sql`md5(${sort.random.seed} || ${table.pk})`]; } diff --git a/api/tests/movies/get-all-movies-with-null.test.ts b/api/tests/movies/get-all-movies-with-null.test.ts index 30d5932f..5b633510 100644 --- a/api/tests/movies/get-all-movies-with-null.test.ts +++ b/api/tests/movies/get-all-movies-with-null.test.ts @@ -1,6 +1,5 @@ import { beforeAll, describe, expect, it } from "bun:test"; import { expectStatus } from "tests/utils"; -import { seedMovie } from "~/controllers/seed/movies"; import { db } from "~/db"; import { shows } from "~/db/schema"; import { bubble } from "~/models/examples"; @@ -10,7 +9,10 @@ import { app, createMovie, getMovies } from "../helpers"; beforeAll(async () => { 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", () => { @@ -39,7 +41,7 @@ describe("with a null value", () => { rating: null, runtime: null, airDate: null, - originalLanguage: null, + originalLanguage: "en", externalId: {}, studios: [], }); diff --git a/api/tests/movies/get-all-movies.test.ts b/api/tests/movies/get-all-movies.test.ts index fc8776f5..9eb9f2af 100644 --- a/api/tests/movies/get-all-movies.test.ts +++ b/api/tests/movies/get-all-movies.test.ts @@ -1,18 +1,19 @@ import { beforeAll, describe, expect, it } from "bun:test"; import { expectStatus } from "tests/utils"; -import { seedMovie } from "~/controllers/seed/movies"; import { db } from "~/db"; import { shows } from "~/db/schema"; import { bubble } from "~/models/examples"; import { dune1984 } from "~/models/examples/dune-1984"; import { dune } from "~/models/examples/dune-2021"; import type { Movie } from "~/models/movie"; -import { isUuid } from "~/models/utils"; -import { app, getMovies } from "../helpers"; +import { app, createMovie, getMovies } from "../helpers"; beforeAll(async () => { 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", () => { diff --git a/api/tests/movies/get-movie.test.ts b/api/tests/movies/get-movie.test.ts index f3b266ac..687e0dd8 100644 --- a/api/tests/movies/get-movie.test.ts +++ b/api/tests/movies/get-movie.test.ts @@ -1,18 +1,18 @@ import { beforeAll, describe, expect, it } from "bun:test"; import { expectStatus } from "tests/utils"; -import { seedMovie } from "~/controllers/seed/movies"; import { db } from "~/db"; import { shows, videos } from "~/db/schema"; import { bubble, bubbleVideo } from "~/models/examples"; -import { getMovie } from "../helpers"; +import { createMovie, getMovie } from "../helpers"; let bubbleId = ""; beforeAll(async () => { await db.delete(shows); await db.insert(videos).values(bubbleVideo); - const ret = await seedMovie(bubble); - if (!("status" in ret)) bubbleId = ret.id; + const [ret, body] = await createMovie(bubble); + expect(ret.status).toBe(201) + bubbleId = body.id; }); describe("Get movie", () => { @@ -124,7 +124,7 @@ describe("Get movie", () => { expect(body.isAvailable).toBe(true); }); it("With isAvailable=false", async () => { - await seedMovie({ + await createMovie({ ...bubble, slug: "no-video", videos: [], diff --git a/api/tests/movies/seed-movies.test.ts b/api/tests/movies/seed-movies.test.ts index bbc8b4d9..611be355 100644 --- a/api/tests/movies/seed-movies.test.ts +++ b/api/tests/movies/seed-movies.test.ts @@ -168,7 +168,7 @@ describe("Movie seeding", () => { const [resp, body] = await createMovie({ ...bubble, slug: "casing-test", - originalLanguage: "jp-jp", + originalLanguage: "en-us", translations: { "en-us": { name: "foo", @@ -191,7 +191,7 @@ describe("Movie seeding", () => { where: eq(shows.id, body.id), with: { translations: true }, }); - expect(ret!.originalLanguage).toBe("jp-JP"); + expect(ret!.original.language).toBe("en-US"); expect(ret!.translations).toBeArrayOfSize(2); expect(ret!.translations).toEqual( expect.arrayContaining([ @@ -229,7 +229,10 @@ describe("Movie seeding", () => { const [resp, body] = await createMovie({ ...bubble, 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); @@ -262,6 +265,7 @@ describe("Movie seeding", () => { "en-us": bubble.translations.en, "en-au": { ...bubble.translations.en, name: "australian thing" }, en: { ...bubble.translations.en, name: "Generic" }, + ja: bubble.translations.ja, }, }); expectStatus(resp, body).toBe(201); @@ -304,6 +308,7 @@ describe("Movie seeding", () => { part: null, version: 1, rendering: "oeunhtoeuth", + guess: { title: "bubble", from: "test" }, }); expectStatus(vresp, video).toBe(201); @@ -329,6 +334,7 @@ describe("Movie seeding", () => { part: null, version: 2, rendering: "oeunhtoeuth", + guess: { title: "bubble", from: "test" }, }); expectStatus(vresp, video).toBe(201); @@ -353,6 +359,7 @@ describe("Movie seeding", () => { part: 1, version: 2, rendering: "oaoeueunhtoeuth", + guess: { title: "bubble", from: "test" }, }); expectStatus(vresp, video).toBe(201); @@ -378,12 +385,14 @@ describe("Movie seeding", () => { part: null, version: 1, rendering: "oeunhtoeuth", + guess: { title: "bubble", from: "test" }, }, { path: "/video/bubble4.mkv", part: null, version: 1, rendering: "aoeuaoeu", + guess: { title: "bubble", from: "test" }, }, ]); expectStatus(vresp, video).toBe(201); diff --git a/api/tests/series/get-series.test.ts b/api/tests/series/get-series.test.ts index 28ab3fb6..2cdfb3c7 100644 --- a/api/tests/series/get-series.test.ts +++ b/api/tests/series/get-series.test.ts @@ -12,7 +12,7 @@ beforeAll(async () => { await createSerie(madeInAbyss); }); -describe("aet series", () => { +describe("Get series", () => { it("Invalid slug", async () => { const [resp, body] = await getSerie("sotneuhn", { langs: "en" });