Skip to content

Commit

Permalink
Use form data
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-balitskyi committed Oct 15, 2024
1 parent 322b400 commit 91cf848
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions fake-snippets-api/routes/api/order_files/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { orderFileSchema } from "fake-snippets-api/lib/db/schema"
export default withRouteSpec({
methods: ["POST"],
auth: "session",
jsonBody: z.object({
multiPartFormData: z.object({
order_id: z.string(),
file: z.any(),
is_gerbers_zip: z.boolean().optional(),
Expand All @@ -15,7 +15,7 @@ export default withRouteSpec({
order_file: orderFileSchema,
}),
})(async (req, ctx) => {
const { order_id, file, is_gerbers_zip, for_provider } = req.jsonBody
const { order_id, file, is_gerbers_zip, for_provider } = req.multiPartFormData

const order = ctx.db.getOrderById(order_id)
if (!order) {
Expand Down
11 changes: 6 additions & 5 deletions fake-snippets-api/tests/routes/order_files/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ test("get order file", async () => {
const file = new File(["test file content"], "test.txt", {
type: "text/plain",
})
const uploadResponse = await axios.post("/api/order_files/upload", {
order_id,
file,
is_gerbers_zip: false,
})
const formData = new FormData()
formData.append("order_id", order_id)
formData.append("file", file)
formData.append("is_gerbers_zip", "false")

const uploadResponse = await axios.post("/api/order_files/upload", formData)

const orderFileId = uploadResponse.data.order_file.order_file_id

Expand Down
6 changes: 1 addition & 5 deletions fake-snippets-api/tests/routes/order_files/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ test("upload order file", async () => {
formData.append("file", file)
formData.append("is_gerbers_zip", "false")

const response = await axios.post("/api/order_files/upload", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
})
const response = await axios.post("/api/order_files/upload", formData)

expect(response.status).toBe(200)
expect(response.data.order_file).toBeDefined()
Expand Down

0 comments on commit 91cf848

Please sign in to comment.