-
Notifications
You must be signed in to change notification settings - Fork 4
/
mockContext.js
56 lines (55 loc) · 1.68 KB
/
mockContext.js
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
55
56
'use strict';
/**
* Function that returns a mock context object for testing AWS Lambda functions
*
* @param {object} - options: object with context properties
* @param {function} - callback function to be called with the value passed into any of the context methods.
* - the callback should contain the test assertions.
*
**/
module.exports = function (options, cb) {
return {
succeed: function (result) {
if (result === undefined) {
return cb(null);
} else {
if (typeof result !== 'string'){
return cb(JSON.stringify(result));
} else {
return cb(result);
}
}
},
fail: function (error) {
if (error === undefined) {
return cb(null);
} else {
return cb(error);
}
},
done: function (err, result) {
if (err) {
return this.fail(err);
} else {
return this.succeed(result);
}
},
getRemainingTimeInMillis: function() {
if (typeof this.timeInMillis !== 'number') {
return 0;
} else {
return this.timeInMillis;
}
},
functionName: options.functionName || "",
functionVersion: options.functionVersion || "",
invokedFunctionArn: options.invokedFunctionArn || "",
memoryLimitInMB: options.memoryLimitInMB || "",
awsRequestId: options.awsRequestId || "",
logGroupName: options.logGroupName || "",
logStreamName: options.logStreamName || "",
identity: options.identity || {},
clientContext: options.clientContext || {},
timeInMillis: options.timeInMillis || 0
};
};