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

Fix count of pending submissions involving edits #1058

Merged
merged 1 commit into from
Dec 8, 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
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