Test get seasons

This commit is contained in:
Zoe Roux 2025-03-01 19:42:53 +01:00
parent 6a30173628
commit b5460682c9
3 changed files with 59 additions and 0 deletions

View File

@ -16,6 +16,35 @@ export const createSerie = async (serie: SeedSerie) => {
return [resp, body] as const;
};
export const getSeasons = async (
serie: 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(`series/${serie}/seasons`, opts), {
method: "GET",
headers: langs
? {
"Accept-Language": langs,
}
: {},
}),
);
const body = await resp.json();
return [resp, body] as const;
};
export const getEntries = async (
serie: string,
{

View File

@ -0,0 +1,30 @@
import { beforeAll, describe, expect, it } from "bun:test";
import { getSeasons } from "tests/helpers";
import { expectStatus } from "tests/utils";
import { seedSerie } from "~/controllers/seed/series";
import { madeInAbyss } from "~/models/examples";
let miaId = "";
beforeAll(async () => {
const ret = await seedSerie(madeInAbyss);
if (!("status" in ret)) miaId = ret.id;
});
describe("Get seasons", () => {
it("Invalid slug", async () => {
const [resp, body] = await getSeasons("sotneuhn", { langs: "en" });
expectStatus(resp, body).toBe(404);
expect(body).toMatchObject({
status: 404,
message: expect.any(String),
});
});
it("Default sort order", async () => {
const [resp, body] = await getSeasons(madeInAbyss.slug, { langs: "en" });
expectStatus(resp, body).toBe(200);
expect(body.items).toBeArrayOfSize(madeInAbyss.seasons.length);
});
});