diff --git a/api/src/models/utils/language.ts b/api/src/models/utils/language.ts index 4706cd40..afc58ea1 100644 --- a/api/src/models/utils/language.ts +++ b/api/src/models/utils/language.ts @@ -49,7 +49,8 @@ export const Language = (props?: StringProps) => ...props, }); -export const processLanguages = (languages: string) => { +export const processLanguages = (languages?: string) => { + if (!languages) return ["*"]; return languages .split(",") .map((x) => { diff --git a/api/tests/get-movies.test.ts b/api/tests/get-movies.test.ts index 95f5e86b..fca0d08a 100644 --- a/api/tests/get-movies.test.ts +++ b/api/tests/get-movies.test.ts @@ -9,13 +9,15 @@ import { shows } from "~/db/schema"; import { bubble } from "~/models/examples"; const app = new Elysia().use(base).use(movies); -const getMovie = async (id: string, langs: string) => { +const getMovie = async (id: string, langs?: string) => { const resp = await app.handle( new Request(`http://localhost/movies/${id}`, { method: "GET", - headers: { - "Accept-Language": langs, - }, + headers: langs + ? { + "Accept-Language": langs, + } + : {}, }), ); const body = await resp.json(); @@ -74,6 +76,16 @@ describe("Get movie", () => { it("Use language fallback", async () => { const [resp, body] = await getMovie(bubble.slug, "fr,ja,*"); + expectStatus(resp, body).toBe(200); + expect(body).toMatchObject({ + slug: bubble.slug, + name: bubble.translations.en.name, + }); + expect(resp.headers.get("Content-Language")).toBe("en"); + }); + it("Works without accept-language header", async () => { + const [resp, body] = await getMovie(bubble.slug, undefined); + expectStatus(resp, body).toBe(200); expect(body).toMatchObject({ slug: bubble.slug,