Skip to content

Commit

Permalink
more tests of reusing instance id
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Sep 18, 2024
1 parent 35eb13c commit 839dcfc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/model/query/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const getDeleted = (projectId, formId, instanceId) => ({ maybeOne }) =>
and submissions."formId" = ${formId}
and submissions."instanceId" = ${instanceId}
and submissions."deletedAt" IS NOT NULL
limit 1`)
`)
.then(map(construct(Submission)));

const joinOnSkiptoken = (skiptoken, formId, draft) => {
Expand Down
53 changes: 52 additions & 1 deletion test/integration/api/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const should = require('should');
const uuid = require('uuid').v4;
const { sql } = require('slonik');
const { createReadStream, readFileSync } = require('fs');
const { testService } = require('../setup');
const { testService, testServiceFullTrx } = require('../setup');
const testData = require('../../data/xml');
const { pZipStreamToFiles } = require('../../util/zip');
const { map } = require('ramda');
Expand Down Expand Up @@ -1437,6 +1437,57 @@ describe('api: /forms/:id/submissions', () => {
await asAlice.delete('/v1/projects/1/forms/simple/draft/submissions/one')
.expect(404);
}));

it('should not let a submission with the same instanceId as a deleted submission be sent', testServiceFullTrx(async (service, { Submissions }) => {
const asAlice = await service.login('alice');

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

await asAlice.delete('/v1/projects/1/forms/simple/submissions/one')
.expect(200);

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

// once purged, the submission can be sent in again
await Submissions.purge(true);

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

it('should delete and restore non-draft submission even when draft submission with same instanceId exists', testService(async (service) => {
const asAlice = await service.login('alice');

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

// make a draft submission with the same instanceId
await asAlice.post('/v1/projects/1/forms/simple/draft');
await asAlice.post('/v1/projects/1/forms/simple/draft/submissions')
.send(testData.instances.simple.one)
.set('Content-Type', 'application/xml')
.expect(200);

// does not effect delete and restore of non-draft submission
await asAlice.delete('/v1/projects/1/forms/simple/submissions/one')
.expect(200);

await asAlice.post('/v1/projects/1/forms/simple/submissions/one/restore')
.expect(200);

await asAlice.get('/v1/projects/1/forms/simple/submissions/one')
.expect(200);
}));
});

describe('/:instanceId RESTORE', () => {
Expand Down

0 comments on commit 839dcfc

Please sign in to comment.