After upgrading my CDK infrastructure code from version 1 to version 2, I encountered some failed test cases. The conversion itself was successful without any issues.
The only changes made were updating the references from version 1 to version 2, nothing else in the codebase was modified.
The potential reasons behind the failed tests could be the usage of apigatewayv2, apigatewayv2-integrations, apigatewayv2-authorizers (all alpha versions).
Since I did not write the original code, I am unable to assist with development-specific issues. However, I can share the code snippet where the tests are failing.
The lambda package being utilized is @types/aws-lambda available at 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: 'Validation error。',
})
@MinLength(1, {
message: 'Invalid length.',
})
readonly token: string
@IsString({
message: 'Validation error.',
})
@MinLength(1, {
message: 'Error: invalid data',
})
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 received during the test run:
35 this.token = event.headers.authorization?.split('Bearer')[1]?.trimLeft()
~~~~~~~~~~
src/modules/validators/error-account/error-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 suspect that APIGatewayProxyEvent
may be sending values in a different format within CDK version 2.