Skip to content

Commit

Permalink
Merge pull request #112 from /issues/100
Browse files Browse the repository at this point in the history
Fix tests for body encoder "multipart"
  • Loading branch information
Vladimir Varankin committed Nov 10, 2015
2 parents 9a7800e + b3f719a commit ef7579a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions test/body_encoders.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,25 @@ module.exports = {
assert.strictEqual(complexParam.key1, bodyMultipart.complex_param.key1);
assert.strictEqual(body.non_string_literal, String(bodyMultipart.non_string_literal));
assert.strictEqual(files.file1.size, fileSize);

assert.isArray(files.multiple_files);
assert.strictEqual(files.multiple_files.length, bodyMultipart.multiple_files.length);
assert.strictEqual(files.multiple_files[0].name, bodyMultipart.multiple_files[0].filename);
assert.ok(isBuffersContentEqual(fs.readFileSync(files.multiple_files[1].path), bodyMultipart.multiple_files[1].data));

// @note: formidable doesn't guaranty order of multipart form processing, so convert them to collection
// @see https://github.com/felixge/node-formidable/issues/261
function filesToCollection(files) {
return files.reduce(function(res, file) {
var filename = file.name || file.filename;
res[filename] = {
filename : filename,
mime : file.type || file.mime,
data : file.path ? fs.readFileSync(file.path) : file.data
};
return res;
}, {});
}
assert.deepEqual(filesToCollection(files.multiple_files), filesToCollection(bodyMultipart.multiple_files));

assert.ok(isBuffersContentEqual(fs.readFileSync(files.file0.path), bodyMultipart.file0));

res.statusCode = 200;
Expand Down

0 comments on commit ef7579a

Please sign in to comment.