forked from jeremydaly/lambda-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.js
More file actions
54 lines (44 loc) · 1.74 KB
/
Copy pathcontext.js
File metadata and controls
54 lines (44 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
const expect = require('chai').expect // Assertion library
// Init API instance
const api = require('../index')({ version: 'v1.0' })
// NOTE: Set test to true
api._test = true;
let event = {
httpMethod: 'get',
path: '/test',
body: {},
multiValueHeaders: {
'Content-Type': ['application/json']
}
}
/******************************************************************************/
/*** DEFINE TEST ROUTES ***/
/******************************************************************************/
api.get('/', function(req,res) {
res.send({
id: req.id,
context: req.context
})
})
/******************************************************************************/
/*** BEGIN TESTS ***/
/******************************************************************************/
describe('Context Tests:', function() {
it('Parse ID and context object', async function() {
let _event = Object.assign({},event,{ path: '/'})
let result = await new Promise(r => api.run(_event,{
functionName: 'testFunction',
awsRequestId: '1234',
log_group_name: 'testLogGroup',
log_stream_name: 'testLogStream',
clientContext: {},
identity: { cognitoIdentityId: 321 }
},(e,res) => { r(res) }))
expect(result).to.deep.equal({
multiValueHeaders: { 'content-type': ['application/json'] },
statusCode: 200,
body: '{"id":"1234","context":{"functionName":"testFunction","awsRequestId":"1234","log_group_name":"testLogGroup","log_stream_name":"testLogStream","clientContext":{},"identity":{"cognitoIdentityId":321}}}',
isBase64Encoded: false })
}) // end it
}) // end ERROR HANDLING tests