Fix api tests

This commit is contained in:
Zoe Roux 2025-07-19 00:25:22 +02:00
parent ec204d04e1
commit 7939cc1c79
3 changed files with 13 additions and 13 deletions

View File

@ -69,9 +69,9 @@ describe("with a null value", () => {
expect.objectContaining({ slug: bubble.slug, airDate: bubble.airDate }), expect.objectContaining({ slug: bubble.slug, airDate: bubble.airDate }),
expect.objectContaining({ slug: dune.slug, airDate: dune.airDate }), expect.objectContaining({ slug: dune.slug, airDate: dune.airDate }),
], ],
this: "http://localhost/movies?limit=2&sort=-airDate", this: "http://localhost/api/movies?limit=2&sort=-airDate",
next: expect.stringContaining( next: expect.stringContaining(
"http://localhost/movies?limit=2&sort=-airDate&after=WyIyMDIxLTEwLTIyIiw", "http://localhost/api/movies?limit=2&sort=-airDate&after=WyIyMDIxLTEwLTIyIiw",
), ),
}); });
@ -118,9 +118,9 @@ describe("with a null value", () => {
}), }),
expect.objectContaining({ slug: dune.slug, airDate: dune.airDate }), expect.objectContaining({ slug: dune.slug, airDate: dune.airDate }),
], ],
this: "http://localhost/movies?limit=2&sort=airDate", this: "http://localhost/api/movies?limit=2&sort=airDate",
next: expect.stringContaining( next: expect.stringContaining(
"http://localhost/movies?limit=2&sort=airDate&after=WyIyMDIxLTEwLTIyIiw", "http://localhost/api/movies?limit=2&sort=airDate&after=WyIyMDIxLTEwLTIyIiw",
), ),
}); });

View File

@ -58,10 +58,10 @@ describe("Get all movies", () => {
expect.objectContaining({ slug: bubble.slug }), expect.objectContaining({ slug: bubble.slug }),
expect.objectContaining({ slug: dune.slug }), expect.objectContaining({ slug: dune.slug }),
], ],
this: "http://localhost/movies?limit=2", this: "http://localhost/api/movies?limit=2",
// we can't have the exact after since it contains the pk that changes with every tests. // we can't have the exact after since it contains the pk that changes with every tests.
next: expect.stringContaining( next: expect.stringContaining(
"http://localhost/movies?limit=2&after=WyJkdW5lIiw", "http://localhost/api/movies?limit=2&after=WyJkdW5lIiw",
), ),
}); });
}); });
@ -81,7 +81,7 @@ describe("Get all movies", () => {
expect(body).toMatchObject({ expect(body).toMatchObject({
items: [expect.objectContaining({ slug: dune1984.slug })], items: [expect.objectContaining({ slug: dune1984.slug })],
this: expect.stringContaining( this: expect.stringContaining(
"http://localhost/movies?limit=2&after=WyJkdW5lIiw", "http://localhost/api/movies?limit=2&after=WyJkdW5lIiw",
), ),
next: null, next: null,
}); });
@ -101,9 +101,9 @@ describe("Get all movies", () => {
expect.objectContaining({ slug: bubble.slug, airDate: bubble.airDate }), expect.objectContaining({ slug: bubble.slug, airDate: bubble.airDate }),
expect.objectContaining({ slug: dune.slug, airDate: dune.airDate }), expect.objectContaining({ slug: dune.slug, airDate: dune.airDate }),
], ],
this: "http://localhost/movies?limit=2&sort=-airDate", this: "http://localhost/api/movies?limit=2&sort=-airDate",
next: expect.stringContaining( next: expect.stringContaining(
"http://localhost/movies?limit=2&sort=-airDate&after=WyIyMDIxLTEwLTIyIiw", "http://localhost/api/movies?limit=2&sort=-airDate&after=WyIyMDIxLTEwLTIyIiw",
), ),
}); });
@ -196,13 +196,13 @@ describe("Get all movies", () => {
it("Get /random", async () => { it("Get /random", async () => {
const resp = await handlers.handle( const resp = await handlers.handle(
new Request("http://localhost/movies/random", { new Request("http://localhost/api/movies/random", {
headers: await getJwtHeaders(), headers: await getJwtHeaders(),
}), }),
); );
expect(resp.status).toBe(302); expect(resp.status).toBe(302);
const location = resp.headers.get("location")!; const location = resp.headers.get("location")!;
expect(location).toStartWith("/movies/"); expect(location).toStartWith("/api/movies/");
}); });
}); });
it("Limit 2, fallback lang, prefer original", async () => { it("Limit 2, fallback lang, prefer original", async () => {

View File

@ -21,6 +21,6 @@ export const buildUrl = (route: string, query?: Record<string, any>) => {
} }
} }
return params.size return params.size
? `http://localhost/${route}?${params}` ? `http://localhost/api/${route}?${params}`
: `http://localhost/${route}`; : `http://localhost/api/${route}`;
}; };