Add tests for preferOriginal in /movies

This commit is contained in:
Zoe Roux 2025-01-17 18:46:49 +01:00
parent a558f47558
commit a734a40668
3 changed files with 84 additions and 5 deletions

View File

@ -199,4 +199,82 @@ describe("Get all movies", () => {
expect(isUuid(id)).toBe(true);
});
});
it("Limit 2, fallback lang, prefer original", async () => {
const [resp, body] = await getMovies({
limit: 2,
langs: "en-au",
preferOriginal: true,
});
expectStatus(resp, body).toBe(200);
expect(body.items[0]).toMatchObject({
slug: bubble.slug,
name: bubble.translations.en.name,
poster: {
source: bubble.translations.ja.poster,
},
thumbnail: {
source: bubble.translations.ja.thumbnail,
},
banner: null,
// we fallback to the translated value when the original is null.
logo: { source: bubble.translations.en.logo },
});
expect(body.items[1]).toMatchObject({
slug: dune.slug,
name: dune.translations.en.name,
});
});
it("Limit 2, * lang, prefer original", async () => {
const [resp, body] = await getMovies({
limit: 2,
langs: "*",
preferOriginal: true,
});
expectStatus(resp, body).toBe(200);
expect(body.items[0]).toMatchObject({
slug: bubble.slug,
name: bubble.translations.en.name,
poster: {
source: bubble.translations.ja.poster,
},
thumbnail: {
source: bubble.translations.ja.thumbnail,
},
banner: null,
// we fallback to the translated value when the original is null.
logo: { source: bubble.translations.en.logo },
});
expect(body.items[1]).toMatchObject({
slug: dune.slug,
name: dune.translations.en.name,
});
});
it("Limit 2, unknown lang, prefer original", async () => {
const [resp, body] = await getMovies({
limit: 2,
langs: "toto",
preferOriginal: true,
});
expectStatus(resp, body).toBe(200);
expect(body.items[0]).toMatchObject({
slug: bubble.slug,
name: bubble.translations.en.name,
poster: {
source: bubble.translations.ja.poster,
},
thumbnail: {
source: bubble.translations.ja.thumbnail,
},
banner: null,
// we fallback to the translated value when the original is null.
logo: { source: bubble.translations.en.logo },
});
expect(body.items[1]).toMatchObject({
slug: dune.slug,
name: dune.translations.en.name,
});
});
});

View File

@ -101,15 +101,15 @@ describe("Get movie", () => {
expect(body).toMatchObject({
slug: bubble.slug,
name: bubble.translations.en.name,
poster: ({
poster: {
source: bubble.translations.ja.poster,
}),
thumbnail: ({
},
thumbnail: {
source: bubble.translations.ja.thumbnail,
}),
},
banner: null,
// we fallback to the translated value when the original is null.
logo: ({ source: bubble.translations.en.logo }),
logo: { source: bubble.translations.en.logo },
});
expect(resp.headers.get("Content-Language")).toBe("en");
});

View File

@ -34,6 +34,7 @@ export const getMovies = async ({
after?: string;
sort?: string | string[];
langs?: string;
preferOriginal?: boolean;
}) => {
const resp = await movieApp.handle(
new Request(buildUrl("movies", query), {