Backup and end-to-end test!

This commit is contained in:
Scott Nonnenberg
2018-04-20 14:55:33 -07:00
parent c3acf43c47
commit a7d44d3344
6 changed files with 477 additions and 28 deletions

View File

@@ -243,9 +243,12 @@ exports.createAttachmentDataWriter = (writeExistingAttachmentData) => {
const message = exports.initializeSchemaVersion(rawMessage);
const { attachments } = message;
const hasAttachments = attachments && attachments.length > 0;
if (!hasAttachments) {
const { attachments, quote } = message;
const hasFilesToWrite =
(quote && quote.attachments && quote.attachments.length > 0) ||
(attachments && attachments.length > 0);
if (!hasFilesToWrite) {
return message;
}
@@ -256,7 +259,7 @@ exports.createAttachmentDataWriter = (writeExistingAttachmentData) => {
return message;
}
attachments.forEach((attachment) => {
(attachments || []).forEach((attachment) => {
if (!Attachment.hasData(attachment)) {
throw new TypeError("'attachment.data' is required during message import");
}
@@ -266,13 +269,29 @@ exports.createAttachmentDataWriter = (writeExistingAttachmentData) => {
}
});
const messageWithoutAttachmentData = Object.assign({}, message, {
attachments: await Promise.all(attachments.map(async (attachment) => {
await writeExistingAttachmentData(attachment);
return omit(attachment, ['data']);
})),
const writeThumbnails = exports._mapQuotedAttachments(async (thumbnail) => {
const { data, path } = thumbnail;
// we want to be bulletproof to thumbnails without data
if (!data || !path) {
return thumbnail;
}
await writeExistingAttachmentData(thumbnail);
return omit(thumbnail, ['data']);
});
const messageWithoutAttachmentData = Object.assign(
{},
await writeThumbnails(message),
{
attachments: await Promise.all((attachments || []).map(async (attachment) => {
await writeExistingAttachmentData(attachment);
return omit(attachment, ['data']);
})),
}
);
return messageWithoutAttachmentData;
};
};