From 6ebeb2870e597e4e353905413b9cfd0f4404e0af Mon Sep 17 00:00:00 2001 From: Kathleen Tuite Date: Mon, 15 Nov 2021 11:55:07 -0800 Subject: [PATCH] immediately purge deleted form with only a draft --- lib/model/query/forms.js | 7 +++++-- test/integration/other/form-purging.js | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/model/query/forms.js b/lib/model/query/forms.js index fecbd78cd..c8af9ad29 100644 --- a/lib/model/query/forms.js +++ b/lib/model/query/forms.js @@ -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); diff --git a/test/integration/other/form-purging.js b/test/integration/other/form-purging.js index 10449fb43..d2cb0d591 100644 --- a/test/integration/other/form-purging.js +++ b/test/integration/other/form-purging.js @@ -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') @@ -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')