Skip to content

Commit

Permalink
incorporated PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja committed Oct 21, 2023
1 parent ceff8d3 commit d0e4681
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/data/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/unit/data/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit d0e4681

Please sign in to comment.