Test ?with=

This commit is contained in:
Zoe Roux 2025-03-03 18:11:39 +01:00
parent 750434465d
commit cdf4ab4941
No known key found for this signature in database
5 changed files with 49 additions and 10 deletions

View File

@ -20,4 +20,3 @@ export const externalid = () =>
>() >()
.notNull() .notNull()
.default({}); .default({});

View File

@ -1,13 +1,14 @@
import { t } from "elysia"; import { t } from "elysia";
import { comment } from "../../utils"; import { comment } from "../../utils";
export const ExternalId = () => t.Record( export const ExternalId = () =>
t.Record(
t.String(), t.String(),
t.Object({ t.Object({
dataId: t.String(), dataId: t.String(),
link: t.Nullable(t.String({ format: "uri" })), link: t.Nullable(t.String({ format: "uri" })),
}), }),
); );
export const EpisodeId = t.Record( export const EpisodeId = t.Record(
t.String(), t.String(),

View File

@ -4,7 +4,10 @@ import type { SeedMovie } from "~/models/movie";
export const getMovie = async ( export const getMovie = async (
id: string, id: string,
{ langs, ...query }: { langs?: string; preferOriginal?: boolean }, {
langs,
...query
}: { langs?: string; preferOriginal?: boolean; with?: string[] },
) => { ) => {
const resp = await app.handle( const resp = await app.handle(
new Request(buildUrl(`movies/${id}`, query), { new Request(buildUrl(`movies/${id}`, query), {

View File

@ -16,6 +16,27 @@ export const createSerie = async (serie: SeedSerie) => {
return [resp, body] as const; return [resp, body] as const;
}; };
export const getSerie = async (
id: string,
{
langs,
...query
}: { langs?: string; preferOriginal?: boolean; with?: string[] },
) => {
const resp = await app.handle(
new Request(buildUrl(`series/${id}`, query), {
method: "GET",
headers: langs
? {
"Accept-Language": langs,
}
: {},
}),
);
const body = await resp.json();
return [resp, body] as const;
};
export const getSeasons = async ( export const getSeasons = async (
serie: string, serie: string,
{ {

View File

@ -1,5 +1,5 @@
import { beforeAll, describe, expect, it } from "bun:test"; import { beforeAll, describe, expect, it } from "bun:test";
import { getShowsByStudio, getStudio } from "tests/helpers"; import { getSerie, getShowsByStudio, getStudio } 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";
@ -46,4 +46,19 @@ describe("Get a studio", () => {
expectStatus(resp, body).toBe(200); expectStatus(resp, body).toBe(200);
expect(body.slug).toBe(slug); expect(body.slug).toBe(slug);
}); });
it("Get using /shows?with=", async () => {
const [resp, body] = await getSerie(madeInAbyss.slug, {
langs: "en",
with: ["studios"],
});
expectStatus(resp, body).toBe(200);
expect(body.slug).toBe(madeInAbyss.slug);
expect(body.studios).toBeArrayOfSize(1);
const studio = madeInAbyss.studios[0];
expect(body.studios[0]).toMatchObject({
slug: studio.slug,
name: studio.translations.en.name,
});
});
}); });