mirror of
https://github.com/strapi/strapi.git
synced 2025-10-30 01:17:28 +00:00
Convert type customField to underlying data type
This commit is contained in:
parent
4949da189e
commit
cdfe1fcb25
@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
const { formatAttribute } = require('../attributes');
|
||||
|
||||
describe('format attributes', () => {
|
||||
it('replaces type customField with the underlying data type', () => {
|
||||
const mockAttribute = {
|
||||
type: 'customField',
|
||||
customField: 'plugin::mycustomfields.color',
|
||||
};
|
||||
|
||||
global.strapi = {
|
||||
container: {
|
||||
// mock container.get('custom-fields')
|
||||
get: jest.fn(() => ({
|
||||
// mock container.get('custom-fields').get(uid)
|
||||
get: jest.fn(() => ({
|
||||
name: 'color',
|
||||
plugin: 'mycustomfields',
|
||||
type: 'text',
|
||||
})),
|
||||
})),
|
||||
},
|
||||
};
|
||||
|
||||
const formattedAttribute = formatAttribute('key', mockAttribute);
|
||||
|
||||
const expected = {
|
||||
type: 'text',
|
||||
customField: 'plugin::mycustomfields.color',
|
||||
};
|
||||
expect(formattedAttribute).toEqual(expected);
|
||||
});
|
||||
});
|
||||
@ -67,6 +67,19 @@ const formatAttribute = (key, attribute) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (attribute.type === 'customField') {
|
||||
const customField = strapi.container.get('custom-fields').get(attribute.customField);
|
||||
|
||||
if (!customField) {
|
||||
throw new Error(`Could not find Custom Field: ${attribute.customField}`);
|
||||
}
|
||||
|
||||
return {
|
||||
...attribute,
|
||||
type: customField.type,
|
||||
};
|
||||
}
|
||||
|
||||
return attribute;
|
||||
};
|
||||
|
||||
|
||||
@ -10,6 +10,9 @@ const customFieldsRegistry = strapi => {
|
||||
getAll() {
|
||||
return customFields;
|
||||
},
|
||||
get(customField) {
|
||||
return customFields[customField];
|
||||
},
|
||||
add(customField) {
|
||||
const customFieldList = Array.isArray(customField) ? customField : [customField];
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user