-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix input validation for missing child blocks (#2942)
- Loading branch information
1 parent
4df9d45
commit 58a99bb
Showing
3 changed files
with
57 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@comet/blocks-api": patch | ||
--- | ||
|
||
Fix input validation for missing child blocks |
35 changes: 35 additions & 0 deletions
35
packages/api/blocks-api/src/blocks/decorators/child-block-input.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { BlockData, BlockDataInterface, BlockInput, createBlock, ExtractBlockData, ExtractBlockInput, inputToData } from "../block"; | ||
import { createRichTextBlock } from "../createRichTextBlock"; | ||
import { ExternalLinkBlock } from "../ExternalLinkBlock"; | ||
import { ChildBlock } from "./child-block"; | ||
import { ChildBlockInput } from "./child-block-input"; | ||
|
||
const RichTextBlock = createRichTextBlock({ link: ExternalLinkBlock }); | ||
|
||
class HeadlineBlockData extends BlockData { | ||
@ChildBlock(RichTextBlock) | ||
headline: ExtractBlockData<typeof RichTextBlock>; | ||
} | ||
|
||
class HeadlineBlockInput extends BlockInput { | ||
@ChildBlockInput(RichTextBlock) | ||
headline: ExtractBlockInput<typeof RichTextBlock>; | ||
|
||
transformToBlockData(): BlockDataInterface { | ||
return inputToData(HeadlineBlockData, this); | ||
} | ||
} | ||
|
||
const HeadlineBlock = createBlock(HeadlineBlockData, HeadlineBlockInput, "Headline"); | ||
|
||
describe("ChildBlockInput", () => { | ||
it("should fail if no value is provided", () => { | ||
// `@Transform()` allows any value, so we use any here. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const plain: any = {}; | ||
|
||
expect(() => { | ||
HeadlineBlock.blockInputFactory(plain); | ||
}).toThrowError(`Missing child block input for 'headline' (RichText)`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters