Skip to content

Commit 256a9e7

Browse files
committed
add test case for #124 and tweak formatting
1 parent adc697a commit 256a9e7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ class REQUEST {
159159
this.rawBody = this.app._event.body
160160

161161
// Set the body (decode it if base64 encoded)
162-
this.body = this.app._event.isBase64Encoded ? Buffer.from(this.app._event.body||'', 'base64').toString() : this.app._event.body
163-
162+
this.body = this.app._event.isBase64Encoded ? Buffer.from(this.app._event.body || '', 'base64').toString() : this.app._event.body
163+
164164
// Set the body
165165
if (this.headers['content-type'] && this.headers['content-type'].includes('application/x-www-form-urlencoded')) {
166166
this.body = QS.parse(this.body)

test/routes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,12 @@ describe('Route Tests:', function() {
609609
expect(result).to.deep.equal({ multiValueHeaders: { 'content-type': ['application/json'] }, statusCode: 200, body: '{"method":"post","status":"ok","body":"Test file for sendFile\\n"}', isBase64Encoded: false })
610610
}) // end it
611611

612+
it('With base64 encoding flagged and no body', async function() {
613+
let _event = Object.assign({},event,{ path: '/test/base64', httpMethod: 'post', body: undefined, isBase64Encoded: true })
614+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
615+
expect(result).to.deep.equal({ multiValueHeaders: { 'content-type': ['application/json'] }, statusCode: 200, body: '{"method":"post","status":"ok","body":""}', isBase64Encoded: false })
616+
}) // end it
617+
612618
it('Missing path: /not_found', async function() {
613619
let _event = Object.assign({},event,{ path: '/not_found', httpMethod: 'post' })
614620
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))

0 commit comments

Comments
 (0)