feat: add community publishing and news syndication
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { EMPTY_ARTICLE_DOCUMENT, parseArticleDocument } from './document';
|
||||
|
||||
describe('article documents', () => {
|
||||
it('accepts formatted prose, multiple Builds, and article images', () => {
|
||||
const parsed = parseArticleDocument({
|
||||
version: 1,
|
||||
document: {
|
||||
type: 'doc',
|
||||
content: [
|
||||
{
|
||||
type: 'heading',
|
||||
attrs: { level: 2 },
|
||||
content: [
|
||||
{ type: 'text', text: 'Opening', marks: [{ type: 'bold' }] },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'paragraph',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Use this rotation.',
|
||||
marks: [
|
||||
{ type: 'link', attrs: { href: 'https://shd.build/guides' } },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'buildEmbed',
|
||||
attrs: {
|
||||
buildId: '11111111-1111-4111-8111-111111111111',
|
||||
embedKey: 'build-11111111-1111-4111-8111-111111111111',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'buildEmbed',
|
||||
attrs: {
|
||||
buildId: '22222222-2222-4222-8222-222222222222',
|
||||
embedKey: 'build-22222222-2222-4222-8222-222222222222',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'articleImage',
|
||||
attrs: {
|
||||
imageId: '33333333-3333-4333-8333-333333333333',
|
||||
alt: 'A loadout screen',
|
||||
caption: 'Final configuration',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(parsed?.buildEmbeds).toHaveLength(2);
|
||||
expect(parsed?.imageIds).toEqual(['33333333-3333-4333-8333-333333333333']);
|
||||
expect(parsed?.plainText).toContain('Opening Use this rotation.');
|
||||
});
|
||||
|
||||
it('rejects unsafe links and unknown nodes', () => {
|
||||
expect(
|
||||
parseArticleDocument({
|
||||
version: 1,
|
||||
document: {
|
||||
type: 'doc',
|
||||
content: [
|
||||
{
|
||||
type: 'paragraph',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'unsafe',
|
||||
marks: [
|
||||
{ type: 'link', attrs: { href: 'javascript:alert(1)' } },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
).toBeNull();
|
||||
expect(
|
||||
parseArticleDocument({
|
||||
version: 1,
|
||||
document: {
|
||||
type: 'doc',
|
||||
content: [{ type: 'iframe', attrs: { src: 'https://example.com' } }],
|
||||
},
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it('rejects duplicate embed keys and unknown envelope fields', () => {
|
||||
const embed = {
|
||||
type: 'buildEmbed',
|
||||
attrs: {
|
||||
buildId: '11111111-1111-4111-8111-111111111111',
|
||||
embedKey: 'build-11111111-1111-4111-8111-111111111111',
|
||||
},
|
||||
};
|
||||
expect(
|
||||
parseArticleDocument({
|
||||
version: 1,
|
||||
document: { type: 'doc', content: [embed, embed] },
|
||||
}),
|
||||
).toBeNull();
|
||||
expect(
|
||||
parseArticleDocument({ ...EMPTY_ARTICLE_DOCUMENT, legacy: true }),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user