Skip to content

Commit 3b4ce08

Browse files
committed
test: increase coverage
1 parent 39e0a02 commit 3b4ce08

4 files changed

Lines changed: 96 additions & 4 deletions

File tree

packages/cdk/tests/stacks.test.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
})

packages/cdk/tests/synth.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ function createBaseEnv() {
1616
}
1717
}
1818

19+
// These are smoke tests for the CLI entrypoints. Resource assertions should be done in-process
20+
// against synthesized stacks so coverage is attributed to the CDK code under test.
1921
describe("CDK synth smoke tests", () => {
2022
it("type-checks the cdk package", () => {
2123
expect(() => {

packages/cdk/vitest.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {createVitestConfig} from "../../vitest.default.config"
22

33
export default createVitestConfig({
4-
workspaceRoot: "../../"
4+
workspaceRoot: "../../",
5+
inlineDeps: ["@nhsdigital/eps-cdk-constructs"]
56
})

vitest.default.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ type VitestDefaultConfigOptions = {
55
workspaceRoot: string;
66
setupFiles?: Array<string>;
77
aliasOverrides?: Record<string, string>;
8+
inlineDeps?: Array<string>;
89
}
910

1011
export function createVitestConfig(options: VitestDefaultConfigOptions) {
11-
const {workspaceRoot, setupFiles = [], aliasOverrides = {}} = options
12+
const {workspaceRoot, setupFiles = [], aliasOverrides = {}, inlineDeps = []} = options
1213

1314
return defineConfig({
1415
resolve: {
@@ -31,7 +32,6 @@ export function createVitestConfig(options: VitestDefaultConfigOptions) {
3132
test: {
3233
clearMocks: true,
3334
coverage: {
34-
all: false,
3535
exclude: [
3636
"**/node_modules/**",
3737
"**/lib/**",
@@ -50,7 +50,7 @@ export function createVitestConfig(options: VitestDefaultConfigOptions) {
5050
include: ["tests/*.test.ts"],
5151
server: {
5252
deps: {
53-
inline: ["@nhsdigital/eps-spine-client", /@middy/]
53+
inline: ["@nhsdigital/eps-spine-client", /@middy/, ...inlineDeps]
5454
}
5555
},
5656
setupFiles

0 commit comments

Comments
 (0)