Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support custom error transformer #296

Merged
merged 2 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentful-slatejs-adapter/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/rich-text-html-renderer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

168 changes: 91 additions & 77 deletions packages/rich-text-types/src/__test__/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,19 @@ describe('validateRichTextDocument', () => {

const errorsResult = validateRichTextDocument(value);

expect(errorsResult).toEqual([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: 'must be equal to one of the allowed values',
params: {
allowedValues: Object.values(INLINES).sort(),
},
data: 'custom-type',
}),
]);
expect(errorsResult).toEqual(
expect.arrayContaining([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: 'must be equal to one of the allowed values',
params: {
allowedValues: Object.values(INLINES).sort(),
},
data: 'custom-type',
}),
]),
);
});
});

Expand Down Expand Up @@ -202,17 +204,19 @@ describe('validateRichTextDocument', () => {
const value = document({}, text());
const errorsResult = validateRichTextDocument(value);

expect(errorsResult).toEqual([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: `must be equal to one of the allowed values`,
params: {
allowedValues: topLevelBlocks,
},
data: 'text',
}),
]);
expect(errorsResult).toEqual(
expect.arrayContaining([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: `must be equal to one of the allowed values`,
params: {
allowedValues: topLevelBlocks,
},
data: 'text',
}),
]),
);
});

it('fail with text and inline as direct children', () => {
Expand All @@ -225,17 +229,19 @@ describe('validateRichTextDocument', () => {

const errorsResult = validateRichTextDocument(value);

expect(errorsResult).toEqual([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: `must be equal to one of the allowed values`,
params: {
allowedValues: topLevelBlocks,
},
data: 'text',
}),
]);
expect(errorsResult).toEqual(
expect.arrayContaining([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: `must be equal to one of the allowed values`,
params: {
allowedValues: topLevelBlocks,
},
data: 'text',
}),
]),
);
});
});

Expand Down Expand Up @@ -302,17 +308,19 @@ describe('validateRichTextDocument', () => {
const value = document({}, node(BLOCKS.UL_LIST, {}, node(BLOCKS.LIST_ITEM, {}, text(''))));
const errorsResult = validateRichTextDocument(value);

expect(errorsResult).toEqual([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: `must be equal to one of the allowed values`,
params: {
allowedValues: listBlocks,
},
data: 'text',
}),
]);
expect(errorsResult).toEqual(
expect.arrayContaining([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: `must be equal to one of the allowed values`,
params: {
allowedValues: listBlocks,
},
data: 'text',
}),
]),
);
});

it(`allows only paragraphs as direct children of ${BLOCKS.TABLE_CELL} nodes`, () => {
Expand All @@ -323,17 +331,19 @@ describe('validateRichTextDocument', () => {

const errorsResult = validateRichTextDocument(value);

expect(errorsResult).toEqual([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: `must be equal to one of the allowed values`,
params: {
allowedValues: ['paragraph'],
},
data: 'text',
}),
]);
expect(errorsResult).toEqual(
expect.arrayContaining([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: `must be equal to one of the allowed values`,
params: {
allowedValues: ['paragraph'],
},
data: 'text',
}),
]),
);
});

it('allows inlines to contain only inline or text nodes', () => {
Expand All @@ -348,17 +358,19 @@ describe('validateRichTextDocument', () => {

const errorsResult = validateRichTextDocument(value);

expect(errorsResult).toEqual([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: `must be equal to one of the allowed values`,
params: {
allowedValues: ['text'],
},
data: BLOCKS.PARAGRAPH,
}),
]);
expect(errorsResult).toEqual(
expect.arrayContaining([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: `must be equal to one of the allowed values`,
params: {
allowedValues: ['text'],
},
data: BLOCKS.PARAGRAPH,
}),
]),
);
});

it(`allows only ${BLOCKS.PARAGRAPH} as children of ${BLOCKS.QUOTE}`, () => {
Expand Down Expand Up @@ -400,17 +412,19 @@ describe('validateRichTextDocument', () => {
const value = document({}, node(BLOCKS.PARAGRAPH, { data: {}, nodeType: null }, text('')));
const errorsResult = validateRichTextDocument(value);

expect(errorsResult).toEqual([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: 'must be equal to one of the allowed values',
params: {
allowedValues: topLevelBlocks,
},
data: null,
}),
]);
expect(errorsResult).toEqual(
expect.arrayContaining([
expect.objectContaining({
keyword: 'enum',
instancePath: '/content/0/nodeType',
message: 'must be equal to one of the allowed values',
params: {
allowedValues: topLevelBlocks,
},
data: null,
}),
]),
);
});

it('fail without required `content` property', () => {
Expand Down
Loading