Fix handling attachment thumbnails using thumbnail key
This commit is contained in:
parent
6413e75f82
commit
9ad55c803f
2 changed files with 32 additions and 4 deletions
|
@ -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));
|
||||
|
|
|
@ -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',
|
||||
},
|
||||
}],
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue