Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

feat: omit query string parameters from builder functions #40

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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