Add Message.withInheritedSchemaVersion

This commit is contained in:
Daniel Gasienica 2018-03-13 22:01:23 -04:00
parent e9e46464c2
commit c27746b79e
2 changed files with 102 additions and 0 deletions

View file

@ -0,0 +1,63 @@
const { assert } = require('chai');
const Message = require('../../../js/modules/types/message');
describe('Message', () => {
describe('withInheritedSchemaVersion', () => {
it('should ignore messages with previously inherited schema', () => {
const input = {
body: 'Imagine there is no heaven…',
schemaVersion: 2,
};
const expected = {
body: 'Imagine there is no heaven…',
schemaVersion: 2,
};
const actual = Message.withInheritedSchemaVersion(input);
assert.deepEqual(actual, expected);
});
context('for message without attachments', () => {
it('should initialize schema version to zero', () => {
const input = {
body: 'Imagine there is no heaven…',
attachments: [],
};
const expected = {
body: 'Imagine there is no heaven…',
attachments: [],
schemaVersion: 0,
};
const actual = Message.withInheritedSchemaVersion(input);
assert.deepEqual(actual, expected);
});
});
context('for message with attachments', () => {
it('should inherit existing attachment schema version', () => {
const input = {
body: 'Imagine there is no heaven…',
attachments: [{
contentType: 'image/jpeg',
fileName: 'lennon.jpg',
schemaVersion: 7,
}],
};
const expected = {
body: 'Imagine there is no heaven…',
attachments: [{
contentType: 'image/jpeg',
fileName: 'lennon.jpg',
}],
schemaVersion: 7,
};
const actual = Message.withInheritedSchemaVersion(input);
assert.deepEqual(actual, expected);
});
});
});
});