Skip to content

feat: rename builder function wrapper #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 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
2 changes: 1 addition & 1 deletion src/lib/builder_functions.js → src/lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ const wrapHandler = (handler) => (event, context, callback) => {
return execution
}

module.exports = { builderFunction: wrapHandler }
module.exports = { builder: wrapHandler }
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const { builderFunction } = require('./lib/builder_functions')
const { builder } = require('./lib/builder')

module.exports = { builderFunction }
module.exports = { builder }
20 changes: 10 additions & 10 deletions test/builder_functions.js → test/builder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('ava')

const { builderFunction } = require('../src/lib/builder_functions')
const { builder } = require('../src/lib/builder')

const { invokeLambda } = require('./helpers/main')

Expand All @@ -20,7 +20,7 @@ test('Injects the metadata object into an asynchronous handler', async (t) => {

return originalResponse
}
const response = await invokeLambda(builderFunction(myHandler))
const response = await invokeLambda(builder(myHandler))

t.deepEqual(response, { ...originalResponse, ...METADATA_OBJECT })
})
Expand All @@ -33,7 +33,7 @@ test('Injects the metadata object into a synchronous handler', async (t) => {
const myHandler = (event, context, callback) => {
callback(null, originalResponse)
}
const response = await invokeLambda(builderFunction(myHandler))
const response = await invokeLambda(builder(myHandler))

t.deepEqual(response, { ...originalResponse, ...METADATA_OBJECT })
})
Expand All @@ -52,7 +52,7 @@ test('Does not inject the metadata object for non-200 responses', async (t) => {

return originalResponse
}
const response = await invokeLambda(builderFunction(myHandler))
const response = await invokeLambda(builder(myHandler))

t.deepEqual(response, originalResponse)
})
Expand All @@ -71,7 +71,7 @@ test('Returns a 405 error for requests using the POST method', async (t) => {

return originalResponse
}
const response = await invokeLambda(builderFunction(myHandler), { method: 'POST' })
const response = await invokeLambda(builder(myHandler), { method: 'POST' })

t.deepEqual(response, { body: 'Method Not Allowed', statusCode: 405 })
})
Expand All @@ -90,7 +90,7 @@ test('Returns a 405 error for requests using the PUT method', async (t) => {

return originalResponse
}
const response = await invokeLambda(builderFunction(myHandler), { method: 'PUT' })
const response = await invokeLambda(builder(myHandler), { method: 'PUT' })

t.deepEqual(response, { body: 'Method Not Allowed', statusCode: 405 })
})
Expand All @@ -109,7 +109,7 @@ test('Returns a 405 error for requests using the DELETE method', async (t) => {

return originalResponse
}
const response = await invokeLambda(builderFunction(myHandler), { method: 'DELETE' })
const response = await invokeLambda(builder(myHandler), { method: 'DELETE' })

t.deepEqual(response, { body: 'Method Not Allowed', statusCode: 405 })
})
Expand All @@ -128,7 +128,7 @@ test('Returns a 405 error for requests using the PATCH method', async (t) => {

return originalResponse
}
const response = await invokeLambda(builderFunction(myHandler), { method: 'PATCH' })
const response = await invokeLambda(builder(myHandler), { method: 'PATCH' })

t.deepEqual(response, { body: 'Method Not Allowed', statusCode: 405 })
})
Expand All @@ -148,7 +148,7 @@ test('Preserves errors thrown inside the wrapped handler', async (t) => {
throw error
}

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

test('Does not pass query parameters to the wrapped handler', async (t) => {
Expand All @@ -165,7 +165,7 @@ test('Does not pass query parameters to the wrapped handler', async (t) => {
}
const multiValueQueryStringParameters = { foo: ['bar'], bar: ['baz'] }
const queryStringParameters = { foo: 'bar', bar: 'baz' }
const response = await invokeLambda(builderFunction(myHandler), {
const response = await invokeLambda(builder(myHandler), {
multiValueQueryStringParameters,
queryStringParameters,
})
Expand Down