Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return correct response for conflict after multiple prior resolutions #1054

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/data/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ const ConflictType = {
const getWithConflictDetails = (defs, audits, relevantToConflict) => {
const result = [];

const lastResolveEvent = audits.findLast(a => a.action === 'entity.update.resolve');
const lastResolveEvent = audits.find(a => a.action === 'entity.update.resolve');

const auditMap = new Map(audits
.filter(a => a.action === 'entity.create' || a.action === 'entity.update.version')
Expand Down
38 changes: 38 additions & 0 deletions test/integration/api/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,44 @@ describe('Entities API', () => {
versions.map(v => v.resolved).should.eql([false, false, false, true, false]);
});
}));

it('should return correct response for conflict after second resolution', testEntities(async (service, container) => {
const asAlice = await service.login('alice');
await createConflictOnV2(asAlice, container);
await asAlice.patch('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc?resolve=true&baseVersion=4')
.expect(200);

// Create v5 based on v3, then resolve it.
await asAlice.post('/v1/projects/1/forms/updateEntity/submissions')
.send(testData.instances.updateEntity.two
.replace('baseVersion="1"', 'baseVersion="3"'))
.set('Content-Type', 'application/xml')
.expect(200);
await exhaust(container);
await asAlice.patch('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc?resolve=true&baseVersion=5')
.expect(200);

// Create v6 based on v3, but don't resolve it.
await asAlice.post('/v1/projects/1/forms/updateEntity/submissions')
.send(testData.instances.updateEntity.three
.replace('baseVersion="1"', 'baseVersion="3"'))
.set('Content-Type', 'application/xml')
.expect(200);
await exhaust(container);

const { body: versions } = await asAlice.get('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc/versions')
.expect(200);
versions.length.should.equal(6);
versions[5].conflict.should.equal('hard');
versions.map(version => version.resolved)
.should.eql([false, false, false, true, true, false]);
versions.filter(version => version.lastGoodVersion)
.map(version => version.version)
.should.eql([5]);
versions.filter(version => version.relevantToConflict)
.map(version => version.version)
.should.eql([3, 5, 6]);
}));
});
});

Expand Down