Skip to content

Commit 1219049

Browse files
feat: omit query string parameters from builder functions (#40)
* feat: omit query string parameters from builder functions * feat: pass empty query string param objects to builder function
1 parent a5414a1 commit 1219049

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/lib/builder_functions.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ const wrapHandler = (handler) => (event, context, callback) => {
2222
})
2323
}
2424

25+
// Removing query string parameters from the builder function.
26+
const modifiedEvent = {
27+
...event,
28+
multiValueQueryStringParameters: {},
29+
queryStringParameters: {},
30+
}
31+
2532
// eslint-disable-next-line promise/prefer-await-to-callbacks
2633
const wrappedCallback = (error, response) => callback(error, augmentResponse(response))
27-
const execution = handler(event, context, wrappedCallback)
34+
const execution = handler(modifiedEvent, context, wrappedCallback)
2835

2936
if (isPromise(execution)) {
3037
// eslint-disable-next-line promise/prefer-await-to-then

test/builder_functions.js

+22
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,25 @@ test('Preserves errors thrown inside the wrapped handler', async (t) => {
150150

151151
await t.throwsAsync(invokeLambda(builderFunction(myHandler)), { is: error })
152152
})
153+
154+
test('Does not pass query parameters to the wrapped handler', async (t) => {
155+
const originalResponse = {
156+
body: ':thumbsup:',
157+
statusCode: 200,
158+
}
159+
// eslint-disable-next-line require-await
160+
const myHandler = async (event) => {
161+
t.deepEqual(event.multiValueQueryStringParameters, {})
162+
t.deepEqual(event.queryStringParameters, {})
163+
164+
return originalResponse
165+
}
166+
const multiValueQueryStringParameters = { foo: ['bar'], bar: ['baz'] }
167+
const queryStringParameters = { foo: 'bar', bar: 'baz' }
168+
const response = await invokeLambda(builderFunction(myHandler), {
169+
multiValueQueryStringParameters,
170+
queryStringParameters,
171+
})
172+
173+
t.deepEqual(response, { ...originalResponse, ...METADATA_OBJECT })
174+
})

test/helpers/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const invokeLambda = (handler, { method = 'GET' } = {}) => {
1+
const invokeLambda = (handler, { method = 'GET', ...options } = {}) => {
22
const event = {
3+
...options,
34
httpMethod: method,
45
}
56

0 commit comments

Comments
 (0)