Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3377 checkmapping #3454

Merged
merged 15 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 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 sameAmountOfProps && sameProps;
const sameProps =
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 sameProps;
konzz marked this conversation as resolved.
Show resolved Hide resolved
};

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