mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-01 20:54:13 -04:00
Test missing accept-language endpoint
This commit is contained in:
parent
3a7a12bfd3
commit
a4853cb186
@ -49,7 +49,8 @@ export const Language = (props?: StringProps) =>
|
|||||||
...props,
|
...props,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const processLanguages = (languages: string) => {
|
export const processLanguages = (languages?: string) => {
|
||||||
|
if (!languages) return ["*"];
|
||||||
return languages
|
return languages
|
||||||
.split(",")
|
.split(",")
|
||||||
.map((x) => {
|
.map((x) => {
|
||||||
|
@ -9,13 +9,15 @@ import { shows } from "~/db/schema";
|
|||||||
import { bubble } from "~/models/examples";
|
import { bubble } from "~/models/examples";
|
||||||
|
|
||||||
const app = new Elysia().use(base).use(movies);
|
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(
|
const resp = await app.handle(
|
||||||
new Request(`http://localhost/movies/${id}`, {
|
new Request(`http://localhost/movies/${id}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: langs
|
||||||
|
? {
|
||||||
"Accept-Language": langs,
|
"Accept-Language": langs,
|
||||||
},
|
}
|
||||||
|
: {},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const body = await resp.json();
|
const body = await resp.json();
|
||||||
@ -74,6 +76,16 @@ describe("Get movie", () => {
|
|||||||
it("Use language fallback", async () => {
|
it("Use language fallback", async () => {
|
||||||
const [resp, body] = await getMovie(bubble.slug, "fr,ja,*");
|
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);
|
expectStatus(resp, body).toBe(200);
|
||||||
expect(body).toMatchObject({
|
expect(body).toMatchObject({
|
||||||
slug: bubble.slug,
|
slug: bubble.slug,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user