Skip to content

Commit

Permalink
Merge pull request #3454 from huridocs/3377-checkmapping
Browse files Browse the repository at this point in the history
3377 checkmapping
  • Loading branch information
mfacar authored Feb 1, 2021
2 parents ea61bac + d260580 commit 9c1c912
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
15 changes: 9 additions & 6 deletions app/api/search/entitiesIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
14 changes: 11 additions & 3 deletions app/api/search/specs/entitiesIndex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
],
};

Expand All @@ -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', () => {
Expand Down

0 comments on commit 9c1c912

Please sign in to comment.