From 2ac634476a679beeb7f1a11946af6410181834ae Mon Sep 17 00:00:00 2001 From: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:23:27 +0100 Subject: [PATCH] add tests for trailing slashes --- .../core/js-sdk/src/__tests__/client.spec.ts | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/core/js-sdk/src/__tests__/client.spec.ts b/packages/core/js-sdk/src/__tests__/client.spec.ts index c8240981b7578..e70a27a1d5d8f 100644 --- a/packages/core/js-sdk/src/__tests__/client.spec.ts +++ b/packages/core/js-sdk/src/__tests__/client.spec.ts @@ -12,6 +12,11 @@ const server = setupServer( test: "test", }) }), + http.get(`${baseUrl}/some/path/test`, ({ request, params, cookies }) => { + return HttpResponse.json({ + test: "test", + }) + }), http.get(`${baseUrl}/throw`, ({ request, params, cookies }) => { return new HttpResponse(null, { status: 500, @@ -190,11 +195,14 @@ describe("Client", () => { baseUrl: "https://someurl.com/some/path", }) - server.use( - http.get("https://someurl.com/some/path/test", () => { - return HttpResponse.json({ test: "test" }) - }) - ) + const resp = await pathClient.fetch("test") + expect(resp).toEqual({ test: "test" }) + }) + + it("should handle baseUrl with trailing slash path correctly", async () => { + const pathClient = new Client({ + baseUrl: "https://someurl.com/some/path/", + }) const resp = await pathClient.fetch("test") expect(resp).toEqual({ test: "test" }) @@ -208,6 +216,15 @@ describe("Client", () => { const resp = await originClient.fetch("test") expect(resp).toEqual({ test: "test" }) }) + + it("should handle baseUrl with just origin and trailing slash", async () => { + const originClient = new Client({ + baseUrl: "https://someurl.com/", + }) + + const resp = await originClient.fetch("test") + expect(resp).toEqual({ test: "test" }) + }) }) describe("GET requests", () => {