Skip to content

Commit

Permalink
Merge pull request #976 from efrain17/master
Browse files Browse the repository at this point in the history
Stage variables integration
  • Loading branch information
dherault committed May 20, 2020
2 parents ac96241 + 5a5b653 commit d7db28d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
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',
)
})
})
})

0 comments on commit d7db28d

Please sign in to comment.