Skip to content

Commit 7a69e03

Browse files
committed
added a test for the header handling
1 parent 3fe7069 commit 7a69e03

1 file changed

Lines changed: 43 additions & 22 deletions

File tree

__tests__/index.js

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,34 +84,55 @@ test('getSocketPath', () => {
8484
expect(socketPath).toEqual('/tmp/server0.sock')
8585
})
8686

87-
describe('forwardResponseToApiGateway: content-type encoding', () => {
88-
const PassThrough = require('stream').PassThrough
89-
90-
class MockResponse extends PassThrough {
91-
constructor(statusCode, headers, body) {
92-
super()
93-
this.statusCode = statusCode
94-
this.headers = headers || {}
95-
this.write(body)
96-
this.end()
97-
}
87+
const PassThrough = require('stream').PassThrough
88+
89+
class MockResponse extends PassThrough {
90+
constructor(statusCode, headers, body) {
91+
super()
92+
this.statusCode = statusCode
93+
this.headers = headers || {}
94+
this.write(body)
95+
this.end()
9896
}
97+
}
9998

100-
class MockServer {
101-
constructor(binaryTypes) {
102-
this._binaryTypes = binaryTypes || []
103-
}
99+
class MockServer {
100+
constructor(binaryTypes) {
101+
this._binaryTypes = binaryTypes || []
104102
}
103+
}
105104

106-
class MockContext {
107-
constructor(resolve) {
108-
this.resolve = resolve
109-
}
110-
succeed(successResponse) {
111-
this.resolve(successResponse)
112-
}
105+
class MockContext {
106+
constructor(resolve) {
107+
this.resolve = resolve
108+
}
109+
succeed(successResponse) {
110+
this.resolve(successResponse)
113111
}
112+
}
114113

114+
describe('forwardResponseToApiGateway: header handling', () => {
115+
test('multiple headers with the same name get transformed', () => {
116+
const server = new MockServer()
117+
const headers = {'foo': ['bar', 'baz']}
118+
const body = 'hello world'
119+
const response = new MockResponse(200, headers, body)
120+
return new Promise(
121+
(resolve, reject) => {
122+
const context = new MockContext(resolve)
123+
awsServerlessExpress.forwardResponseToApiGateway(
124+
server, response, context)
125+
}
126+
).then(successResponse => expect(successResponse).toEqual({
127+
statusCode: 200,
128+
body: body,
129+
headers: { Foo: 'bar', fOo: 'baz' },
130+
isBase64Encoded: false
131+
}))
132+
})
133+
})
134+
135+
describe('forwardResponseToApiGateway: content-type encoding', () => {
115136
test('content-type header missing', () => {
116137
const server = new MockServer()
117138
const headers = {'foo': 'bar'}

0 commit comments

Comments
 (0)