Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stage variables integration #976

Merged
merged 2 commits into from May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/events/http/HttpServer.js
Expand Up @@ -472,10 +472,14 @@ export default class HttpServer {
event = request.payload || {}
}
} else if (integration === 'AWS_PROXY') {
const stageVariables = this.#serverless.service.custom
? this.#serverless.service.custom.stageVariables
: null
const lambdaProxyIntegrationEvent = new LambdaProxyIntegrationEvent(
request,
this.#serverless.service.provider.stage,
requestPath,
stageVariables,
)

event = lambdaProxyIntegrationEvent.create()
Expand Down
6 changes: 4 additions & 2 deletions src/events/http/lambda-events/LambdaProxyIntegrationEvent.js
Expand Up @@ -21,11 +21,13 @@ export default class LambdaProxyIntegrationEvent {
#path = null
#request = null
#stage = null
#stageVariables = null

constructor(request, stage, path) {
constructor(request, stage, path, stageVariables) {
this.#path = path
this.#request = request
this.#stage = stage
this.#stageVariables = stageVariables
}

create() {
Expand Down Expand Up @@ -185,7 +187,7 @@ export default class LambdaProxyIntegrationEvent {
stage: this.#stage,
},
resource: this.#path,
stageVariables: null,
stageVariables: this.#stageVariables,
}
}
}
22 changes: 22 additions & 0 deletions tests/old-unit/LambdaProxyIntegrationEvent.test.js
Expand Up @@ -676,4 +676,26 @@ describe('LambdaProxyIntegrationEvent', () => {
).toEqual('customCognitoAuthenticationProvider')
})
})

describe('with stage variables', () => {
test('should assign the value to stageVariables', () => {
const requestBuilder = new RequestBuilder('POST', '/fn1')
requestBuilder.addBody({ key: 'value' })
requestBuilder.addHeader('content-type', 'custom/test')
const request = requestBuilder.toObject()
const path = 'path'
const stageVariables = 'stageVariables'

const lambdaProxyIntegrationEvent = new LambdaProxyIntegrationEvent(
request,
stage,
path,
stageVariables,
).create()

expect(lambdaProxyIntegrationEvent.stageVariables).toEqual(
'stageVariables',
)
})
})
})