Skip to content

Commit

Permalink
add test for www-form-urlencoded
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 26, 2023
1 parent abca2d7 commit 7f73c13
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe("Validate", () => {
app.use(
"/custom",
eventHandler(async (event) => {
console.log(event.headers);
const data = await readValidatedBody(event, customValidate);
return data;
})
Expand All @@ -60,13 +61,22 @@ describe("Validate", () => {
});

describe("custom validator", () => {
it("Valid", async () => {
it("Valid JSON", async () => {
const res = await request.post("/custom").send({ field: "value" });
expect(res.body).toEqual({ field: "value", default: "default" });
expect(res.status).toEqual(200);
});

it("Invalid", async () => {
it("Valid x-www-form-urlencoded", async () => {
const res = await request
.post("/custom")
.set("Content-Type", "application/x-www-form-urlencoded")
.send("field=value");
expect(res.body).toEqual({ field: "value", default: "default" });
expect(res.status).toEqual(200);
});

it("Invalid JSON", async () => {
const res = await request.post("/custom").send({ invalid: true });
expect(res.text).include("Invalid key");
expect(res.status).toEqual(400);
Expand Down

0 comments on commit 7f73c13

Please sign in to comment.