Fix test, add missing global

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-04-28 18:10:39 +02:00 committed by Alexandre BODIN
parent 7e41e28bf8
commit a0c87af098

View File

@ -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 = {