Test extras

This commit is contained in:
Zoe Roux 2025-03-01 19:55:41 +01:00
parent 655f677e91
commit 84d9ccb8bb
2 changed files with 54 additions and 1 deletions

View File

@ -73,3 +73,38 @@ export const getEntries = async (
const body = await resp.json(); const body = await resp.json();
return [resp, body] as const; return [resp, body] as const;
}; };
export const getExtras = async (
serie: string,
opts: {
filter?: string;
limit?: number;
after?: string;
sort?: string | string[];
query?: string;
},
) => {
const resp = await app.handle(
new Request(buildUrl(`series/${serie}/extras`, opts), {
method: "GET",
}),
);
const body = await resp.json();
return [resp, body] as const;
};
export const getUnknowns = async (opts: {
filter?: string;
limit?: number;
after?: string;
sort?: string | string[];
query?: string;
}) => {
const resp = await app.handle(
new Request(buildUrl(`unknowns`, opts), {
method: "GET",
}),
);
const body = await resp.json();
return [resp, body] as const;
};

View File

@ -1,5 +1,5 @@
import { beforeAll, describe, expect, it } from "bun:test"; import { beforeAll, describe, expect, it } from "bun:test";
import { getEntries } from "tests/helpers"; import { getEntries, getExtras } from "tests/helpers";
import { expectStatus } from "tests/utils"; import { expectStatus } from "tests/utils";
import { seedSerie } from "~/controllers/seed/series"; import { seedSerie } from "~/controllers/seed/series";
import { madeInAbyss } from "~/models/examples"; import { madeInAbyss } from "~/models/examples";
@ -28,3 +28,21 @@ describe("Get entries", () => {
expect(body.items).toBeArrayOfSize(madeInAbyss.entries.length); expect(body.items).toBeArrayOfSize(madeInAbyss.entries.length);
}); });
}); });
describe("Get extra", () => {
it("Invalid slug", async () => {
const [resp, body] = await getExtras("sotneuhn", {});
expectStatus(resp, body).toBe(404);
expect(body).toMatchObject({
status: 404,
message: expect.any(String),
});
});
it("Default sort order", async () => {
const [resp, body] = await getExtras(madeInAbyss.slug, {});
expectStatus(resp, body).toBe(200);
expect(body.items).toBeArrayOfSize(madeInAbyss.extras.length);
});
});