Skip to content

Commit

Permalink
feat: omit query string parameters from builder functions (#40)
Browse files Browse the repository at this point in the history
* feat: omit query string parameters from builder functions

* feat: pass empty query string param objects to builder function
  • Loading branch information
eduardoboucas authored Apr 8, 2021
1 parent a5414a1 commit 1219049
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/lib/builder_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ const wrapHandler = (handler) => (event, context, callback) => {
})
}

// Removing query string parameters from the builder function.
const modifiedEvent = {
...event,
multiValueQueryStringParameters: {},
queryStringParameters: {},
}

// eslint-disable-next-line promise/prefer-await-to-callbacks
const wrappedCallback = (error, response) => callback(error, augmentResponse(response))
const execution = handler(event, context, wrappedCallback)
const execution = handler(modifiedEvent, context, wrappedCallback)

if (isPromise(execution)) {
// eslint-disable-next-line promise/prefer-await-to-then
Expand Down
22 changes: 22 additions & 0 deletions test/builder_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,25 @@ test('Preserves errors thrown inside the wrapped handler', async (t) => {

await t.throwsAsync(invokeLambda(builderFunction(myHandler)), { is: error })
})

test('Does not pass query parameters to the wrapped handler', async (t) => {
const originalResponse = {
body: ':thumbsup:',
statusCode: 200,
}
// eslint-disable-next-line require-await
const myHandler = async (event) => {
t.deepEqual(event.multiValueQueryStringParameters, {})
t.deepEqual(event.queryStringParameters, {})

return originalResponse
}
const multiValueQueryStringParameters = { foo: ['bar'], bar: ['baz'] }
const queryStringParameters = { foo: 'bar', bar: 'baz' }
const response = await invokeLambda(builderFunction(myHandler), {
multiValueQueryStringParameters,
queryStringParameters,
})

t.deepEqual(response, { ...originalResponse, ...METADATA_OBJECT })
})
3 changes: 2 additions & 1 deletion test/helpers/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const invokeLambda = (handler, { method = 'GET' } = {}) => {
const invokeLambda = (handler, { method = 'GET', ...options } = {}) => {
const event = {
...options,
httpMethod: method,
}

Expand Down

0 comments on commit 1219049

Please sign in to comment.