fix(entity-validator): improve error messaging

This commit is contained in:
Jamie Howard 2022-11-23 14:32:26 +00:00
parent 7d64a36867
commit df0fe1c9be
4 changed files with 44 additions and 33 deletions

View File

@ -280,7 +280,8 @@ describe('CM API - Basic + dz + draftAndPublish', () => {
name: 'ValidationError', name: 'ValidationError',
}, },
{ {
message: 'Cannot build relations store: "uid" is undefined', message:
'Cannot build relations store from dynamiczone, component identifier is undefined',
name: 'ValidationError', name: 'ValidationError',
path: [], path: [],
}, },

View File

@ -310,7 +310,8 @@ describe('CM API - Basic + dz', () => {
name: 'ValidationError', name: 'ValidationError',
}, },
{ {
message: 'Cannot build relations store: "uid" is undefined', message:
'Cannot build relations store from dynamiczone, component identifier is undefined',
name: 'ValidationError', name: 'ValidationError',
path: [], path: [],
}, },

View File

@ -293,40 +293,48 @@ const buildRelationsStore = ({ uid, data }) => {
break; break;
} }
case 'component': { case 'component': {
return castArray(value).reduce( return castArray(value).reduce((relationsStore, componentValue) => {
(relationsStore, componentValue) => if (!attribute.component) {
mergeWith( throw new ValidationError(
relationsStore, `Cannot build relations store from component, component identifier is undefined`
buildRelationsStore({ );
uid: attribute.component, }
data: componentValue,
}), return mergeWith(
(objValue, srcValue) => { relationsStore,
if (isArray(objValue)) { buildRelationsStore({
return objValue.concat(srcValue); uid: attribute.component,
} data: componentValue,
}),
(objValue, srcValue) => {
if (isArray(objValue)) {
return objValue.concat(srcValue);
} }
), }
result );
); }, result);
} }
case 'dynamiczone': { case 'dynamiczone': {
return value.reduce( return value.reduce((relationsStore, dzValue) => {
(relationsStore, dzValue) => if (!dzValue.__component) {
mergeWith( throw new ValidationError(
relationsStore, `Cannot build relations store from dynamiczone, component identifier is undefined`
buildRelationsStore({ );
uid: dzValue.__component, }
data: dzValue,
}), return mergeWith(
(objValue, srcValue) => { relationsStore,
if (isArray(objValue)) { buildRelationsStore({
return objValue.concat(srcValue); uid: dzValue.__component,
} data: dzValue,
}),
(objValue, srcValue) => {
if (isArray(objValue)) {
return objValue.concat(srcValue);
} }
), }
result );
); }, result);
} }
default: default:
break; break;

View File

@ -350,7 +350,8 @@ describe('Core API - Basic + dz', () => {
name: 'ValidationError', name: 'ValidationError',
}, },
{ {
message: 'Cannot build relations store: "uid" is undefined', message:
'Cannot build relations store from dynamiczone, component identifier is undefined',
name: 'ValidationError', name: 'ValidationError',
path: [], path: [],
}, },