diff --git a/api/src/controllers/shows/logic.ts b/api/src/controllers/shows/logic.ts index d832871b..7d11ee6e 100644 --- a/api/src/controllers/shows/logic.ts +++ b/api/src/controllers/shows/logic.ts @@ -88,6 +88,7 @@ export async function getShows({ status: sql`${shows.status}`, airDate: shows.startAir, kind: sql`${shows.kind}`, + isAvailable: sql`${shows.availableCount} != 0`, poster: sql`coalesce(${showTranslations.poster}, ${poster})`, thumbnail: sql`coalesce(${showTranslations.thumbnail}, ${thumbnail})`, @@ -138,6 +139,7 @@ export async function getShow( extras: { airDate: sql`${shows.startAir}`.as("airDate"), status: sql`${shows.status}`.as("status"), + isAvailable: sql`${shows.availableCount} != 0`.as("isAvailable"), }, where: and(isUuid(id) ? eq(shows.id, id) : eq(shows.slug, id), filters), with: { diff --git a/api/src/models/movie.ts b/api/src/models/movie.ts index 5285d374..0e70cce6 100644 --- a/api/src/models/movie.ts +++ b/api/src/models/movie.ts @@ -59,7 +59,9 @@ export const Movie = t.Intersect([ MovieTranslation, BaseMovie, DbMetadata, - // t.Object({ isAvailable: t.Boolean() }), + t.Object({ + isAvailable: t.Boolean(), + }), ]); export type Movie = Prettify; diff --git a/api/tests/movies/get-movie.test.ts b/api/tests/movies/get-movie.test.ts index b282c882..f3b266ac 100644 --- a/api/tests/movies/get-movie.test.ts +++ b/api/tests/movies/get-movie.test.ts @@ -2,14 +2,15 @@ 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 { shows, videos } from "~/db/schema"; +import { bubble, bubbleVideo } from "~/models/examples"; import { 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; }); @@ -116,4 +117,21 @@ describe("Get movie", () => { }); expect(resp.headers.get("Content-Language")).toBe("en"); }); + it("With isAvailable", async () => { + const [resp, body] = await getMovie(bubble.slug, {}); + + expectStatus(resp, body).toBe(200); + expect(body.isAvailable).toBe(true); + }); + it("With isAvailable=false", async () => { + await seedMovie({ + ...bubble, + slug: "no-video", + videos: [], + }); + const [resp, body] = await getMovie("no-video", {}); + + expectStatus(resp, body).toBe(200); + expect(body.isAvailable).toBe(false); + }); }); diff --git a/api/tests/series/get-series.test.ts b/api/tests/series/get-series.test.ts index b89bf827..b2e7a14b 100644 --- a/api/tests/series/get-series.test.ts +++ b/api/tests/series/get-series.test.ts @@ -1,9 +1,10 @@ import { beforeAll, describe, expect, it } from "bun:test"; -import { createSerie, getSerie } from "tests/helpers"; +import { createSerie, createVideo, getSerie } from "tests/helpers"; import { expectStatus } from "tests/utils"; -import { madeInAbyss } from "~/models/examples"; +import { madeInAbyss, madeInAbyssVideo } from "~/models/examples"; beforeAll(async () => { + await createVideo(madeInAbyssVideo); await createSerie(madeInAbyss); }); @@ -20,7 +21,6 @@ describe("Get seasons", () => { it("With a valid entryCount/availableCount", async () => { const [resp, body] = await getSerie(madeInAbyss.slug, { langs: "en" }); - console.log(body) expectStatus(resp, body).toBe(200); expect(body.entriesCount).toBe(madeInAbyss.entries.length); expect(body.availableCount).toBe(1);