Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/example-todo-app/pages/api/todo/form-add-with-default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { withRouteSpec, checkRouteSpec } from "lib/middlewares"
import { z } from "zod"
import { v4 as uuidv4 } from "uuid"
import { formData } from "./form-add"

export const route_spec = checkRouteSpec({
methods: ["POST"],
auth: "auth_token",
formData,
jsonResponse: z.object({
ok: z.boolean(),
}),
})

export default withRouteSpec(route_spec)(async (req, res) => {
return res.status(200).json({ ok: true })
})
34 changes: 34 additions & 0 deletions apps/example-todo-app/tests/api/todo/form-add-with-default.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import test from "ava"
import getTestServer from "tests/fixtures/get-test-server"

test("POST /todo/form-add-with-default with optional form data", async (t) => {
const { axios } = await getTestServer(t)

axios.defaults.headers.common.Authorization = `Bearer auth_token`

const bodyFormData = {
id: "test-id",
completed: true,
}

const resWithFormData = await axios({
method: "POST",
url: "/todo/form-add-with-default",
data: bodyFormData,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
}).catch((err) => err)

t.is(resWithFormData.status, 200)

const resWithoutData = await axios({
method: "POST",
url: "/todo/form-add-with-default",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
}).catch((err) => err)

t.is(resWithoutData.status, 200)
})
3 changes: 2 additions & 1 deletion apps/example-todo-app/tests/api/todo/form-add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import test from "ava"
import { TODO_ID } from "tests/fixtures"
import getTestServer from "tests/fixtures/get-test-server"
import { v4 as uuidv4 } from "uuid"
import { formData } from "pages/api/todo/form-add"
import { z } from "zod"
import qs from "qs"

test("POST /todo/form-add", async (t) => {
const { axios } = await getTestServer(t)
Expand Down
Loading