Skip to content

Commit

Permalink
Dont count submission edits in pending submission count (#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite authored Dec 8, 2023
1 parent 5e08f06 commit 38410eb
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/model/query/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ LEFT JOIN (
entity_defs ed
JOIN entity_def_sources es ON es.id = ed."sourceId"
JOIN entities e ON e.id = ed."entityId" AND e."datasetId" = ${datasetId}
) ON es."submissionDefId" = sd.id
JOIN submission_defs source_sub_defs ON es."submissionDefId" = source_sub_defs.id
) ON source_sub_defs."submissionId" = s.id
LEFT JOIN (
SELECT DISTINCT ON ((details->'submissionDefId')::INTEGER) * FROM audits
WHERE action = 'entity.error'
Expand Down
70 changes: 70 additions & 0 deletions test/integration/api/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4155,6 +4155,76 @@ describe('datasets and entities', () => {
}));
});

it('should not let submission edits get caught in pending submission count', testService(async (service, container) => {
const asAlice = await service.login('alice');

// Upload form that creates an entity list and publish it
await asAlice.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.simpleEntity)
.set('Content-Type', 'application/xml')
.expect(200);

// Configure the entity list to create entities on submission approval
await asAlice.patch('/v1/projects/1/datasets/people')
.send({ approvalRequired: true })
.expect(200);

// Populate one entity
await asAlice.post('/v1/projects/1/datasets/people/entities')
.send({
uuid: '12345678-1234-4123-8234-123456789abc',
label: 'Johnny Doe',
data: { first_name: 'Johnny', age: '22' }
})
.expect(200);

// Upload form that updates entities
await asAlice.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.updateEntity)
.set('Content-Type', 'application/xml')
.expect(200);

// Send submission
await asAlice.post('/v1/projects/1/forms/updateEntity/submissions')
.send(testData.instances.updateEntity.one)
.set('Content-Type', 'application/xml')
.expect(200);

await exhaust(container);

// Observe that entity was updated
await asAlice.get('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc')
.expect(200)
.then(({ body: person }) => {
person.currentVersion.data.age.should.equal('85');
person.currentVersion.version.should.equal(2);
});

// Edit the submission
await asAlice.patch('/v1/projects/1/forms/updateEntity/submissions/one')
.send(testData.instances.updateEntity.one
.replace('<instanceID>one', '<deprecatedID>one</deprecatedID><instanceID>one2')
.replace('<age>85</age>', '<age>99</age>'))
.set('Content-Type', 'application/xml')
.expect(200);

// Should do nothing
await exhaust(container);

// Observe that nothing else happened with the entity
await asAlice.get('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc')
.expect(200)
.then(({ body: person }) => {
person.currentVersion.data.age.should.equal('85');
person.currentVersion.version.should.equal(2);
});

// count return 200 instead of 400 error with pending submission count
await asAlice.patch('/v1/projects/1/datasets/people')
.send({ approvalRequired: false })
.expect(200);
}));

describe('central issue #547, reprocessing submissions that had previous entity errors', () => {
it('should not reprocess submission that previously generated entity.error', testService(async (service, container) => {
const asAlice = await service.login('alice');
Expand Down

0 comments on commit 38410eb

Please sign in to comment.