Skip to content

Commit

Permalink
add tests for trailing slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperkristensen committed Nov 22, 2024
1 parent 0ab5d3c commit 2ac6344
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions packages/core/js-sdk/src/__tests__/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<any>("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<any>("test")
expect(resp).toEqual({ test: "test" })
Expand All @@ -208,6 +216,15 @@ describe("Client", () => {
const resp = await originClient.fetch<any>("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<any>("test")
expect(resp).toEqual({ test: "test" })
})
})

describe("GET requests", () => {
Expand Down

0 comments on commit 2ac6344

Please sign in to comment.