From 7939cc1c790e52f211bceaa3f122046fb8e3873b Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 19 Jul 2025 00:25:22 +0200 Subject: [PATCH] Fix api tests --- api/tests/movies/get-all-movies-with-null.test.ts | 8 ++++---- api/tests/movies/get-all-movies.test.ts | 14 +++++++------- api/tests/utils.ts | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/api/tests/movies/get-all-movies-with-null.test.ts b/api/tests/movies/get-all-movies-with-null.test.ts index 3a7d53d9..83e6e348 100644 --- a/api/tests/movies/get-all-movies-with-null.test.ts +++ b/api/tests/movies/get-all-movies-with-null.test.ts @@ -69,9 +69,9 @@ describe("with a null value", () => { expect.objectContaining({ slug: bubble.slug, airDate: bubble.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( - "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 }), ], - this: "http://localhost/movies?limit=2&sort=airDate", + this: "http://localhost/api/movies?limit=2&sort=airDate", next: expect.stringContaining( - "http://localhost/movies?limit=2&sort=airDate&after=WyIyMDIxLTEwLTIyIiw", + "http://localhost/api/movies?limit=2&sort=airDate&after=WyIyMDIxLTEwLTIyIiw", ), }); diff --git a/api/tests/movies/get-all-movies.test.ts b/api/tests/movies/get-all-movies.test.ts index 06f400d4..c80db4ce 100644 --- a/api/tests/movies/get-all-movies.test.ts +++ b/api/tests/movies/get-all-movies.test.ts @@ -58,10 +58,10 @@ describe("Get all movies", () => { expect.objectContaining({ slug: bubble.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. 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({ items: [expect.objectContaining({ slug: dune1984.slug })], this: expect.stringContaining( - "http://localhost/movies?limit=2&after=WyJkdW5lIiw", + "http://localhost/api/movies?limit=2&after=WyJkdW5lIiw", ), next: null, }); @@ -101,9 +101,9 @@ describe("Get all movies", () => { expect.objectContaining({ slug: bubble.slug, airDate: bubble.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( - "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 () => { const resp = await handlers.handle( - new Request("http://localhost/movies/random", { + new Request("http://localhost/api/movies/random", { headers: await getJwtHeaders(), }), ); expect(resp.status).toBe(302); const location = resp.headers.get("location")!; - expect(location).toStartWith("/movies/"); + expect(location).toStartWith("/api/movies/"); }); }); it("Limit 2, fallback lang, prefer original", async () => { diff --git a/api/tests/utils.ts b/api/tests/utils.ts index a3101a87..aa92945d 100644 --- a/api/tests/utils.ts +++ b/api/tests/utils.ts @@ -21,6 +21,6 @@ export const buildUrl = (route: string, query?: Record) => { } } return params.size - ? `http://localhost/${route}?${params}` - : `http://localhost/${route}`; + ? `http://localhost/api/${route}?${params}` + : `http://localhost/api/${route}`; };