mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 12:14:46 -04:00
Add get by studio tests
This commit is contained in:
parent
4d9547952e
commit
ff5fc69d41
@ -36,7 +36,7 @@ export const studiosH = new Elysia({ tags: ["studios"] })
|
|||||||
.where(isUuid(id) ? eq(studios.id, id) : eq(studios.slug, id))
|
.where(isUuid(id) ? eq(studios.id, id) : eq(studios.slug, id))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
if (!studios) {
|
if (!studio) {
|
||||||
return error(404, {
|
return error(404, {
|
||||||
status: 404,
|
status: 404,
|
||||||
message: `No studios with the id or slug: '${id}'.`,
|
message: `No studios with the id or slug: '${id}'.`,
|
||||||
|
31
api/tests/helpers/studio-helper.ts
Normal file
31
api/tests/helpers/studio-helper.ts
Normal 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;
|
||||||
|
};
|
30
api/tests/series/studios.test.ts
Normal file
30
api/tests/series/studios.test.ts
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user