Skip to content

Commit

Permalink
Allow uploading empty files (#374)
Browse files Browse the repository at this point in the history
* fix: allow uploading empty files

* test: update tests
  • Loading branch information
jkoenig134 authored Dec 19, 2024
1 parent 919eefc commit 8d2dc74
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ class Validator extends SchemaValidator<UploadOwnFileValidatableRequest> {
);
}

if (input.content.length === 0) {
validationResult.addFailure(
new ValidationFailure(
RuntimeErrors.general.invalidPropertyValue(`'${nameof<UploadOwnFileValidatableRequest>((r) => r.content)}' is empty`),
nameof<UploadOwnFileValidatableRequest>((r) => r.content)
)
);
}

if (input.expiresAt && CoreDate.from(input.expiresAt).isSameOrBefore(CoreDate.utc())) {
validationResult.addFailure(
new ValidationFailure(
Expand Down
12 changes: 9 additions & 3 deletions packages/runtime/test/transport/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ describe("File upload", () => {
expect(file).toBeDefined();

const response = await transportServices1.files.downloadFile({ id: file.id });
expect(response.isSuccess).toBeTruthy();
expect(response).toBeSuccessful();

expect(response.value.content.byteLength).toBe(4);
});

test("cannot upload an empty file", async () => {
test("can exchange an empty file", async () => {
const response = await transportServices1.files.uploadOwnFile(await makeUploadRequest({ content: Buffer.of() }));
expect(response).toBeAnError("'content' is empty", "error.runtime.validation.invalidPropertyValue");
expect(response).toBeSuccessful();

const downloadResponse = await transportServices1.files.downloadFile({ id: response.value.id });
expect(downloadResponse).toBeSuccessful();

expect(downloadResponse.value.content.byteLength).toBe(0);
});

test("cannot upload a file that is null", async () => {
Expand Down

0 comments on commit 8d2dc74

Please sign in to comment.