Skip to content

Commit

Permalink
immediately purge deleted form with only a draft
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Nov 15, 2021
1 parent 21d680a commit 6ebeb28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/model/query/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ update.audit = (form, data) => (log) => log('form.update', form, { data });

const _updateDef = (form, data) => ({ one }) => one(updater(form.def, data));

const del = (form) => ({ run, Assignments }) =>
Promise.all([ run(markDeleted(form)), Assignments.revokeByActeeId(form.acteeId) ]);
const del = (form) => ({ run, Assignments, Forms }) =>
Promise.all([ run(markDeleted(form)), Assignments.revokeByActeeId(form.acteeId) ])
.then(() => ((form.currentDefId === null)
? Forms.purge(true, form.id)
: null));
del.audit = (form) => (log) => log('form.delete', form);


Expand Down
17 changes: 16 additions & 1 deletion test/integration/other/form-purging.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const testData = require('../../data/xml');
const { createReadStream } = require('fs');


describe.only('query module form purge', () => {
describe('query module form purge', () => {
it('should purge a soft-deleted form', testService((service, container) =>
service.login('alice', (asAlice) =>
asAlice.delete('/v1/projects/1/forms/simple')
Expand Down Expand Up @@ -117,6 +117,21 @@ describe.only('query module form purge', () => {
]))
.then((counts) => counts.should.eql([0, 0])))));

it('should immediately purge a deleted form with only a draft', testService((service, container) =>
service.login('alice', (asAlice) =>
asAlice.post('/v1/projects/1/forms')
.send(testData.forms.simple2)
.set('Content-Type', 'application/xml')
.expect(200)
.then(() => container.Forms.getByProjectAndXmlFormId(1, 'simple2').then((o) => o.get())
.then((ghostForm) => asAlice.delete('/v1/projects/1/forms/simple2') // purge should happen internally
.expect(200)
.then(() => Promise.all([
container.oneFirst(sql`select count(*) from forms where id=${ghostForm.id}`),
container.oneFirst(sql`select count(*) from form_defs where "formId"=${ghostForm.id}`)
]))
.then((counts) => counts.should.eql([0, 0])))))));

it('should purge attachments (and blobs) of a form', testService((service, container) =>
service.login('alice', (asAlice) =>
asAlice.post('/v1/projects/1/forms')
Expand Down

0 comments on commit 6ebeb28

Please sign in to comment.