Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow zero-sized files #63

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
10 changes: 8 additions & 2 deletions src/tests/__snapshots__/fileDestinationUrlApi.int.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`fileDestinationUrl API #int POST /api/fileDestinationUrl should return an S3 URL when a zero-sized file is passed 1`] = `
Object {
"destinationUrl": "https://permanent-tests.s3.amazonaws.com/my_example_path/example.png",
}
`;

exports[`fileDestinationUrl API #int POST /api/fileDestinationUrl should return an S3 URL when passed the proper parameters 1`] = `
Object {
"destinationUrl": "https://permanent-tests.s3.amazonaws.com/my_example_path/example.png",
Expand Down Expand Up @@ -39,10 +45,10 @@ Object {
"context": Object {
"key": "maxSize",
"label": "maxSize",
"limit": 1,
"limit": 0,
"value": -1,
},
"message": "\\"maxSize\\" must be greater than or equal to 1",
"message": "\\"maxSize\\" must be greater than or equal to 0",
"path": Array [
"maxSize",
],
Expand Down
15 changes: 15 additions & 0 deletions src/tests/fileDestinationUrlApi.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,20 @@ describe('fileDestinationUrl API #int', () => {

expect(response.body).toMatchSnapshot();
});

it('should return an S3 URL when a zero-sized file is passed', async () => {
const response = await agent
.post('/api/fileDestinationUrl')
.send({
bucket: 'permanent-tests',
path: 'my_example_path',
fileType: 'image/png',
fileName: 'example.png',
maxSize: 0,
})
.expect(200);

expect(response.body).toMatchSnapshot();
});
});
});
2 changes: 1 addition & 1 deletion src/validators/validateCreateFileDestinationUrlParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const validateCreateFileDestinationUrlParams = (
bucket: Joi.string().min(3, 'utf8').max(63, 'utf8').required(),
fileName: Joi.string().max(1024, 'utf8'),
fileType: Joi.string().required(),
maxSize: Joi.number().min(1).required(),
maxSize: Joi.number().min(0).required(),
path: Joi.string(),
}).validate(
data,
Expand Down