From 891edc2bcf48506b8f71b7227218da96dab072e0 Mon Sep 17 00:00:00 2001 From: Sadiq Khoja Date: Mon, 3 Jul 2023 14:37:48 -0400 Subject: [PATCH] fixes #701: don't start transaction for POST submission.csv (#917) --- lib/http/endpoint.js | 2 +- test/unit/http/endpoint.js | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/http/endpoint.js b/lib/http/endpoint.js index 907231542..6a932c7e2 100644 --- a/lib/http/endpoint.js +++ b/lib/http/endpoint.js @@ -34,7 +34,7 @@ const Problem = require('../util/problem'); // determines if a request needs a transaction. const phony = (request) => { - if (/submissions\.csv\.zip$/i.test(request.path)) return true; + if (/submissions\.csv(\.zip)?$/i.test(request.path)) return true; return false; }; const isWriteRequest = (request) => !phony(request) && diff --git a/test/unit/http/endpoint.js b/test/unit/http/endpoint.js index 4df59837d..5ba79110e 100644 --- a/test/unit/http/endpoint.js +++ b/test/unit/http/endpoint.js @@ -361,20 +361,20 @@ describe('endpoints', () => { .then(() => { transacted.should.equal(false); }); }))); - it('should not initiate a transaction given a nonwrite POST', () => { - let transacted = false; - const container = { - transacting(cb) { transacted = true; return cb(); }, - with() { return container; } - }; + it('should not initiate a transaction given a nonwrite POST', () => + Promise.all([ + '/projects/1/forms/encrypted/submissions.csv', + '/projects/1/forms/encrypted/submissions.csv.zip' + ].map((path) => { + let transacted = false; + const container = { + transacting(cb) { transacted = true; return cb(); }, + with() { return container; } + }; - const request = { - method: 'POST', - path: '/projects/1/forms/encrypted/submissions.csv.zip' - }; - return endpointBase({ resultWriter: noop })(container)(always(true))(request) - .then(() => { transacted.should.equal(false); }); - }); + return endpointBase({ resultWriter: noop })(container)(always(true))({ method: 'POST', path }) + .then(() => { transacted.should.equal(false); }); + }))); it('should reject on the transacting promise on preprocessor failure', () => { // we still check the transacted flag just to be sure the rejectedWith assertion runs.