Add get by studio tests

This commit is contained in:
Zoe Roux 2025-03-03 09:36:38 +01:00
parent 4d9547952e
commit ff5fc69d41
No known key found for this signature in database
3 changed files with 62 additions and 1 deletions

View File

@ -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}'.`,

View File

@ -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;
};

View File

@ -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);
});
});