From ff5fc69d4142d7ec74ee9decb10f47a1a04f3b6d Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 3 Mar 2025 09:36:38 +0100 Subject: [PATCH] Add get by studio tests --- api/src/controllers/studios.ts | 2 +- api/tests/helpers/studio-helper.ts | 31 ++++++++++++++++++++++++++++++ api/tests/series/studios.test.ts | 30 +++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 api/tests/helpers/studio-helper.ts create mode 100644 api/tests/series/studios.test.ts diff --git a/api/src/controllers/studios.ts b/api/src/controllers/studios.ts index 2eeb5e8e..dd6799a8 100644 --- a/api/src/controllers/studios.ts +++ b/api/src/controllers/studios.ts @@ -36,7 +36,7 @@ export const studiosH = new Elysia({ tags: ["studios"] }) .where(isUuid(id) ? eq(studios.id, id) : eq(studios.slug, id)) .limit(1); - if (!studios) { + if (!studio) { return error(404, { status: 404, message: `No studios with the id or slug: '${id}'.`, diff --git a/api/tests/helpers/studio-helper.ts b/api/tests/helpers/studio-helper.ts new file mode 100644 index 00000000..42f80160 --- /dev/null +++ b/api/tests/helpers/studio-helper.ts @@ -0,0 +1,31 @@ +import { buildUrl } from "tests/utils"; +import { app } from "~/elysia"; + +export const getShowsByStudio = async ( + studio: string, + { + langs, + ...opts + }: { + filter?: string; + limit?: number; + after?: string; + sort?: string | string[]; + query?: string; + langs?: string; + preferOriginal?: boolean; + }, +) => { + const resp = await app.handle( + new Request(buildUrl(`studios/${studio}/shows`, opts), { + method: "GET", + headers: langs + ? { + "Accept-Language": langs, + } + : {}, + }), + ); + const body = await resp.json(); + return [resp, body] as const; +}; diff --git a/api/tests/series/studios.test.ts b/api/tests/series/studios.test.ts new file mode 100644 index 00000000..4d2b6c21 --- /dev/null +++ b/api/tests/series/studios.test.ts @@ -0,0 +1,30 @@ +import { beforeAll, describe, expect, it } from "bun:test"; +import { getShowsByStudio } from "tests/helpers/studio-helper"; +import { expectStatus } from "tests/utils"; +import { seedSerie } from "~/controllers/seed/series"; +import { madeInAbyss } from "~/models/examples"; + +beforeAll(async () => { + await seedSerie(madeInAbyss); +}); + +describe("Get by studio", () => { + it("Invalid slug", async () => { + const [resp, body] = await getShowsByStudio("sotneuhn", { langs: "en" }); + + expectStatus(resp, body).toBe(404); + expect(body).toMatchObject({ + status: 404, + message: expect.any(String), + }); + }); + it("Get serie from studio", async () => { + const [resp, body] = await getShowsByStudio(madeInAbyss.studios[0].slug, { + langs: "en", + }); + + expectStatus(resp, body).toBe(200); + expect(body.items).toBeArrayOfSize(1); + expect(body.items[0].slug).toBe(madeInAbyss.slug); + }); +});