Skip to content

Commit f295c9b

Browse files
committed
More tests
1 parent ede6f44 commit f295c9b

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

test/eventToRequestOptions.test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import eventToRequestOptions from '../src/eventToRequestOptions';
22

33
import eventRestApi from './fixtures/event-rest-api.json';
4+
import eventHttpApiV1 from './fixtures/event-http-api-1.0.json';
5+
import eventHttpApiV2 from './fixtures/event-http-api-2.0.json';
6+
import eventHttpApiLegacy from './fixtures/event-http-api.json';
47
import eventHealth from './fixtures/health-event.json';
58
import eventAlb from './fixtures/alb-event.json';
69
import evenMultiHeadertAlb from './fixtures/alb-multi-header-event.json';
@@ -38,6 +41,87 @@ describe('eventToRequestOptions', () => {
3841
})
3942
})
4043

44+
it('converts Api Gateway HTTP v1 event to RequestOptions object', () => {
45+
const reqOpts = eventToRequestOptions(eventHttpApiV1);
46+
expect(reqOpts).toEqual({
47+
"method": "GET",
48+
"path": "/inspect?param=ab%20cd",
49+
"remoteAddress": "9.9.9.9",
50+
"body": Buffer.alloc(0),
51+
"ssl": true,
52+
"headers": {
53+
"content-length": "0",
54+
"host": "apiid.execute-api.ap-southeast-2.amazonaws.com",
55+
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36",
56+
"x-amzn-trace-id": "Root=1-5eac36bd-7a4863e4e05a7ca67c0a68ae",
57+
"x-forwarded-for": "1.2.3.4, 4.5.6.7, 9.9.9.9",
58+
"x-forwarded-port": "443",
59+
"x-forwarded-proto": "https",
60+
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
61+
"accept-encoding": "gzip, deflate, br",
62+
"accept-language": "en-US,en;q=0.9,pl-PL;q=0.8,pl;q=0.7,ru;q=0.6",
63+
"sec-fetch-dest": "document",
64+
"sec-fetch-mode": "navigate",
65+
"sec-fetch-site": "none",
66+
"sec-fetch-user": "?1",
67+
"upgrade-insecure-requests": "1",
68+
"cookie": "cookie1=value1; cookie2=value2; cookie3=value3; hackyname=h3c%2Fky%3D%3Bva%7Blu%5De"
69+
},
70+
})
71+
})
72+
73+
it('converts Api Gateway HTTP v2 event to RequestOptions object', () => {
74+
const reqOpts = eventToRequestOptions(eventHttpApiV2);
75+
expect(reqOpts).toEqual({
76+
"method": "GET",
77+
"path": "/inspect?param=ab%20cd",
78+
"remoteAddress": "9.9.9.9",
79+
"body": Buffer.alloc(0),
80+
"ssl": true,
81+
"headers": {
82+
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
83+
"accept-encoding": "gzip, deflate, br",
84+
"accept-language": "en-US,en;q=0.9,pl-PL;q=0.8,pl;q=0.7,ru;q=0.6",
85+
"cache-control": "max-age=0",
86+
"content-length": "0",
87+
"cookie": "cookie1=value1; cookie2=value2; cookie3=value3; hackyname=h3c%2Fky%3D%3Bva%7Blu%5De",
88+
"host": "apiid.execute-api.ap-southeast-2.amazonaws.com",
89+
"sec-fetch-dest": "document",
90+
"sec-fetch-mode": "navigate",
91+
"sec-fetch-site": "none",
92+
"sec-fetch-user": "?1",
93+
"upgrade-insecure-requests": "1",
94+
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36",
95+
"x-amzn-trace-id": "Root=1-5eac37e3-8e447320ce745898566b3300",
96+
"x-forwarded-for": "1.2.3.4, 4.5.6.7, 9.9.9.9",
97+
"x-forwarded-port": "443",
98+
"x-forwarded-proto": "https"
99+
}
100+
})
101+
})
102+
103+
it('converts Api Gateway HTTP legacy event to RequestOptions object', () => {
104+
const reqOpts = eventToRequestOptions(eventHttpApiLegacy);
105+
expect(reqOpts).toEqual({
106+
"method": "GET",
107+
"path": "/inspect?param=ab%20cd",
108+
"remoteAddress": "9.9.9.9",
109+
"body": Buffer.alloc(0),
110+
"ssl": true,
111+
"headers": {
112+
"content-length": "0",
113+
"host": "apiid.execute-api.ap-southeast-2.amazonaws.com",
114+
"user-agent": "curl/7.54.0",
115+
"x-amzn-trace-id": "Root=1-5de881d0-2a206d74d6702f28f7e78eb0",
116+
"x-forwarded-for": "1.2.3.4, 4.5.6.7, 9.9.9.9",
117+
"x-forwarded-port": "443",
118+
"x-forwarded-proto": "https",
119+
"accept": "*/*",
120+
"cookie": "cookie1=value1; cookie2=value2; cookie3=value3; hackyname=h3c%2Fky%3D%3Bva%7Blu%5De"
121+
},
122+
})
123+
})
124+
41125
it('converts ALB single header value event to RequestOptions object', () => {
42126
const reqOpts = eventToRequestOptions(eventAlb);
43127
expect(reqOpts).toEqual({

0 commit comments

Comments
 (0)