Skip to content

Commit

Permalink
Exclude deleted forms from linkedForms (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-white authored Apr 26, 2024
1 parent cfe46c9 commit c2982af
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/model/query/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ const getMetadata = (dataset) => async ({ all, Datasets }) => {

const _getLinkedForms = (datasetName, projectId) => sql`
SELECT DISTINCT f."xmlFormId", coalesce(fd.name, f."xmlFormId") "name" FROM form_attachments fa
JOIN forms f ON f.id = fa."formId"
JOIN forms f ON f.id = fa."formId" AND f."deletedAt" IS NULL
JOIN form_defs fd ON f."currentDefId" = fd.id
JOIN datasets ds ON ds.id = fa."datasetId"
WHERE ds.name = ${datasetName}
Expand Down
32 changes: 32 additions & 0 deletions test/integration/api/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,38 @@ describe('datasets and entities', () => {

}));

it('should not return a linked form that has been deleted', testService(async (service) => {
const asAlice = await service.login('alice');
await asAlice.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.simpleEntity)
.set('Content-Type', 'application/xml')
.expect(200);
const withAttachments = testData.forms.withAttachments
.replace('goodone.csv', 'people.csv');
await asAlice.post('/v1/projects/1/forms?publish=true')
.send(withAttachments)
.set('Content-Type', 'application/xml')
.expect(200);
await asAlice.post('/v1/projects/1/forms?publish=true')
.send(withAttachments
.replace('id="withAttachments"', 'id="withAttachments2"'))
.set('Content-Type', 'application/xml')
.expect(200);
const { body: beforeDeletion } = await asAlice.get('/v1/projects/1/datasets/people')
.expect(200);
beforeDeletion.linkedForms.map(form => form.xmlFormId).should.eql([
'withAttachments',
'withAttachments2'
]);
await asAlice.delete('/v1/projects/1/forms/withAttachments2')
.expect(200);
const { body: afterDeletion } = await asAlice.get('/v1/projects/1/datasets/people')
.expect(200);
afterDeletion.linkedForms.map(form => form.xmlFormId).should.eql([
'withAttachments'
]);
}));

it('should return properties of a dataset in order', testService(async (service) => {
const asAlice = await service.login('alice');

Expand Down

0 comments on commit c2982af

Please sign in to comment.