-
Notifications
You must be signed in to change notification settings - Fork 5
CCM-13787: create supplier mock for testing #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Vlasis-Perdikidis
wants to merge
16
commits into
main
Choose a base branch
from
feature/CCM-13787-createSupplierMockForTesting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
940bbdf
add supplier mock dummy lambda function
Vlasis-Perdikidis 72522b1
correct the name of the supplier_mock lambda
Vlasis-Perdikidis b709f6a
remove comment from tf file
Vlasis-Perdikidis 241808b
get dummy test to pass
Vlasis-Perdikidis 52da831
disable vale spelling from README
Vlasis-Perdikidis 577b851
correct lambda handler name
Vlasis-Perdikidis c3bde6b
restore changes
Vlasis-Perdikidis c22f094
call patch letter and add variables to parameter store
Vlasis-Perdikidis 5f4ea2a
merge main
Vlasis-Perdikidis c2c9675
resolve final conflicts
Vlasis-Perdikidis 98d5fb2
refresh package-lock file
Vlasis-Perdikidis e7a0433
correct lint and typecheck errors
Vlasis-Perdikidis b048bbf
resolve final conflicts
Vlasis-Perdikidis 92d4c60
re-add @pact-foundation/pact library in run-pact-tests.sh script
Vlasis-Perdikidis 510c828
install amd64 version of @pact-foundation if missing
Vlasis-Perdikidis 3199ce5
add ssm:GetParameter permission for supplierId parameter in supplier …
Vlasis-Perdikidis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| name: Acceptance tests - component | ||
| description: "Run component acceptance tests for this repo" | ||
|
|
||
| inputs: | ||
| testType: | ||
| description: Type of test to run | ||
| required: true | ||
|
|
||
| targetEnvironment: | ||
| description: Name of the environment under test | ||
| required: true | ||
|
|
||
| targetComponent: | ||
| description: Name of the component under test | ||
| required: true | ||
|
|
||
| runs: | ||
| using: "composite" | ||
|
|
||
| steps: | ||
|
|
||
| - name: Repo setup | ||
| uses: ./.github/actions/node-install | ||
| with: | ||
| GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }} | ||
|
|
||
| - name: Fetch terraform output | ||
| uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 | ||
| with: | ||
| name: terraform-output-${{ inputs.targetComponent }} | ||
|
|
||
| - name: Get Node version | ||
| id: nodejs_version | ||
| shell: bash | ||
| run: | | ||
| echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Run test - ${{ inputs.testType }} | ||
| shell: bash | ||
| env: | ||
| TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }} | ||
| run: | | ||
| make test-${{ inputs.testType }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
infrastructure/terraform/components/api/module_lambda_supplier_mock.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| module "supplier_mock" { | ||
| source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip" | ||
|
|
||
| function_name = "supplier_mock" | ||
| description = "Mock the behaviour of a supplier" | ||
|
|
||
| aws_account_id = var.aws_account_id | ||
| component = var.component | ||
| environment = var.environment | ||
| project = var.project | ||
| region = var.region | ||
| group = var.group | ||
|
|
||
| log_retention_in_days = var.log_retention_in_days | ||
| kms_key_arn = module.kms.key_arn | ||
|
|
||
| iam_policy_document = { | ||
| body = data.aws_iam_policy_document.supplier_mock_lambda.json | ||
| } | ||
|
|
||
| function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"] | ||
| function_code_base_path = local.aws_lambda_functions_dir_path | ||
| function_code_dir = "supplier-mock/dist" | ||
| function_include_common = true | ||
| handler_function_name = "supplierMockHandler" | ||
| runtime = "nodejs22.x" | ||
| memory = 512 | ||
| timeout = 29 | ||
| log_level = var.log_level | ||
|
|
||
| force_lambda_code_deploy = var.force_lambda_code_deploy | ||
| enable_lambda_insights = false | ||
|
|
||
| log_destination_arn = local.destination_arn | ||
| log_subscription_role_arn = local.acct.log_subscription_role_arn | ||
|
|
||
| lambda_env_vars = merge(local.common_lambda_env_vars, { | ||
| ENVIRONMENT = var.environment | ||
| GET_LETTERS_FUNCTION_NAME = module.get_letters.function_name | ||
| PATCH_LETTER_FUNCTION_NAME = module.patch_letter.function_name | ||
| SUPPLIER_MOCK_GET_LETTERS_LIMIT_PARAM_NAME = aws_ssm_parameter.supplier_mock_get_letters_limit.name | ||
| SUPPLIER_MOCK_SUPPLIER_ID = aws_ssm_parameter.supplier_mock_supplier_id.name | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_ssm_parameter" "supplier_mock_get_letters_limit" { | ||
| name = format("/nhs/supapi/supplier-mock/%s/get-letters-limit", var.environment) | ||
| description = "Default get_letters limit for supplier mock lambda" | ||
| type = "String" | ||
| value = "100" | ||
|
|
||
| lifecycle { | ||
| ignore_changes = [value] | ||
| } | ||
| } | ||
|
|
||
| resource "aws_ssm_parameter" "supplier_mock_supplier_id" { | ||
| name = format("/nhs/supapi/supplier-mock/%s/supplier-id", var.environment) | ||
| description = "Supplier ID to be used by the supplier mock lambda" | ||
| type = "String" | ||
| value = "TestSupplier1" | ||
|
|
||
| lifecycle { | ||
| ignore_changes = [value] | ||
| } | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "supplier_mock_lambda" { | ||
| statement { | ||
| sid = "KMSPermissions" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "kms:Decrypt", | ||
| "kms:GenerateDataKey", | ||
| ] | ||
|
|
||
| resources = [ | ||
| module.kms.key_arn, ## Requires shared kms module | ||
| ] | ||
| } | ||
|
|
||
| statement { | ||
| sid = "AllowInvokeLambda" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "lambda:InvokeFunction", | ||
| ] | ||
|
|
||
| resources = [ | ||
| module.get_letters.function_arn, | ||
| module.patch_letter.function_arn | ||
| ] | ||
| } | ||
|
|
||
| statement { | ||
| sid = "AllowReadSupplierMockLimitParameter" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "ssm:GetParameter", | ||
| ] | ||
|
|
||
| resources = [ | ||
| aws_ssm_parameter.supplier_mock_get_letters_limit.arn, | ||
| aws_ssm_parameter.supplier_mock_supplier_id.arn | ||
| ] | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
infrastructure/terraform/components/api/scheduler_supplier_mock.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| data "aws_iam_policy_document" "supplier_mock_scheduler_trust_policy" { | ||
| statement { | ||
| sid = "AllowSchedulerAssumeRole" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "sts:AssumeRole", | ||
| ] | ||
|
|
||
| principals { | ||
| type = "Service" | ||
|
|
||
| identifiers = [ | ||
| "scheduler.amazonaws.com", | ||
| ] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "aws_iam_role" "supplier_mock_scheduler" { | ||
| name = "${local.csi}-supplier-mock-scheduler" | ||
| description = "Allows EventBridge Scheduler to invoke supplier mock lambda" | ||
| assume_role_policy = data.aws_iam_policy_document.supplier_mock_scheduler_trust_policy.json | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "supplier_mock_scheduler_invoke_policy" { | ||
| statement { | ||
| sid = "AllowInvokeSupplierMockLambda" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "lambda:InvokeFunction", | ||
| ] | ||
|
|
||
| resources = [ | ||
| module.supplier_mock.function_arn, | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| resource "aws_iam_policy" "supplier_mock_scheduler_invoke_policy" { | ||
| name = "${local.csi}-supplier-mock-scheduler-invoke" | ||
| policy = data.aws_iam_policy_document.supplier_mock_scheduler_invoke_policy.json | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy_attachment" "supplier_mock_scheduler_invoke_policy" { | ||
| role = aws_iam_role.supplier_mock_scheduler.name | ||
| policy_arn = aws_iam_policy.supplier_mock_scheduler_invoke_policy.arn | ||
| } | ||
|
|
||
| resource "aws_scheduler_schedule" "supplier_mock" { | ||
| name = "${local.csi}-supplier-mock" | ||
| description = "Scheduled trigger for supplier mock lambda" | ||
| state = var.enable_supplier_mock_scheduler ? "ENABLED" : "DISABLED" | ||
|
|
||
| flexible_time_window { | ||
| mode = "OFF" | ||
| } | ||
|
|
||
| schedule_expression = var.supplier_mock_schedule_expression | ||
|
|
||
| target { | ||
| arn = module.supplier_mock.function_arn | ||
| role_arn = aws_iam_role.supplier_mock_scheduler.arn | ||
| input = jsonencode({ | ||
| source = "eventbridge-scheduler" | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| coverage | ||
| node_modules | ||
| dist | ||
| .reports | ||
| .aws-sam |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| export const baseJestConfig = { | ||
| preset: "ts-jest", | ||
| extensionsToTreatAsEsm: [".ts"], | ||
| transform: { | ||
| "^.+\\.ts$": [ | ||
| "ts-jest", | ||
| { | ||
| useESM: true, | ||
| }, | ||
| ], | ||
| }, | ||
| transformIgnorePatterns: [ | ||
| "node_modules/(?!(@nhsdigital/nhs-notify-event-schemas-supplier-config)/)", | ||
| ], | ||
|
|
||
| // Automatically clear mock calls, instances, contexts and results before every test | ||
| clearMocks: true, | ||
|
|
||
| // Indicates whether the coverage information should be collected while executing the test | ||
| collectCoverage: true, | ||
|
|
||
| // The directory where Jest should output its coverage files | ||
| coverageDirectory: "./.reports/unit/coverage", | ||
|
|
||
| // Indicates which provider should be used to instrument code for coverage | ||
| coverageProvider: "babel", | ||
|
|
||
| coverageThreshold: { | ||
| global: { | ||
| branches: 100, | ||
| functions: 100, | ||
| lines: 100, | ||
| statements: -10, | ||
| }, | ||
| }, | ||
|
|
||
| coveragePathIgnorePatterns: ["/__tests__/"], | ||
| testPathIgnorePatterns: [".build"], | ||
| testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"], | ||
|
|
||
| // Use this configuration option to add custom reporters to Jest | ||
| reporters: [ | ||
| "default", | ||
| [ | ||
| "jest-html-reporter", | ||
| { | ||
| pageTitle: "Test Report", | ||
| outputPath: "./.reports/unit/test-report.html", | ||
| includeFailureMsg: true, | ||
| }, | ||
| ], | ||
| ], | ||
|
|
||
| // The test environment that will be used for testing | ||
| testEnvironment: "jsdom", | ||
| }; | ||
|
|
||
| const utilsJestConfig = { | ||
| ...baseJestConfig, | ||
|
|
||
| testEnvironment: "node", | ||
|
|
||
| coveragePathIgnorePatterns: [ | ||
| ...(baseJestConfig.coveragePathIgnorePatterns ?? []), | ||
| "zod-validators.ts", | ||
| ], | ||
| }; | ||
|
|
||
| export default utilsJestConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "dependencies": { | ||
| "@aws-sdk/client-api-gateway": "^3.1030.0", | ||
| "@aws-sdk/client-lambda": "^3.1030.0", | ||
| "@aws-sdk/client-ssm": "^3.1054.0", | ||
| "@internal/helpers": "^0.1.0", | ||
| "aws-embedded-metrics": "^4.2.1", | ||
| "aws-lambda": "^1.0.7", | ||
| "pino": "^10.3.1", | ||
| "zod": "^4.3.6" | ||
| }, | ||
| "name": "nhs-notify-supplier-api-supplier-mock", | ||
| "private": true, | ||
| "scripts": { | ||
| "lambda-build": "rm -rf dist && npx esbuild --bundle --minify --sourcemap --target=es2020 --platform=node --loader:.node=file --entry-names=[name] --outdir=dist src/index.ts", | ||
| "lint": "eslint .", | ||
| "lint:fix": "eslint . --fix", | ||
| "test:unit": "jest", | ||
| "typecheck": "tsc --noEmit" | ||
| }, | ||
| "version": "0.0.1" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the scheduler get created for all branches or just
main?