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 passing of content in request with file type body #1326

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions lib/collection/form-param.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ _.inherit((
this.value = options.value || '';
this.type = options.type;
this.src = options.src;
this.content = options.content;
this.contentType = options.contentType;
}), Property);

Expand Down
3 changes: 0 additions & 3 deletions lib/collection/request-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ _.assign(RequestBody.prototype, /** @lends RequestBody.prototype */ {
toJSON () {
dev-sharma-08 marked this conversation as resolved.
Show resolved Hide resolved
var obj = PropertyBase.toJSON(this);

// make sure that file content is removed because it is non-serializable ReadStream
_.unset(obj, 'file.content');

return obj;
}
});
Expand Down
14 changes: 13 additions & 1 deletion test/unit/form-param.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('FormParam', function () {
expect(fp.toJSON()).to.eql(definition);
});

it('should correctly handle param with type `file`', function () {
it('should correctly handle param with type `file` and src', function () {
var definition = {
key: 'foo',
src: 'fileSrc',
Expand All @@ -80,6 +80,18 @@ describe('FormParam', function () {
expect(fp.toJSON()).to.eql(definition);
});

it('should correctly handle param with type `file` and content', function () {
var definition = {
key: 'foo',
content: 'Base64 representation of buffer',
type: 'file',
contentType: 'application/json'
},
fp = new FormParam(definition);

expect(fp.toJSON()).to.eql(definition);
});

it('should not have value for param with type `file`', function () {
var fp = new FormParam({
key: 'foo',
Expand Down
6 changes: 3 additions & 3 deletions test/unit/request-body.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,14 @@ describe('RequestBody', function () {
expect(rBody.toJSON()).to.eql(definition);
});

it('should not have content in file body', function () {
it('should have content in file body', function () {
var definition = {
mode: 'file',
file: { src: 'fileSrc', content: 'this should be removed' }
file: { src: 'fileSrc', content: 'this should not be removed' }
},
rBody = new RequestBody(definition);

expect(rBody.toJSON().file).to.not.have.property('content');
expect(rBody.toJSON().file).to.have.property('content');
dev-sharma-08 marked this conversation as resolved.
Show resolved Hide resolved
});
});
});