From ca8c51bb48f5b6f4a94070e6a2a147e5d2368df3 Mon Sep 17 00:00:00 2001 From: Jim Wild Date: Tue, 3 Sep 2024 10:49:13 +0100 Subject: [PATCH] Fix: [AEA-4159] - Resolve sonar issues (#449) ## Summary - Routine Change ### Details Just going down the sonar issues, and resolving them. --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- SAMtemplates/main_template.yaml | 2 +- SAMtemplates/sandbox_template.yaml | 4 ++-- packages/sandbox/tests/test-handler.test.ts | 8 ++++++-- .../statusLambda/tests/test-handler.test.ts | 17 ++++++++--------- scripts/calculate_version.py | 3 ++- sonar-project.properties | 11 ++++++++++- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/SAMtemplates/main_template.yaml b/SAMtemplates/main_template.yaml index 718c6eed..54903cb3 100644 --- a/SAMtemplates/main_template.yaml +++ b/SAMtemplates/main_template.yaml @@ -108,7 +108,7 @@ Resources: AccessToSpine: "true" LogRetentionDays: !Ref LogRetentionDays StatusLambda: - Type: AWS::Serverless::Function + Type: AWS::Serverless::Function # NOSONAR - The scan complains that this has no log group, but it's defined in the lambda resources above. Properties: FunctionName: !Sub "${AWS::StackName}-statusLambda" CodeUri: ../packages diff --git a/SAMtemplates/sandbox_template.yaml b/SAMtemplates/sandbox_template.yaml index 2e34f2f2..84ca0518 100644 --- a/SAMtemplates/sandbox_template.yaml +++ b/SAMtemplates/sandbox_template.yaml @@ -92,7 +92,7 @@ Resources: LambdaName: !Sub "${AWS::StackName}-Sandbox" LogRetentionDays: !Ref LogRetentionDays Sandbox: - Type: AWS::Serverless::Function + Type: AWS::Serverless::Function # NOSONAR - The scan complains that this has no log group, but it's defined in the lambda resources above. Properties: FunctionName: !Sub "${AWS::StackName}-Sandbox" CodeUri: ../packages @@ -134,7 +134,7 @@ Resources: LambdaName: !Sub "${AWS::StackName}-statusLambda" LogRetentionDays: !Ref LogRetentionDays StatusLambda: - Type: AWS::Serverless::Function + Type: AWS::Serverless::Function # NOSONAR - The scan complains that this has no log group, but it's defined in the lambda resources above. Properties: FunctionName: !Sub "${AWS::StackName}-statusLambda" CodeUri: ../packages diff --git a/packages/sandbox/tests/test-handler.test.ts b/packages/sandbox/tests/test-handler.test.ts index d14f43e3..27646d1d 100644 --- a/packages/sandbox/tests/test-handler.test.ts +++ b/packages/sandbox/tests/test-handler.test.ts @@ -1,9 +1,13 @@ import {APIGatewayProxyEvent, APIGatewayProxyResult} from "aws-lambda" import {handler} from "../src/sandbox" import {expect, describe, it} from "@jest/globals" -import {helloworldContext} from "@clinicaltracker_common/testing" import successData from "../examples/GetMyPrescriptions/Bundle/success.json" -import {mockAPIGatewayProxyEvent, test_append_trace_ids, test_mime_type} from "@clinicaltracker_common/testing" +import { + mockAPIGatewayProxyEvent, + test_append_trace_ids, + test_mime_type, + helloworldContext +} from "@clinicaltracker_common/testing" const dummyContext = helloworldContext const mockEvent: APIGatewayProxyEvent = mockAPIGatewayProxyEvent diff --git a/packages/statusLambda/tests/test-handler.test.ts b/packages/statusLambda/tests/test-handler.test.ts index 8b3cdd5b..9bb4c248 100644 --- a/packages/statusLambda/tests/test-handler.test.ts +++ b/packages/statusLambda/tests/test-handler.test.ts @@ -6,11 +6,10 @@ import { describe, it } from "@jest/globals" -import {helloworldContext} from "@clinicaltracker_common/testing" import {Logger} from "@aws-lambda-powertools/logger" import MockAdapter from "axios-mock-adapter" import axios from "axios" -import {mockAPIGatewayProxyEvent} from "@clinicaltracker_common/testing" +import {mockAPIGatewayProxyEvent, helloworldContext} from "@clinicaltracker_common/testing" const mock = new MockAdapter(axios) @@ -30,7 +29,7 @@ describe("Unit test for status check", function () { const result: APIGatewayProxyResult = (await handler( mockAPIGatewayProxyEvent, dummyContext - )) as APIGatewayProxyResult + )) expect(result.statusCode).toEqual(200) expect(JSON.parse(result.body)).toMatchObject({ @@ -45,7 +44,7 @@ describe("Unit test for status check", function () { const result: APIGatewayProxyResult = (await handler( mockAPIGatewayProxyEvent, dummyContext - )) as APIGatewayProxyResult + )) expect(result.statusCode).toEqual(200) expect(JSON.parse(result.body)).toMatchObject({ @@ -74,7 +73,7 @@ describe("Unit test for status check", function () { const result: APIGatewayProxyResult = (await handler( mockAPIGatewayProxyEvent, dummyContext - )) as APIGatewayProxyResult + )) const headers = result.headers @@ -103,7 +102,7 @@ describe("Unit test for status check", function () { const result: APIGatewayProxyResult = (await handler( mockAPIGatewayProxyEvent, dummyContext - )) as APIGatewayProxyResult + )) expect(result.statusCode).toEqual(200) const result_body = JSON.parse(result.body) @@ -120,7 +119,7 @@ describe("Unit test for status check", function () { const result: APIGatewayProxyResult = (await handler( mockAPIGatewayProxyEvent, dummyContext - )) as APIGatewayProxyResult + )) expect(result.statusCode).toEqual(200) const result_body = JSON.parse(result.body) @@ -137,7 +136,7 @@ describe("Unit test for status check", function () { const result: APIGatewayProxyResult = (await handler( mockAPIGatewayProxyEvent, dummyContext - )) as APIGatewayProxyResult + )) expect(result.statusCode).toEqual(200) const result_body = JSON.parse(result.body) @@ -154,7 +153,7 @@ describe("Unit test for status check", function () { const result: APIGatewayProxyResult = (await handler( mockAPIGatewayProxyEvent, dummyContext - )) as APIGatewayProxyResult + )) expect(result.statusCode).toEqual(200) const result_body = JSON.parse(result.body) diff --git a/scripts/calculate_version.py b/scripts/calculate_version.py index 56c8dc7a..4dd91b25 100644 --- a/scripts/calculate_version.py +++ b/scripts/calculate_version.py @@ -71,7 +71,8 @@ def calculate_version(base_major=1, base_minor=0, base_revision=0, base_pre="alp """Calculates a semver based on commit history and special flags in commit messages""" major = base_major minor = base_minor - patch = base_revision + # Unused variable + # patch = base_revision pre = base_pre commits = get_versionable_commits(REPO) diff --git a/sonar-project.properties b/sonar-project.properties index 77c94ec2..00fb75a2 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,10 +2,19 @@ sonar.organization=nhsdigital sonar.projectKey=NHSDigital_electronic-prescription-service-clinical-prescription-tracker sonar.host.url=https://sonarcloud.io -sonar.coverage.exclusions=**/*.test.*, \ +sonar.coverage.exclusions=**/*.test.*,\ + **/tests/*,\ + **/jest.config.ts,scripts/*, \ + packages/common/testing/*, \ + eslint.config.mjs + +sonar.cpd.exclusions=**/*.test.*,\ + **/tests/*,\ **/jest.config.ts,scripts/*, \ packages/common/testing/*, \ eslint.config.mjs sonar.javascript.lcov.reportPaths=packages/sandbox/coverage/lcov.info, \ packages/statusLambda/coverage/lcov.info + +sonar.python.version=3.10