aws-lambda-test-utils
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -7,5 +7,6 @@ 'use strict'; | ||
module.exports = { | ||
createS3Event: createS3Event, | ||
createS3Event: createS3Event, | ||
createDynamoDBEvent: createDynamoDBEvent, | ||
createSNSEvent: createSNSEvent, | ||
createSNSEvent: createSNSEvent, | ||
createAPIGatewayEvent: createAPIGatewayEvent | ||
} | ||
@@ -63,2 +64,19 @@ | ||
message: "default test message" | ||
}, | ||
"api-gateway": { | ||
path: "default/path", | ||
method: "GET", | ||
headers: { | ||
"default-header": 'default' | ||
}, | ||
queryStringParameters: { | ||
query: "default" | ||
}, | ||
pathParameters: { | ||
uuid: '1234' | ||
}, | ||
stageVariables: { | ||
ENV: "test" | ||
}, | ||
body: "default body" | ||
} | ||
@@ -79,3 +97,3 @@ }; | ||
options.message = typeof options.message === "string" ? options.message : JSON.stringify(options.message); | ||
return { | ||
@@ -154,1 +172,40 @@ "Records": [ | ||
} | ||
function createAPIGatewayEvent(options) { | ||
var options = setDefaults(options, "api-gateway"); | ||
return { | ||
"resource": "/assets", | ||
"path": options.path, | ||
"httpMethod": options.method, | ||
"headers": options.headers, | ||
"queryStringParameters": options.queryStringParameters, | ||
"pathParameters": options.pathParameters, | ||
"stageVariables": options.stageVariables, | ||
"requestContext": { | ||
"accountId": "1234", | ||
"resourceId": "snmm5d", | ||
"stage": "test-invoke-stage", | ||
"requestId": "test-invoke-request", | ||
"identity": { | ||
"cognitoIdentityPoolId": null, | ||
"accountId": "1234", | ||
"cognitoIdentityId": null, | ||
"caller": "1234", | ||
"apiKey": "test-invoke-api-key", | ||
"sourceIp": "test-invoke-source-ip", | ||
"accessKey": "1234", | ||
"cognitoAuthenticationType": null, | ||
"cognitoAuthenticationProvider": null, | ||
"userArn": "arn:aws:iam::1234:user/test_user", | ||
"userAgent": "Apache-HttpClient/4.5.x (Java/1.8.0)", | ||
"user": "1234" | ||
}, | ||
"resourcePath": options.path, | ||
"httpMethod": options.method, | ||
"apiId": "1234" | ||
}, | ||
"body": options.body, | ||
"isBase64Encoded": false | ||
} | ||
}; |
{ | ||
"name": "aws-lambda-test-utils", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Test your AWS Lambda Functions for reals!", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -128,4 +128,30 @@ # aws-lambda-test-utils | ||
``` | ||
#### `createAPIGatewayEvent(options)` | ||
```js | ||
var utils = require('aws-lambda-test-utils'); | ||
var APIGatewayEvent = utils.mockEventCreator.createAPIGatewayEvent(); | ||
// Default options (which can be overridden): | ||
{ | ||
path: "default/path", | ||
method: "GET", | ||
headers: { | ||
"default-header": 'default' | ||
}, | ||
queryStringParameters: { | ||
query: "default" | ||
}, | ||
pathParameters: { | ||
uuid: '1234' | ||
}, | ||
stageVariables: { | ||
ENV: "test" | ||
}, | ||
body: "default body" | ||
} | ||
``` | ||
## Documentation | ||
@@ -132,0 +158,0 @@ |
@@ -85,1 +85,22 @@ 'use strict'; | ||
}); | ||
test('mockEventCreator - createAPIGatewayEvent', function(t) { | ||
t.test('no options: returns an object with default api gateway values', function(st) { | ||
var APIGatewayEvent = mockEventCreator.createAPIGatewayEvent(); | ||
st.equals(APIGatewayEvent.httpMethod, "GET", "event method should be GET"); | ||
st.equals(APIGatewayEvent.body, "default body", "event body should be 'default body'"); | ||
st.end() | ||
}); | ||
t.test('options with body and stageVariables: returns an object with custom body and stageVariables', function(st) { | ||
var options = { | ||
stageVariables: { ENV: "DEV", API_URL: 'http://api.url'}, | ||
body: "i am a custom body" | ||
} | ||
var APIGatewayEvent = mockEventCreator.createAPIGatewayEvent(options); | ||
st.deepEquals(APIGatewayEvent.stageVariables, options.stageVariables, "event stageVariables should be custom stageVariables "); | ||
st.equals(APIGatewayEvent.body, options.body, "event body should be custom body"); | ||
st.end() | ||
}); | ||
t.end(); | ||
}); |
41579
466
215