diff --git a/test/integration/other/submission-purging.js b/test/integration/other/submission-purging.js index c86a6a0db..14ce118cd 100644 --- a/test/integration/other/submission-purging.js +++ b/test/integration/other/submission-purging.js @@ -2,6 +2,7 @@ const { sql } = require('slonik'); const { testService } = require('../setup'); const testData = require('../../data/xml'); const should = require('should'); +const { createReadStream } = require('fs'); const appPath = require('app-root-path'); const { exhaust } = require(appPath + '/lib/worker/worker'); @@ -331,18 +332,53 @@ describe('query module submission purge', () => { }); })); - // TODO check soft-deleted submissions - // should not be accessible - // should not show up in any export - // should not show up in odata - // should interact with pagination and skip tokens + // TODO: test doesn't pass because of client audit purging bug + it.skip('should purge client audit blobs attachments for a deleted submission', testService(async (service, container) => { + const asAlice = await service.login('alice'); + + // Create the form + await asAlice.post('/v1/projects/1/forms?publish=true') + .send(testData.forms.clientAudits) + .expect(200); + + // Send the submission with the client audit attachment + await asAlice.post('/v1/projects/1/submission') + .set('X-OpenRosa-Version', '1.0') + .attach('audit.csv', createReadStream(appPath + '/test/data/audit.csv'), { filename: 'audit.csv' }) + .attach('xml_submission_file', Buffer.from(testData.instances.clientAudits.one), { filename: 'data.xml' }) + .expect(201); + + // Process the client audit attachment + await exhaust(container); + + // Check that the client audit events are in the database + const clientAuditEventCount = await container.oneFirst(sql`select count(*) from client_audits group by "blobId"`); + clientAuditEventCount.should.equal(5); // 1 blob with 5 events in it + + // Check that the blobs are in the database + const numBlobs = await container.oneFirst(sql`select count(*) from blobs`); + numBlobs.should.equal(1); + + // Delete the submission + await asAlice.delete('/v1/projects/1/forms/clientAudits/submissions/one'); + + // Purge the submission + await container.Submissions.purge(true); + + // Check that the client audit events are deleted from the database + const numClientAudits = await container.oneFirst(sql`select count(*) from client_audits`); + numClientAudits.should.equal(0); + + // Check that the blobs are deleted from the database + const count = await container.oneFirst(sql`select count(*) from blobs`); + count.should.equal(0); + })); // TODO other stuff // should not delete a draft submission? or yes? // should purge client audits associated with a submission via attachment // TODO in purge function - // redact audit notes // decide there should be no actee id in the submission.purge audit log because it could be across forms or projects // purge by specific thing like project,xmlFormId,instanceId // add cli thing to do this