Skip to content

Commit

Permalink
mark create-as-update as conflict at level of entity version
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Dec 6, 2024
1 parent 17d44cc commit 7ed2b18
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 8 additions & 1 deletion lib/data/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,15 @@ const getWithConflictDetails = (defs, audits, relevantToConflict) => {
if (v.version > 1) { // v.root is false here - can use either
const baseNotContiguousWithTrunk = v.branchId != null &&
branches.get(v.branchId).lastContiguousWithTrunk < v.baseVersion;

// check if it's a create applied as an update, which is also a conflict
const createAsUpdate = def.aux.source?.details?.submission?.action === 'create';

const conflict = v.version !== (v.baseVersion + 1) ||
baseNotContiguousWithTrunk;
baseNotContiguousWithTrunk || createAsUpdate;

if (createAsUpdate)
v.conflictingProperties = Object.keys(v.dataReceived);

v.baseDiff = getDiffProp(v.dataReceived, { ...defs[v.baseVersion - 1].data, label: defs[v.baseVersion - 1].label });

Expand Down
5 changes: 4 additions & 1 deletion lib/model/query/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,10 @@ const _updateEntity = (dataset, entityData, submissionId, submissionDef, submiss

// make some kind of source object
const sourceDetails = {
submission: { instanceId: submissionDef.instanceId }
submission: {
instanceId: submissionDef.instanceId,
...createSubAsUpdate ? { action: 'create' } : {}
},
};
const sourceId = await Entities.createSource(sourceDetails, submissionDefId, event.id, forceOutOfOrderProcessing);
const partial = new Entity.Partial(serverEntity.with({ conflict }), {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/api/offline-entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ describe('Offline Entities', () => {
});
}));

it.only('should show proper conflict info on create applied as update', testOfflineEntities(async (service, container) => {
it('should show proper conflict info on create applied as update', testOfflineEntities(async (service, container) => {
// Issue c#815
const asAlice = await service.login('alice');
const branchId = uuid();
Expand Down Expand Up @@ -1758,8 +1758,8 @@ describe('Offline Entities', () => {
await asAlice.get('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789ddd/versions')
.expect(200)
.then(({ body }) => {
// TODO body[1].conflict should actually NOT be null
body.map(v => v.conflict).should.eql([null, null]);
body.map(v => v.conflict).should.eql([null, 'hard']);
body[1].conflictingProperties.should.eql(['age', 'label', 'status', 'first_name']);
});
}));
});
Expand Down

0 comments on commit 7ed2b18

Please sign in to comment.