Skip to content
Permalink
Browse files

add test case for #124 and tweak formatting

  • Loading branch information
jeremydaly committed Oct 29, 2019
1 parent adc697a commit 256a9e767694c84821afb764d6272ad791e5eb42
Showing with 8 additions and 2 deletions.
  1. +2 −2 lib/request.js
  2. +6 −0 test/routes.js
@@ -159,8 +159,8 @@ class REQUEST {
this.rawBody = this.app._event.body

// Set the body (decode it if base64 encoded)
this.body = this.app._event.isBase64Encoded ? Buffer.from(this.app._event.body||'', 'base64').toString() : this.app._event.body
this.body = this.app._event.isBase64Encoded ? Buffer.from(this.app._event.body || '', 'base64').toString() : this.app._event.body

// Set the body
if (this.headers['content-type'] && this.headers['content-type'].includes('application/x-www-form-urlencoded')) {
this.body = QS.parse(this.body)
@@ -609,6 +609,12 @@ describe('Route Tests:', function() {
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 })
}) // end it

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

it('Missing path: /not_found', async function() {
let _event = Object.assign({},event,{ path: '/not_found', httpMethod: 'post' })
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))

0 comments on commit 256a9e7

Please sign in to comment.
You can’t perform that action at this time.