|
|
@ -64,6 +64,9 @@ describe('serve', () => { |
|
|
|
id: 'testFuncId', |
|
|
|
handlerFunc: testHandlerFunc, |
|
|
|
}; |
|
|
|
const testHttpEvent = { |
|
|
|
integration: 'lambda' |
|
|
|
} |
|
|
|
const testReq = { |
|
|
|
method: 'testmethod', |
|
|
|
headers: 'testheaders', |
|
|
@ -76,7 +79,7 @@ describe('serve', () => { |
|
|
|
}; |
|
|
|
testRes.status = sinon.stub().returns(testRes); |
|
|
|
module.getContext = sinon.stub().returns('testContext'); |
|
|
|
const handler = module._handlerBase(testFuncConf); |
|
|
|
const handler = module._handlerBase(testFuncConf, testHttpEvent); |
|
|
|
handler(testReq, testRes); |
|
|
|
expect(testRes.status).to.have.been.calledWith(200); |
|
|
|
expect(testRes.send).to.have.been.calledWith(testHandlerResp); |
|
|
@ -111,6 +114,44 @@ describe('serve', () => { |
|
|
|
expect(testRes.status).to.have.been.calledWith(500); |
|
|
|
expect(testRes.send).to.have.been.calledWith(testHandlerErr); |
|
|
|
}); |
|
|
|
|
|
|
|
it('handles lambda-proxy integration for request and response', () => { |
|
|
|
const testHandlerResp = { statusCode: 200, body: 'testHandlerResp' }; |
|
|
|
const testHandlerFunc = sinon.spy((ev, ct, cb) => { |
|
|
|
cb(null, testHandlerResp); |
|
|
|
}); |
|
|
|
const testFuncConf = { |
|
|
|
id: 'testFuncId', |
|
|
|
handlerFunc: testHandlerFunc, |
|
|
|
}; |
|
|
|
const testHttpEvent = {} |
|
|
|
const testReq = { |
|
|
|
method: 'testmethod', |
|
|
|
headers: 'testheaders', |
|
|
|
body: 'testbody', |
|
|
|
params: 'testparams', |
|
|
|
query: 'testquery', |
|
|
|
}; |
|
|
|
const testRes = { |
|
|
|
send: sinon.spy(), |
|
|
|
}; |
|
|
|
testRes.status = sinon.stub().returns(testRes); |
|
|
|
module.getContext = sinon.stub().returns('testContext'); |
|
|
|
const handler = module._handlerBase(testFuncConf, testHttpEvent); |
|
|
|
handler(testReq, testRes); |
|
|
|
expect(testRes.status).to.have.been.calledWith(testHandlerResp.statusCode); |
|
|
|
expect(testRes.send).to.have.been.calledWith(testHandlerResp.body); |
|
|
|
expect(testHandlerFunc).to.have.been.calledWith( |
|
|
|
{ |
|
|
|
body: 'testbody', |
|
|
|
headers: 'testheaders', |
|
|
|
method: 'testmethod', |
|
|
|
path: 'testparams', |
|
|
|
queryStringParameters: 'testquery', |
|
|
|
}, |
|
|
|
'testContext' |
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('_optionsHandler', () => { |
|
|
|