From d0e46810e2624dda9403f313aeaf6a338f3078a4 Mon Sep 17 00:00:00 2001 From: Sadiq Khoja Date: Sat, 21 Oct 2023 08:26:33 -0400 Subject: [PATCH] incorporated PR feedback --- lib/data/entity.js | 6 ++++-- test/unit/data/entity.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/data/entity.js b/lib/data/entity.js index e32169970..fb24ca148 100644 --- a/lib/data/entity.js +++ b/lib/data/entity.js @@ -361,7 +361,9 @@ const getWithConflictDetails = (defs, audits, relevantToConflict) => { const lastResolveEvent = audits.findLast(a => a.action === 'entity.update.resolve'); - const auditMap = new Map(audits.map(a => [a.details.entityDefId, a.details])); + const auditMap = new Map(audits + .filter(a => a.action === 'entity.create' || a.action === 'entity.update.version') + .map(a => [a.details.entityDefId, a.details])); const versionMap = new Map(); @@ -418,7 +420,7 @@ const getWithConflictDetails = (defs, audits, relevantToConflict) => { // We return all the versions after last good version and the base versions of those. if (relevantToConflict) { - return result.filter(v => lastGoodVersion > 0 && (v.version >= lastGoodVersion || relevantBaseVersions.has(v.version))); + return lastGoodVersion > 0 ? result.filter(v => v.version >= lastGoodVersion || relevantBaseVersions.has(v.version)) : []; } return result; diff --git a/test/unit/data/entity.js b/test/unit/data/entity.js index 2b08c2a08..38cd346e5 100644 --- a/test/unit/data/entity.js +++ b/test/unit/data/entity.js @@ -688,7 +688,7 @@ describe('extracting and validating entities', () => { new Entity.Def({ id: 0, version: 3, label: 'Jane', data: { name: 'Jane', age: '99' }, dataReceived: { age: '99' }, conflictingProp: [], baseVersion: 1 }) ]; - const audits = [{ details: { entityDefId: 0 } }]; + const audits = [{ action: 'entity.create', details: { entityDefId: 0 } }]; const result = getWithConflictDetails(defs, audits, false); @@ -704,7 +704,7 @@ describe('extracting and validating entities', () => { new Entity.Def({ id: 0, version: 3, label: 'Jane', data: { name: 'Jane', age: '99' }, dataReceived: { age: '99' }, conflictingProperties: ['age'], baseVersion: 1 }) ]; - const audits = [{ details: { entityDefId: 0 } }]; + const audits = [{ action: 'entity.create', details: { entityDefId: 0 } }]; const result = getWithConflictDetails(defs, audits, false);