How to unit test an endpoint that receives a multipart/form-data payload?

Viewed 285

I've created an endpoint with the following config:

payload: {
  output: 'stream',
  allow: 'multipart/form-data'
}

I've tested it with Postman and it's working, but I can't make unit tests work. I'd like to test that when the endpoint receives a payload with those specifications and has two properties, let's say file and name, the endpoint returns a 200.

What I've tried to do is create a FormData and append those two properties and then send the FormData as payload, but I am always getting a 415 error, Unsupported Media Type. I think it has to do with the way I am creating the file.

I've tried using the createReadStream function, creating a new File object, a Buffer, but nothing's worked so far.

Any suggestions?

Your help is very much appreciated!

0 Answers
Related