-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
80 lines (71 loc) · 2.01 KB
/
test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"use strict";
const assert = require("assert");
const httpMocks = require("express-mocks-http");
const index = require("./dist/index");
const awsConfig = index.awsConfig;
const apigatewayEventParser = index.apigatewayEventParser;
const printLog = index.printLog;
const printError = index.printError;
let request, response;
function prepare(logStyle = null) {
request = httpMocks.createRequest();
response = httpMocks.createResponse();
process.env = {"A": 1, "B": 2};
if (logStyle)
process.env["PRINT_LOG"] = logStyle;
request.headers = {};
request.headers["x-apigateway-event"] = JSON.stringify({stageVariables: {C: 3}});
}
describe("aws-serverless-config", function() {
it('aws-config', function() {
prepare();
function next() {
let result = request["aws-config"].A + request["aws-config"].B + request["aws-config"].C;
assert.equal(result, 6);
}
awsConfig(request, response, next);
});
it('apigateway-event-parser', function() {
prepare();
function next() {
assert.equal(request.headers["x-apigateway-event"].stageVariables.C, 3);
}
apigatewayEventParser(request, response, next);
});
it('print-log : none', function() {
prepare();
function next() {
}
awsConfig(request, response, next);
printLog(request, response, next);
});
it('print-log : event', function() {
prepare("EVENT");
function next() {
}
awsConfig(request, response, next);
printLog(request, response, next);
});
it('print-log : request', function() {
prepare("REQUEST");
function next() {
}
awsConfig(request, response, next);
printLog(request, response, next);
});
it('print-log : simple', function() {
prepare("SIMPLE");
function next() {
}
awsConfig(request, response, next);
printLog(request, response, next);
});
it('print-error', function() {
prepare();
function next() {
}
const error = new Error("TEST");
error.statusCode = 500;
printError(error, request, response, next);
});
});