Skip to content

Commit

Permalink
Fixes resolveContent with streams overriding data
Browse files Browse the repository at this point in the history
  • Loading branch information
Warren Choisy authored and andris9 committed Mar 4, 2021
1 parent 91108d7 commit bf57cf5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/shared/index.js
Expand Up @@ -327,7 +327,11 @@ module.exports.resolveContent = (data, key, callback) => {
}
// we can't stream twice the same content, so we need
// to replace the stream object with the streaming result
data[key] = value;
if (data[key].content) {
data[key].content = value;
} else {
data[key] = value;
}
callback(null, value);
});
} else if (/^https?:\/\//i.test(content.path || content.href)) {
Expand Down
24 changes: 24 additions & 0 deletions test/shared/shared-test.js
Expand Up @@ -200,6 +200,30 @@ describe('Shared Funcs Tests', function () {
});
});

it('should set content from a stream and preserve other properties', function (done) {
let mail = {
data: {
attachment: {
filename: 'message.html',
content: fs.createReadStream(__dirname + '/fixtures/message.html')
}
}
};
shared.resolveContent(mail.data, 'attachment', function (err, value) {
expect(err).to.not.exist;
expect(mail).to.deep.equal({
data: {
attachment: {
filename: 'message.html',
content: Buffer.from('<p>Tere, tere</p><p>vana kere!</p>\n')
}
}
});
expect(value).to.deep.equal(Buffer.from('<p>Tere, tere</p><p>vana kere!</p>\n'));
done();
});
});

it('should return an error', function (done) {
let mail = {
data: {
Expand Down

0 comments on commit bf57cf5

Please sign in to comment.