Skip to content

Commit

Permalink
Replicating the fake for empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
imrishabh18 committed Nov 21, 2024
1 parent 3fd51e7 commit 85df219
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 6 additions & 2 deletions routes/v1/sessions/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ export default withRouteSpec({
user_id: z.string(),
host: z.string(),
}),
jsonBody: z.object({
body: z.string().optional(),
}),
})((req, ctx) => {
// TODO check the body, this endpoint sends a 502 bad gateway
// if you don't provide an empty string in the body
if (req.jsonBody.body !== "") {
return ctx.json({ id: "", user_id: "", host: "" }, { status: 502 })
}

const session = {
session_id: randomUUID(),
Expand Down
24 changes: 23 additions & 1 deletion tests/routes/v1/sessions/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,33 @@ test("POST /v1/sessions/create", async () => {
"Freerouting-Environment-Host": "test-host",
}

const { data } = await axios.post("/v1/sessions/create", {}, { headers })
const { data } = await axios.post("/v1/sessions/create", {
body: "",
}, { headers })

expect(data).toMatchObject({
id: expect.any(String),
user_id: "test-user-id",
host: "test-host",
})
})

test("POST /v1/sessions/create with non-empty body returns 502", async () => {
const { axios } = await getTestServer()

const headers = {
"Freerouting-Profile-ID": "test-user-id",
"Freerouting-Environment-Host": "test-host",
}

const response = await axios.post(
"/v1/sessions/create",
{ some: "data" },
{
headers,
validateStatus: () => true,
}
)

expect(response.status).toBe(502)
})

0 comments on commit 85df219

Please sign in to comment.