@condenast/flyway-schema-validator
Version:
A joi schema validator for flyways types
84 lines (79 loc) • 2.49 kB
JavaScript
/* eslint-env jest */
const mockRender = jest.fn(doc => ({ doc }));
jest.mock('@condenast/atjson-renderer-ckeditor', () => ({
default: {
render: mockRender
}
}));
const mockConvert = jest.fn(doc => doc);
jest.mock('@condenast/atjson-source-ckeditor-html', () => ({
default: {
fromRaw: jest.fn(({ doc }) => ({
convertTo: jest.fn(() => mockConvert(doc))
}))
}
}));
const VersoSource = require('@condenast/atjson-source-verso').default;
const { isCKEditorCompatible } = require('./atjson');
describe('isCKEditorCompatible', () => {
it('should return true for markdown string with valid properties', () => {
const { result, error } = isCKEditorCompatible('I am a markdown string!\n\n\n[#article: /articles/123]\n\n');
expect(result).toBe(true);
expect(error).toBeUndefined();
});
it('should return false for markdown string containing invalid properties', () => {
mockConvert.mockImplementationOnce(
({ content, annotations }) =>
new VersoSource({
content,
annotations: annotations.filter(annotation => annotation.type !== 'callout')
})
);
const { result, error, diff } = isCKEditorCompatible(
'I am a markdown string\n\n\n+++mycallout\nThis is an unsupported callout type\n+++\n'
);
expect(result).toBe(false);
expect(error).toBeUndefined();
expect(diff).toEqual(`Index: annotations
===================================================================
--- annotations in
+++ annotations out
@@ -2,24 +2,15 @@
{
"type": "-offset-paragraph",
"start": 0,
"end": 22,
"content": "I am a markdown string",
"attributes": {}
},
{
- "type": "-verso-callout",
- "start": 22,
- "end": 57,
- "content": "This is an unsupported callout type",
- "attributes": {
- "-verso-type": "mycallout"
- }
- },
- {
"type": "-offset-paragraph",
"start": 22,
"end": 57,
"content": "This is an unsupported callout type",
"attributes": {}
}
]
`);
});
it('should return false and error if error is thrown at any point', () => {
const thrownError = new Error('boom!');
mockRender.mockImplementationOnce(() => {
throw thrownError;
});
const { result, error } = isCKEditorCompatible(
'I am a markdown string...\n\n[#image: /photos/1234]|||# Heading|||\n\nwith a image caption containing a heading.'
);
expect(result).toBe(false);
expect(error).toBe(thrownError);
});
});