Add Message.createImporter

This commit is contained in:
Daniel Gasienica 2018-04-03 21:10:34 -04:00
parent 5a6668e677
commit bf67254cc5
3 changed files with 111 additions and 1 deletions

View file

@ -5,6 +5,66 @@ const { stringToArrayBuffer } = require('../../../js/modules/string_to_array_buf
describe('Message', () => {
describe('createImporter', () => {
it('should ignore messages that didnt go through attachment migration', async () => {
const input = {
body: 'Imagine there is no heaven…',
schemaVersion: 2,
};
const expected = {
body: 'Imagine there is no heaven…',
schemaVersion: 2,
};
const writeExistingAttachmentData = () => {};
const actual = await Message.createImporter(writeExistingAttachmentData)(input);
assert.deepEqual(actual, expected);
});
it('should ignore messages without attachments', async () => {
const input = {
body: 'Imagine there is no heaven…',
schemaVersion: 4,
attachments: [],
};
const expected = {
body: 'Imagine there is no heaven…',
schemaVersion: 4,
attachments: [],
};
const writeExistingAttachmentData = () => {};
const actual = await Message.createImporter(writeExistingAttachmentData)(input);
assert.deepEqual(actual, expected);
});
it('should write attachments to file system on original path', async () => {
const input = {
body: 'Imagine there is no heaven…',
schemaVersion: 4,
attachments: [{
path: 'ab/abcdefghi',
data: stringToArrayBuffer('Its easy if you try'),
}],
};
const expected = {
body: 'Imagine there is no heaven…',
schemaVersion: 4,
attachments: [{
path: 'ab/abcdefghi',
}],
};
const writeExistingAttachmentData = (attachment) => {
assert.equal(attachment.path, 'ab/abcdefghi');
assert.deepEqual(attachment.data, stringToArrayBuffer('Its easy if you try'));
};
const actual = await Message.createImporter(writeExistingAttachmentData)(input);
assert.deepEqual(actual, expected);
});
});
describe('initializeSchemaVersion', () => {
it('should ignore messages with previously inherited schema', () => {
const input = {