diff --git a/api/src/controllers/seed/insert/shows.ts b/api/src/controllers/seed/insert/shows.ts index f5e6d9c7..62ef4a65 100644 --- a/api/src/controllers/seed/insert/shows.ts +++ b/api/src/controllers/seed/insert/shows.ts @@ -1,4 +1,4 @@ -import { and, count, eq, exists, sql } from "drizzle-orm"; +import { and, count, eq, exists, ne, sql } from "drizzle-orm"; import { db } from "~/db"; import { entries, entryVideoJoin, showTranslations, shows } from "~/db/schema"; import { conflictUpdateAllExcept, sqlarr } from "~/db/utils"; @@ -107,6 +107,7 @@ export async function updateAvailableCount( .where( and( eq(entries.showPk, shows.pk), + ne(entries.kind, "extra"), exists( db .select() @@ -119,7 +120,9 @@ export async function updateAvailableCount( entriesCount: sql`${db .select({ count: count() }) .from(entries) - .where(eq(entries.showPk, shows.pk))}`, + .where( + and(eq(entries.showPk, shows.pk), ne(entries.kind, "extra")), + )}`, }), }) .where(eq(shows.pk, sql`any(${sqlarr(showPks)})`)); diff --git a/api/tests/series/get-series.test.ts b/api/tests/series/get-series.test.ts new file mode 100644 index 00000000..b89bf827 --- /dev/null +++ b/api/tests/series/get-series.test.ts @@ -0,0 +1,28 @@ +import { beforeAll, describe, expect, it } from "bun:test"; +import { createSerie, getSerie } from "tests/helpers"; +import { expectStatus } from "tests/utils"; +import { madeInAbyss } from "~/models/examples"; + +beforeAll(async () => { + await createSerie(madeInAbyss); +}); + +describe("Get seasons", () => { + it("Invalid slug", async () => { + const [resp, body] = await getSerie("sotneuhn", { langs: "en" }); + + expectStatus(resp, body).toBe(404); + expect(body).toMatchObject({ + status: 404, + message: expect.any(String), + }); + }); + 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); + }); +});