Skip to content

Commit f79d171

Browse files
authored
Merge pull request #5 from AntonBazhal/next-null
Does not override event and context when null is passed
2 parents 5b21c9c + 4a9025f commit f79d171

4 files changed

Lines changed: 38 additions & 4 deletions

File tree

lib/handler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ async function dispatch(middleware, state, i = 0) {
77
throw err;
88
}
99

10-
if (context !== undefined) {
10+
if (context !== undefined && context !== null) {
1111
state.context = context;
1212
}
1313

14-
if (event !== undefined) {
14+
if (event !== undefined && event !== null) {
1515
state.event = event;
1616
}
1717

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alpha-lambda/handler",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Middleware pipeline for AWS Lambda handlers",
55
"repository": {
66
"type": "git",

test/lambda-handler-tests.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,40 @@ describe('handler', function() {
212212
});
213213
});
214214

215+
it('middleware does not override context and event when their values are null', function() {
216+
const spy = sinon.spy();
217+
218+
const fixture = lambdaHandler()
219+
.use(function(event, context, next) {
220+
return next(null, null, null);
221+
})
222+
.use(spy);
223+
224+
return fixture(testEvent, testContext)
225+
.then(() => {
226+
expect(spy.calledOnce).to.be.true;
227+
expect(spy.firstCall.args[0]).to.equal(testEvent);
228+
expect(spy.firstCall.args[1]).to.equal(testContext);
229+
});
230+
});
231+
232+
it('middleware does not override context and event when their values are undefined', function() {
233+
const spy = sinon.spy();
234+
235+
const fixture = lambdaHandler()
236+
.use(function(event, context, next) {
237+
return next(null, undefined, undefined);
238+
})
239+
.use(spy);
240+
241+
return fixture(testEvent, testContext)
242+
.then(() => {
243+
expect(spy.calledOnce).to.be.true;
244+
expect(spy.firstCall.args[0]).to.equal(testEvent);
245+
expect(spy.firstCall.args[1]).to.equal(testContext);
246+
});
247+
});
248+
215249
it('middleware can override result after await next()', function() {
216250
const stub = sinon.stub().returns('foo');
217251
const fixture = lambdaHandler()

0 commit comments

Comments
 (0)