Skip to content

Commit

Permalink
test/submissions/attachments: demonstrate current null Content-Type h…
Browse files Browse the repository at this point in the history
…andling (#1352)
  • Loading branch information
alxndrsn authored Jan 13, 2025
1 parent ec1c0ae commit 26cd17e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/integration/api/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4377,6 +4377,50 @@ one,h,/data/h,2000-01-01T00:06,2000-01-01T00:07,-5,-6,,ee,ff
body.toString().should.equal('testvideo');
})))))));

// Ref https://github.com/getodk/central-backend/issues/1351
it('should attach a given file with empty Content-Type', testService((service) =>
service.login('alice', (asAlice) =>
asAlice.post('/v1/projects/1/forms?publish=true')
.set('Content-Type', 'application/xml')
.send(testData.forms.binaryType)
.expect(200)
.then(() => asAlice.post('/v1/projects/1/forms/binaryType/submissions')
.send(testData.instances.binaryType.both)
.set('Content-Type', 'text/xml')
.expect(200)
.then(() => asAlice.post('/v1/projects/1/forms/binaryType/submissions/both/attachments/my_file1.mp4')
.send('testvideo')
.set('Content-Type', '') // N.B. must be called _after_ send()
.expect(200)
.then(() => asAlice.get('/v1/projects/1/forms/binaryType/submissions/both/attachments/my_file1.mp4')
.expect(200)
.then(({ headers, text }) => {
headers['content-type'].should.equal('null');
text.toString().should.equal('testvideo'); // use 'text' instead of 'body' to avoid supertest response parsing
})))))));

// Ref https://github.com/getodk/central-backend/issues/1351
it('should attach a given file with missing Content-Type', testService((service) =>
service.login('alice', (asAlice) =>
asAlice.post('/v1/projects/1/forms?publish=true')
.set('Content-Type', 'application/xml')
.send(testData.forms.binaryType)
.expect(200)
.then(() => asAlice.post('/v1/projects/1/forms/binaryType/submissions')
.send(testData.instances.binaryType.both)
.set('Content-Type', 'text/xml')
.expect(200)
.then(() => asAlice.post('/v1/projects/1/forms/binaryType/submissions/both/attachments/my_file1.mp4')
.send('testvideo')
.unset('Content-Type') // N.B. must be called _after_ send()
.expect(200)
.then(() => asAlice.get('/v1/projects/1/forms/binaryType/submissions/both/attachments/my_file1.mp4')
.expect(200)
.then(({ headers, text }) => {
headers['content-type'].should.equal('null');
text.toString().should.equal('testvideo'); // use 'text' instead of 'body' to avoid supertest response parsing
})))))));

it('should log an audit entry about initial attachment', testService((service, { Audits, Forms, Submissions, SubmissionAttachments }) =>
service.login('alice', (asAlice) =>
asAlice.post('/v1/projects/1/forms?publish=true')
Expand Down

0 comments on commit 26cd17e

Please sign in to comment.