Skip to content

Commit

Permalink
Return new properties in serverDiff and baseDiff (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja authored Oct 24, 2023
1 parent f682891 commit 643fd63
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/data/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/model/query/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion test/unit/data/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 643fd63

Please sign in to comment.