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,9 +293,14 @@ 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(
`Cannot build relations store from component, component identifier is undefined`
);
}
return mergeWith(
relationsStore, relationsStore,
buildRelationsStore({ buildRelationsStore({
uid: attribute.component, uid: attribute.component,
@ -306,14 +311,18 @@ const buildRelationsStore = ({ uid, data }) => {
return objValue.concat(srcValue); 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(
`Cannot build relations store from dynamiczone, component identifier is undefined`
);
}
return mergeWith(
relationsStore, relationsStore,
buildRelationsStore({ buildRelationsStore({
uid: dzValue.__component, uid: dzValue.__component,
@ -324,9 +333,8 @@ const buildRelationsStore = ({ uid, data }) => {
return objValue.concat(srcValue); 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: [],
}, },