diff --git a/lib/data/entity.js b/lib/data/entity.js index 86e162ee7..936c00feb 100644 --- a/lib/data/entity.js +++ b/lib/data/entity.js @@ -348,7 +348,7 @@ const diffEntityData = (defData) => { // Returns an array of properties which are different between // `dataReceived` and `otherVersionData` const getDiffProp = (dataReceived, otherVersionData) => - Object.keys(dataReceived).filter(key => key in otherVersionData && dataReceived[key] !== otherVersionData[key]); + Object.keys(dataReceived).filter(key => (!(key in otherVersionData)) || (key in otherVersionData && dataReceived[key] !== otherVersionData[key])); const ConflictType = { SOFT: 'soft', // discrepancy in version number but no overlaping properties diff --git a/lib/model/query/entities.js b/lib/model/query/entities.js index be380f03d..c2d867c75 100644 --- a/lib/model/query/entities.js +++ b/lib/model/query/entities.js @@ -194,7 +194,7 @@ const _updateEntity = (dataset, entityData, submissionId, submissionDef, submiss if (serverEntity.aux.currentVersion.label !== baseEntityVersion.label) serverDiffData.label = serverEntity.aux.currentVersion.label; - conflictingProperties = getDiffProp(clientEntity.def.dataReceived, serverDiffData); + conflictingProperties = Object.keys(clientEntity.def.dataReceived).filter(key => key in serverDiffData && clientEntity.def.dataReceived[key] !== serverDiffData[key]); if (conflict !== ConflictType.HARD) { // We don't want to downgrade conflict here conflict = conflictingProperties.length > 0 ? ConflictType.HARD : ConflictType.SOFT; diff --git a/test/unit/data/entity.js b/test/unit/data/entity.js index 1e9897d3a..63ecd8da5 100644 --- a/test/unit/data/entity.js +++ b/test/unit/data/entity.js @@ -673,9 +673,14 @@ describe('extracting and validating entities', () => { describe('getDiffProp', () => { it('should return list of different properties', () => { - getDiffProp({ name: 'John', age: '22', gender: 'male' }, { name: 'Jane', age: '22', hometown: 'Boston' }) + getDiffProp({ name: 'John', age: '22', hometown: 'Boston' }, { name: 'Jane', age: '22', hometown: 'Boston' }) .should.eql(['name']); }); + + it('should include properties not in 2nd argument', () => { + getDiffProp({ name: 'John', age: '22', gender: 'male' }, { name: 'Jane', age: '22', hometown: 'Boston' }) + .should.eql(['name', 'gender']); + }); }); describe('getWithConflictDetails', () => {