diff --git a/packages/strapi-plugin-content-type-builder/controllers/validation/__tests__/content-type.test.js b/packages/strapi-plugin-content-type-builder/controllers/validation/__tests__/content-type.test.js index 4e93c15745..9f369b944f 100644 --- a/packages/strapi-plugin-content-type-builder/controllers/validation/__tests__/content-type.test.js +++ b/packages/strapi-plugin-content-type-builder/controllers/validation/__tests__/content-type.test.js @@ -1,6 +1,23 @@ const { validateKind, validateUpdateContentTypeInput } = require('../content-type'); describe('Content type validator', () => { + global.strapi = { + plugins: { + 'content-type-builder': { + services: { + builder: { + getReservedNames() { + return { + models: [], + attributes: ['thisIsReserved'], + }; + }, + }, + }, + }, + }, + }; + describe('validateKind', () => { it('Only allows for single and collection types', async () => { await expect(validateKind('wrong')).rejects.toBeDefined(); @@ -16,6 +33,30 @@ describe('Content type validator', () => { }); }); + describe('Prevents use of reservedNames', () => { + test('Throws when resverd names are used', async () => { + const data = { + contentType: { + name: 'test', + attributes: { + thisIsReserved: { + type: 'string', + default: '', + }, + }, + }, + }; + + await validateUpdateContentTypeInput(data).catch(err => { + expect(err).toMatchObject({ + 'contentType.attributes.thisIsReserved': [ + expect.stringMatching('Attribute keys cannot be one of'), + ], + }); + }); + }); + }); + describe('validateUpdateContentTypeInput', () => { test('Deletes empty defaults', async () => { const data = {