Fix handling attachment thumbnails using thumbnail key

This commit is contained in:
Scott Nonnenberg 2018-04-13 15:45:37 -07:00
parent 6413e75f82
commit 9ad55c803f
No known key found for this signature in database
GPG Key ID: 5F82280C35134661
2 changed files with 32 additions and 4 deletions

View File

@ -157,8 +157,17 @@ exports._mapQuotedAttachments = upgradeAttachment => async (message, context) =>
return message;
}
const upgradeWithContext = attachment =>
upgradeAttachment(attachment, context);
const upgradeWithContext = async (attachment) => {
if (!attachment || !attachment.thumbnail) {
return attachment;
}
const thumbnail = await upgradeAttachment(attachment.thumbnail, context);
return Object.assign({}, attachment, {
thumbnail,
});
};
const quotedAttachments = (message.quote && message.quote.attachments) || [];
const attachments = await Promise.all(quotedAttachments.map(upgradeWithContext));

View File

@ -358,6 +358,21 @@ describe('Message', () => {
assert.deepEqual(result, message);
});
it('handles attachments with no thumbnail', async () => {
const upgradeAttachment = sinon.stub().throws(new Error("Shouldn't be called"));
const upgradeVersion = Message._mapQuotedAttachments(upgradeAttachment);
const message = {
body: 'hey there!',
quote: {
text: 'hey!',
attachments: [],
},
};
const result = await upgradeVersion(message);
assert.deepEqual(result, message);
});
it('calls provided async function for each quoted attachment', async () => {
const upgradeAttachment = sinon.stub().resolves({
path: '/new/path/on/disk',
@ -369,7 +384,9 @@ describe('Message', () => {
quote: {
text: 'hey!',
attachments: [{
data: 'data is here',
thumbnail: {
data: 'data is here',
},
}],
},
};
@ -378,7 +395,9 @@ describe('Message', () => {
quote: {
text: 'hey!',
attachments: [{
path: '/new/path/on/disk',
thumbnail: {
path: '/new/path/on/disk',
},
}],
},
};