Skip to content

Commit

Permalink
Throw on Unexpected mobiledoc version
Browse files Browse the repository at this point in the history
fixes #13
  • Loading branch information
bantic committed Nov 16, 2015
1 parent 87ac82a commit 858239d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ function renderSection(section, renderState) {
}
}

function validateVersion(version) {
if (version !== '0.2.0') {
throw new Error(`Unexpected Mobiledoc version "${version}"`);
}
}

export default class Renderer {
/**
* @param {Mobiledoc} mobiledoc
Expand All @@ -122,6 +128,7 @@ export default class Renderer {
* @return DOMNode
*/
render({version, sections: sectionData}, root=createElement('div'), cards={}) {
validateVersion(version);
const [markerTypes, sections] = sectionData;
cards.image = cards.image || ImageCard;
const renderState = {root, markerTypes, cards};
Expand Down
23 changes: 22 additions & 1 deletion tests/unit/renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ test('renders a mobiledoc with multiple markups in a section', (assert) => {
test('renders a mobiledoc with image section', (assert) => {
let url = "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=";
let mobiledoc = {
versions: MOBILEDOC_VERSION,
version: MOBILEDOC_VERSION,
sections: [
[], // markers
[ // sections
Expand Down Expand Up @@ -358,3 +358,24 @@ test('rendering nested mobiledocs in cards', (assert) => {
assert.equal(card.childNodes[0].tagName, 'P', 'card has P child');
assert.equal(card.childNodes[0].innerText, 'hello world');
});

test('throw when given unexpected mobiledoc version', (assert) => {
let mobiledoc = {
version: '0.1.0',
sections: [
[], []
]
};

assert.throws(
() => renderer.render(mobiledoc),
/Unexpected Mobiledoc version.*0.1.0/
);

mobiledoc.version = '0.2.1';
assert.throws(
() => renderer.render(mobiledoc),
/Unexpected Mobiledoc version.*0.2.1/
);

});

0 comments on commit 858239d

Please sign in to comment.