Testing guidelines for custom API bodyParser config (sizeLimit)?
Unanswered
Magyar agár posted this in #help-forum
Magyar agárOP
We have a frontend error message that appears via a toast when someone tries to upload a pdf file larger than 100MB. That part is working great. But I need to be able to set that file size limitation parameter in the proxy as well. I read that you can simply change your next config to use the following.
But how would you actually write a test (jest or Cypress) that would test that a large file is not able to be sent via the proxy to our backend? I'm thinking it would have to be a unit test since the frontend component technically blocks it going to the Nextjs backend at all. I've been struggling with getting this test to work quite right.
Here is my route.test.ts file, keep in mind there are quite a few errors here...
https://gist.github.com/mtander/9d87a5cc782383b89c69e4e763d583fb
const nextConfig = {
api: {
bodyParser: {
sizeLimit: '100mb', // Adjusted to 100mb to prevent large file uploads
},
},
}But how would you actually write a test (jest or Cypress) that would test that a large file is not able to be sent via the proxy to our backend? I'm thinking it would have to be a unit test since the frontend component technically blocks it going to the Nextjs backend at all. I've been struggling with getting this test to work quite right.
Here is my route.test.ts file, keep in mind there are quite a few errors here...
https://gist.github.com/mtander/9d87a5cc782383b89c69e4e763d583fb
2 Replies
@Magyar agár We have a frontend error message that appears via a toast when someone tries to upload a pdf file larger than 100MB. That part is working great. But I need to be able to set that file size limitation parameter in the proxy as well. I read that you can simply change your next config to use the following.
const nextConfig = {
api: {
bodyParser: {
sizeLimit: '100mb', // Adjusted to 100mb to prevent large file uploads
},
},
}
But how would you actually write a test (jest or Cypress) that would test that a large file is not able to be sent via the proxy to our backend? I'm thinking it would have to be a unit test since the frontend component technically blocks it going to the Nextjs backend at all. I've been struggling with getting this test to work quite right.
Here is my route.test.ts file, keep in mind there are quite a few errors here...
https://gist.github.com/mtander/9d87a5cc782383b89c69e4e763d583fb
this can't be a unit test. just make a e2e test.
* build the app
* run the production server
* send the big file to the production server
* expect the request to fail
* build the app
* run the production server
* send the big file to the production server
* expect the request to fail
a unit test like you wrote above will only care about running the
POST function itself. it doesn't care about the size limit imposed by the export statement.