diff --git a/app/api/search/entitiesIndex.js b/app/api/search/entitiesIndex.js index 14c88758cb..33a0f9ba23 100644 --- a/app/api/search/entitiesIndex.js +++ b/app/api/search/entitiesIndex.js @@ -170,13 +170,16 @@ const equalPropMapping = (mapA, mapB) => { return true; } - const sameAmountOfProps = - Object.keys(mapA.properties).length === Object.keys(mapB.properties).length; - const sameProps = Object.keys(mapA.properties).reduce( - (result, propKey) => result && mapA.properties[propKey].type === mapB.properties[propKey].type, - true + return ( + Object.keys(mapA.properties).length === Object.keys(mapB.properties).length && + Object.keys(mapA.properties).reduce( + (result, propKey) => + result && + mapB.properties[propKey] && + mapA.properties[propKey].type === mapB.properties[propKey].type, + true + ) ); - return sameAmountOfProps && sameProps; }; const checkMapping = async template => { diff --git a/app/api/search/specs/entitiesIndex.spec.ts b/app/api/search/specs/entitiesIndex.spec.ts index e4e81c78eb..e9fd61c24d 100644 --- a/app/api/search/specs/entitiesIndex.spec.ts +++ b/app/api/search/specs/entitiesIndex.spec.ts @@ -103,7 +103,7 @@ describe('entitiesIndex', () => { properties: [ { name: 'name', type: 'text', label: 'Name' }, { name: 'dob', type: 'date', label: 'Date of birth' }, - { name: 'country', type: 'select', label: 'Country' }, + { name: 'country', type: 'relationship', label: 'Country' }, ], }; @@ -117,9 +117,17 @@ describe('entitiesIndex', () => { let response = await checkMapping(templateB); expect(response).toEqual({ errors: [], valid: true }); - templateB.properties[0].type = 'text'; + templateB.properties = [ + { name: 'dob', type: 'text', label: 'Date of birth' }, + { name: 'country', type: 'select', label: 'Country' }, + ]; + response = await checkMapping(templateB); - expect(response).toEqual({ errors: [{ name: 'Date of birth' }], valid: false }); + + expect(response).toEqual({ + errors: [{ name: 'Date of birth' }, { name: 'Country' }], + valid: false, + }); }); describe('when the mapping is empty', () => {