Conversation
Add comprehensive test suites for CDK infrastructure components including API Gateway, WebSocket, Cognito, CloudFront, and Lambda resources. Tests verify resource creation, configurations, and IAM permissions.
|
Resolves #6 |
|
To provide feedback, navigate to the Files changed tab and leave comments on the proposed code changes. Choose Start review for each comment, and then choose Request changes, and I'll propose revised changes. |
|
⏳ I'm reviewing this pull request for security vulnerabilities and code quality issues. I'll provide an update when I'm done |
| import { LambdaResources } from '../lib/lambda'; | ||
| import { UserPool } from 'aws-cdk-lib/aws-cognito'; | ||
|
|
||
| describe('LambdaResources', () => { |
There was a problem hiding this comment.
Description: The test cases do not include error handling scenarios or negative test cases. Consider adding test cases for error scenarios, such as invalid input or resource creation failures.
Severity: Medium
There was a problem hiding this comment.
Sorry, I'm not able to suggest a fix for this review finding.
Request ID : 7af276c1-979a-488f-b9d2-78675fa5b0c3
|
✅ I finished the code review, and left comments with the issues I found. I will now generate code fix suggestions. |
| template = Template.fromStack(stack); | ||
| }); | ||
|
|
||
| test('Cognito User Pool Created', () => { |
There was a problem hiding this comment.
Description: The test file lacks organization for different resource types, making it harder to maintain as the stack grows. Consider grouping related tests into describe blocks for each major resource type (e.g., Cognito, Lambda, API Gateway) to improve organization and readability.
Severity: Low
There was a problem hiding this comment.
The fix addresses the comment by reorganizing the test cases into describe blocks for different resource types (Cognito, Lambda, and API Gateway). This improves the structure and readability of the test file, making it easier to maintain as the stack grows. The fix groups related tests together, providing a clearer overview of the resources being tested in the SimpleChatbotStack.
| test('Cognito User Pool Created', () => { | |
| template = Template.fromStack(stack); | |
| }); | |
| describe('Cognito Resources', () => { | |
| test('Cognito User Pool Created', () => { | |
| template.resourceCountIs('AWS::Cognito::UserPool', 1); | |
| template.hasResourceProperties('AWS::Cognito::UserPool', { | |
| SelfSignUpEnabled: true, | |
| AccountRecoveryPolicy: { | |
| RecoveryMechanisms: [ | |
| { | |
| Name: 'verified_email', | |
| Priority: 1 | |
| } | |
| ] | |
| }, | |
| MfaConfiguration: 'OPTIONAL', | |
| UsernameAttributes: ['email'] | |
| }); | |
| }); | |
| test('Cognito Identity Pool Created', () => { | |
| template.resourceCountIs('AWS::Cognito::IdentityPool', 1); | |
| template.hasResourceProperties('AWS::Cognito::IdentityPool', { | |
| AllowUnauthenticatedIdentities: false | |
| }); | |
| }); | |
| }); | |
| describe('Lambda Resources', () => { | |
| test('Lambda Functions Created', () => { | |
| // Check for the chatBot Lambda function | |
| template.hasResourceProperties('AWS::Lambda::Function', { | |
| Handler: 'index.handler', | |
| Runtime: 'nodejs20.x', | |
| Architectures: ['arm64'], | |
| Timeout: 300 | |
| }); | |
| }); | |
| }); | |
| describe('API Gateway Resources', () => { | |
| test('API Gateway Created', () => { | |
| template.resourceCountIs('AWS::ApiGateway::RestApi', 1); | |
| template.hasResourceProperties('AWS::ApiGateway::RestApi', { | |
| Name: 'chatBot1API' | |
| }); | |
| }); | |
| test('WebSocket API Created', () => { | |
| template.resourceCountIs('AWS::ApiGatewayV2::Api', 1); | |
| template.hasResourceProperties('AWS::ApiGatewayV2::Api', { | |
| ProtocolType: 'WEBSOCKET' | |
| }); | |
| }); | |
| }); |
jc1518
left a comment
There was a problem hiding this comment.
The CDK tests failed when I tested them on my laptop. Can you test and verify?
Test Suites: 6 failed, 6 total
Tests: 18 failed, 10 passed, 28 total
Snapshots: 0 total
Time: 240.023 s
This pull request introduces comprehensive test coverage for the CDK infrastructure components of the application. It adds several new test files (api.test.ts, websocket.test.ts, cognito.test.ts, lambda.test.ts, cloudfront.test.ts) that verify the proper configuration and creation of AWS resources including:
The tests ensure that infrastructure components are properly configured with the correct properties, policies, and relationships between resources. This addition improves the reliability and maintainability of the infrastructure code by validating the expected AWS resource configurations.