Skip to content

Commit

Permalink
fix prod edge-api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbalfour committed Mar 26, 2024
1 parent d676d3a commit 4ffc5fb
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions packages/constructs/edge-api/tests/construct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
RedirectionEndpoint,
ProxyEndpoint,
EdgeAPILambda,
RequestMiddleware,
} from '../src'
import { Certificate } from 'aws-cdk-lib/aws-certificatemanager'
import { Bucket } from 'aws-cdk-lib/aws-s3'
Expand Down Expand Up @@ -614,20 +615,22 @@ describe('edge-api', () => {
pathPattern: '/google',
destination,
customMiddlewares: [
// @ts-expect-error
(req, mapping) => {
if (req.uri === '/authorize' || req.uri === '/login') {
if (typeof mapping !== 'string') {
const ip = `identity_provider=${mapping.idpProviderName}`
if (req.querystring.length) {
req.querystring = `${ip}&${req.querystring}`
} else {
req.querystring = ip
new RequestMiddleware(
// @ts-expect-error
(req, mapping) => {
if (req.uri === '/authorize' || req.uri === '/login') {
if (typeof mapping !== 'string') {
const ip = `identity_provider=${mapping.idpProviderName}`
if (req.querystring.length) {
req.querystring = `${ip}&${req.querystring}`
} else {
req.querystring = ip
}
}
req.uri = '/oauth2/authorize'
}
req.uri = '/oauth2/authorize'
}
},
},
),
],
}),
)
Expand Down Expand Up @@ -663,12 +666,13 @@ describe('edge-api', () => {
},
})
const lambdas = result.findResources('AWS::Lambda::Function')
const code = Object.values(lambdas)
const codes = Object.values(lambdas)
.filter((lambda) => {
return !!lambda.Properties.Code.ZipFile
})
.map((lambda) => lambda.Properties.Code.ZipFile)
.find((code) => code.includes('identity_provider=${mapping.idpProviderName}'))

const code = codes.find((code) => code.includes('identity_provider=${mapping.idpProviderName}'))

const lambdaResult = await testGeneratedLambda(code, {
Records: [
Expand Down

0 comments on commit 4ffc5fb

Please sign in to comment.