Skip to content

Commit

Permalink
feat: bump limit of allowed sources (#1336)
Browse files Browse the repository at this point in the history
* feat: bump limit of allowed sources

* chore: adjust tests to new limit
  • Loading branch information
anho authored Jul 18, 2024
1 parent 59321bb commit 860fa6a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
19 changes: 13 additions & 6 deletions src/lib/offline-api/validator/schema/field-validations-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,24 @@ const assetImageDimensions = validation(

const assetFileSize = validation('assetFileSize', range('number'))

const resourceLinkNode = () =>
Joi.object({
validations: Joi.array().items(size),
allowedResources: allowedResourcesSchema
})

const nodes = validation(
'nodes',
Joi.object({
'embedded-entry-block': Joi.array(),
'embedded-entry-inline': Joi.array(),
'embedded-resource-inline': resourceLinkNode(),
'embedded-asset-block': Joi.array(),
'embedded-resource-block': Joi.object({
validations: Joi.array().items(size),
allowedResources: allowedResourcesSchema
}),
'embedded-resource-block': resourceLinkNode(),
'entry-hyperlink': Joi.array(),
'asset-hyperlink': Joi.array(),
hyperlink: Joi.array()
hyperlink: Joi.array(),
'resource-hyperlink': resourceLinkNode()
})
)

Expand Down Expand Up @@ -100,7 +105,9 @@ const enabledNodeTypes = validation(
'hyperlink',
'entry-hyperlink',
'asset-hyperlink',
'embedded-entry-inline'
'resource-hyperlink',
'embedded-entry-inline',
'embedded-resource-inline'
)
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/resource-links.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const MAX_ALLOWED_RESOURCES = 3
export const MAX_ALLOWED_RESOURCES = 20
export const MAX_RESOURCE_LINKS = 3

export const RICH_TEXT_RESOURCE_LINK_NODES = ['embedded-resource-block']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import { expect } from 'chai'
import validateBatches from './validate-batches'
import { MAX_RESOURCE_LINKS } from '../../../../../src/lib/utils/resource-links'
import {
MAX_ALLOWED_RESOURCES,
MAX_RESOURCE_LINKS
} from '../../../../../src/lib/utils/resource-links'

const VALID_ALLOWED_RESOURCE = {
type: 'Contentful:Entry',
Expand Down Expand Up @@ -136,29 +139,19 @@ describe('payload validation (dependencies)', function () {
.createField('mainCourse')
.name('Main Course')
.type('ResourceLink')
.allowedResources([
{
...VALID_ALLOWED_RESOURCE,
source: 'crn:contentful:::content:spaces/cooking-space-1'
},
{
.allowedResources(
[...Array(MAX_ALLOWED_RESOURCES + 1).keys()].map((value) => ({
...VALID_ALLOWED_RESOURCE,
source: 'crn:contentful:::content:spaces/cooking-space-2'
},
{
...VALID_ALLOWED_RESOURCE,
source: 'crn:contentful:::content:spaces/cooking-space-3'
},
{ ...VALID_ALLOWED_RESOURCE, source: 'crn:contentful:::content:spaces/cooking-space-4' }
])
source: `crn:contentful:::content:spaces/cooking-space-${value + 1}`
}))
)
}, existingCts)

expect(errors).to.eql([
[
{
type: 'InvalidPayload',
message:
'The property "allowedResources" on the field "mainCourse" must have at most 3 items.'
message: `The property "allowedResources" on the field "mainCourse" must have at most ${MAX_ALLOWED_RESOURCES} items.`
}
]
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ describe('payload validation (dependencies)', function () {
expect(errors).to.eql([
[
{
message:
'The property "validations.1.nodes.embedded-resource-block.allowedResources" on the field "menu" must have at most 3 items.',
message: `The property "validations.1.nodes.embedded-resource-block.allowedResources" on the field "menu" must have at most ${MAX_ALLOWED_RESOURCES} items.`,
type: 'InvalidPayload'
}
]
Expand Down

0 comments on commit 860fa6a

Please sign in to comment.