I converted my cdk infrastructure code from version 1 to version 2. It was a successful conversion.
However, some of the test cases are now being failed. I haven’t touched any other code except changing references from version to version 2.
Possible causes :- The infrastructure uses apigatewayv2, apigatewayv2-integrations, apigatewayv2-authorizers ( alpha version of these packages)
Since i have not written code, i cannot help you with development code.
However i can provide the code where test cases are being failed.
Package for lambda is being used as @types/aws-lambda https://www.npmjs.com/package/@types/aws-lambda
import { BookDetailUseCaseInput } from '@use-cases/suken-account/detail-book'
import { IsString, Length, Matches, MinLength } from 'class-validator'
import { APIGatewayProxyEvent } from 'aws-lambda'
readonly bookId: string
@IsString({
message: 'wdawdawd。',
})
@MinLength(1, {
message: 'wdawd。',
})
readonly token: string
@IsString({
message: 'wdawd。',
})
@MinLength(1, {
message: 'dwdada',
})
readonly appVersion: string
constructor(event: APIGatewayProxyEvent) {
this.bookId = event.pathParameters!.book_id
this.token = event.headers.authorization?.split('Bearer')[1]?.trimLeft()
this.appVersion = event.headers['app-viewer-version']
}
error message during test run
35 this.token = event.headers.authorization?.split('Bearer')[1]?.trimLeft()
~~~~~~~~~~
src/modules/validators/wdwdwd-account/wdwdwdwd-request.ts:36:5 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
36 this.appVersion = event.headers['app-viewer-version']
I think APIGatewayProxyEvent
is sending values in different format in cdk version 2
2
Answers
The libraries were updated, and henceforth libraries were expecting different format syntax. I solved it by pinning down the library version
try this: