Skip to content

Commit

Permalink
Merge pull request #3361 from huridocs/3357-mapping-error
Browse files Browse the repository at this point in the history
Fixed error when adding a property to a blank state uwazi
  • Loading branch information
daneryl authored Dec 10, 2020
2 parents d499e55 + 4577d2f commit fecf881
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/api/search/entitiesIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ const checkMapping = async (template, elasticIndex) => {
const errors = [];
const mapping = elasticMapFactory.mapping([template]);
const currentMapping = await elastic.indices.getMapping({ index: elasticIndex });
const mappedProps = currentMapping.body[elasticIndex].mappings.properties.metadata.properties;
const mappedProps =
currentMapping.body[elasticIndex].mappings.properties.metadata.properties || {};
const newMappedProps = mapping.properties.metadata.properties;
Object.keys(newMappedProps).forEach(key => {
if (!equalPropMapping(mappedProps[key], newMappedProps[key])) {
Expand Down
12 changes: 12 additions & 0 deletions app/api/search/specs/entitiesIndex.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ describe('entitiesIndex', () => {
response = await checkMapping(templateB, elasticIndex);
expect(response).toEqual({ errors: [{ name: 'Date of birth' }], valid: false });
});

describe('when the mapping is empty', () => {
it('should throw no errors', async () => {
const templateB = {
_id: '456',
name: 'template B',
properties: [{ name: 'dob', type: 'date', label: 'Date of birth' }],
};
const response = await checkMapping(templateB, elasticIndex);
expect(response).toEqual({ errors: [], valid: true });
});
});
});

describe('reindexAll', () => {
Expand Down

0 comments on commit fecf881

Please sign in to comment.