Skip to content

Commit 1dae4ae

Browse files
committed
Added tests for KoaDriver bug #156
1 parent 1586ec5 commit 1dae4ae

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

test/functional/action-params.spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@ describe("action parameters", () => {
240240
return `<html><body>${uploadedFileName}</body></html>`;
241241
}
242242

243+
@Post("/files-with-body")
244+
postFileWithBody(@UploadedFile("myfile") file: any, @Body() body: any): any {
245+
uploadedFileName = file.originalname;
246+
return `<html><body>${uploadedFileName} - ${JSON.stringify(body)}</body></html>`;
247+
}
248+
249+
@Post("/files-with-body-param")
250+
postFileWithBodyParam(@UploadedFile("myfile") file: any, @BodyParam("p1") p1: string): any {
251+
uploadedFileName = file.originalname;
252+
return `<html><body>${uploadedFileName} - ${p1}</body></html>`;
253+
}
254+
243255
@Post("/files-with-limit")
244256
postFileWithLimit(@UploadedFile("myfile", { options: { limits: { fileSize: 2 } } }) file: any): any {
245257
return `<html><body>${file.originalname}</body></html>`;
@@ -682,6 +694,49 @@ describe("action parameters", () => {
682694
});
683695
});
684696

697+
describe("@UploadedFile with @Body should return both the file and the body", () => {
698+
const requestOptions = {
699+
formData: {
700+
myfile: {
701+
value: "hello world",
702+
options: {
703+
filename: "hello-world.txt",
704+
contentType: "image/text"
705+
}
706+
},
707+
anotherField: "hi",
708+
andOther: "hello",
709+
}
710+
};
711+
712+
assertRequest([3001, 3002], "post", "files-with-body", undefined, requestOptions, response => {
713+
expect(response).to.be.status(200);
714+
expect(response).to.have.header("content-type", "text/html; charset=utf-8");
715+
expect(response.body).to.be.equal(`<html><body>hello-world.txt - {"anotherField":"hi","andOther":"hello"}</body></html>`);
716+
});
717+
});
718+
719+
describe("@UploadedFile with @BodyParam should return both the file and the body param", () => {
720+
const requestOptions = {
721+
formData: {
722+
myfile: {
723+
value: "hello world",
724+
options: {
725+
filename: "hello-world.txt",
726+
contentType: "image/text"
727+
}
728+
},
729+
p1: "hi, i'm a param",
730+
}
731+
};
732+
733+
assertRequest([3001, 3002], "post", "files-with-body-param", undefined, requestOptions, response => {
734+
expect(response).to.be.status(200);
735+
expect(response).to.have.header("content-type", "text/html; charset=utf-8");
736+
expect(response.body).to.be.equal("<html><body>hello-world.txt - hi, i'm a param</body></html>");
737+
});
738+
});
739+
685740
describe("@UploadedFile with passed uploading options (limit) should throw an error", () => {
686741
const validRequestOptions = {
687742
formData: {

0 commit comments

Comments
 (0)