-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update schema to support new field type: embedded_block
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 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,68 @@ | ||
import { generateNewCmaClient } from '../../../jest-helpers/generateNewCmaClient'; | ||
import { buildBlockRecord, SchemaTypes } from '@datocms/cma-client'; | ||
|
||
describe('embedded block', () => { | ||
it.concurrent('create, update', async () => { | ||
const client = await generateNewCmaClient(); | ||
|
||
const articleItemType = await client.itemTypes.create({ | ||
name: 'Article', | ||
api_key: 'article', | ||
}); | ||
|
||
const contentItemType = await client.itemTypes.create({ | ||
name: 'Block', | ||
api_key: 'block', | ||
modular_block: true, | ||
}); | ||
|
||
await client.fields.create(contentItemType.id, { | ||
label: 'Text', | ||
field_type: 'text', | ||
api_key: 'text', | ||
}); | ||
|
||
await client.fields.create(articleItemType.id, { | ||
label: 'Content', | ||
field_type: 'embedded_block', | ||
api_key: 'content', | ||
validators: { | ||
embedded_block_block: { item_type: contentItemType.id }, | ||
required: {}, | ||
}, | ||
}); | ||
|
||
const item = await client.items.create({ | ||
item_type: articleItemType, | ||
content: buildBlockRecord({ | ||
text: 'Foo', | ||
item_type: contentItemType, | ||
}), | ||
}); | ||
|
||
expect(typeof item.content).toBe('string'); | ||
|
||
const itemWithNestedBlocks = await client.items.find(item.id, { | ||
nested: true, | ||
}); | ||
|
||
const block = itemWithNestedBlocks.content as SchemaTypes.Item; | ||
|
||
await client.items.update(item.id, { | ||
content: buildBlockRecord({ | ||
id: block.id, | ||
text: `Updated ${block.attributes.text}`, | ||
item_type: block.relationships.item_type.data, | ||
}), | ||
}); | ||
|
||
const updatedItemWithNestedBlocks = await client.items.find(item.id, { | ||
nested: true, | ||
}); | ||
|
||
const updatedBlock = | ||
updatedItemWithNestedBlocks.content as SchemaTypes.Item; | ||
|
||
expect(updatedBlock.attributes.text).toEqual('Updated Foo'); | ||
}); | ||
}); |
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
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