|
| 1 | +import {App} from "aws-cdk-lib" |
| 2 | +import {Template} from "aws-cdk-lib/assertions" |
| 3 | +import {describe, it} from "vitest" |
| 4 | +import {PfPApiSandboxStack, PfPApiSandboxStackProps} from "../stacks/PfPApiSandboxStack" |
| 5 | +import {PfPApiStack, PfPApiStackProps} from "../stacks/PfPApiStack" |
| 6 | + |
| 7 | +function createStandardStackProps() { |
| 8 | + return { |
| 9 | + commitId: "test-commit", |
| 10 | + env: { |
| 11 | + region: "eu-west-2" |
| 12 | + }, |
| 13 | + environment: "test", |
| 14 | + isPullRequest: true, |
| 15 | + version: "0.0.0-test" |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +function createMainStackProps(): PfPApiStackProps { |
| 20 | + return { |
| 21 | + ...createStandardStackProps(), |
| 22 | + allowNhsNumberOverride: "false", |
| 23 | + csocApiGatewayDestination: "arn:aws:logs:eu-west-2:693466633220:destination:api_gateway_log_destination", |
| 24 | + enableAlerts: true, |
| 25 | + forwardCsocLogs: false, |
| 26 | + logLevel: "INFO", |
| 27 | + logRetentionInDays: 7, |
| 28 | + mutualTlsTrustStoreKey: undefined, |
| 29 | + serviceSearchApiKeySecretName: "pfp-PfP-ServiceSearch-API-Key", |
| 30 | + stackName: "pfp-test-stack", |
| 31 | + targetServiceSearchServer: "https://live/service-search-api/", |
| 32 | + targetSpineServer: "https://example-spine.test", |
| 33 | + tc007NhsNumberValue: "9000000009", |
| 34 | + tc008NhsNumberValue: "9000000017", |
| 35 | + tc009NhsNumberValue: "9000000025", |
| 36 | + toggleGetStatusUpdates: "true" |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +function createSandboxStackProps(): PfPApiSandboxStackProps { |
| 41 | + return { |
| 42 | + ...createStandardStackProps(), |
| 43 | + logLevel: "INFO", |
| 44 | + logRetentionInDays: 30, |
| 45 | + mutualTlsTrustStoreKey: undefined, |
| 46 | + stackName: "pfp-sandbox", |
| 47 | + targetServiceSearchServer: "https://sandbox/service-search-api/", |
| 48 | + targetSpineServer: "https://example-spine.test" |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +describe("CDK stack synthesis", () => { |
| 53 | + it("synthesizes the main stack with the core API resources", () => { |
| 54 | + const app = new App() |
| 55 | + const stack = new PfPApiStack(app, "TestPfPApiStack", createMainStackProps()) |
| 56 | + const template = Template.fromStack(stack) |
| 57 | + |
| 58 | + template.resourceCountIs("AWS::ApiGateway::RestApi", 1) |
| 59 | + template.resourceCountIs("AWS::CloudWatch::Alarm", 4) |
| 60 | + template.resourceCountIs("AWS::StepFunctions::StateMachine", 1) |
| 61 | + |
| 62 | + template.hasResourceProperties("AWS::CloudWatch::Alarm", { |
| 63 | + AlarmDescription: "Count of Service Search errors", |
| 64 | + AlarmName: "pfp-test-stack-ServiceSearch_Errors", |
| 65 | + ActionsEnabled: true |
| 66 | + }) |
| 67 | + |
| 68 | + template.hasResourceProperties("AWS::Lambda::Function", { |
| 69 | + FunctionName: "pfp-test-stack-GetMyPrescriptions" |
| 70 | + }) |
| 71 | + }) |
| 72 | + |
| 73 | + it("synthesizes the sandbox stack with its public endpoints", () => { |
| 74 | + const app = new App() |
| 75 | + const stack = new PfPApiSandboxStack(app, "TestPfPApiSandboxStack", createSandboxStackProps()) |
| 76 | + const template = Template.fromStack(stack) |
| 77 | + |
| 78 | + template.resourceCountIs("AWS::ApiGateway::RestApi", 1) |
| 79 | + template.resourceCountIs("AWS::Lambda::Function", 3) |
| 80 | + |
| 81 | + template.hasResourceProperties("AWS::Lambda::Function", { |
| 82 | + FunctionName: "pfp-sandbox-Sandbox" |
| 83 | + }) |
| 84 | + |
| 85 | + template.hasResourceProperties("AWS::Lambda::Function", { |
| 86 | + FunctionName: "pfp-sandbox-CapabilityStatement" |
| 87 | + }) |
| 88 | + }) |
| 89 | +}) |
0 commit comments