Skip to content

Commit b25ca3e

Browse files
authored
Merge pull request #262 from NHSDigital/feature/CCM-7498_templates-api-test-pack
CCM-7498: add playwright test suite for templates api
2 parents ba23e78 + 9afa790 commit b25ca3e

File tree

86 files changed

+7846
-1382
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+7846
-1382
lines changed

.eslintrc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@
8686
"devDependencies": [
8787
"jest.config.ts",
8888
"jest.setup.ts",
89-
"src/__tests__/**"
89+
"**/__tests__/**"
9090
]
9191
}
9292
],
93-
"no-empty-function": "off"
93+
"no-empty-function": "off",
94+
"unicorn/prefer-module": "off"
9495
},
9596
"overrides": [
9697
{

.github/workflows/stage-4-acceptance.yaml

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ jobs:
6666
with:
6767
name: sandbox_tf_outputs.json
6868
path: sandbox_tf_outputs.json
69+
- uses: actions/upload-artifact@v4
70+
with:
71+
name: amplify_outputs.json
72+
path: ./frontend/amplify_outputs.json
6973
test-security:
7074
name: "Security test"
7175
runs-on: ubuntu-latest
@@ -95,6 +99,10 @@ jobs:
9599
with:
96100
name: sandbox_tf_outputs.json
97101
path: ./
102+
- uses: actions/download-artifact@v4
103+
with:
104+
name: amplify_outputs.json
105+
path: ./frontend
98106
- name: "Repo setup"
99107
run: |
100108
npm ci
@@ -108,9 +116,7 @@ jobs:
108116
role-session-name: deployInfra
109117
aws-region: eu-west-2
110118
- name: "Run accessibility test"
111-
run: |
112-
npm run create-amplify-outputs file
113-
make test-accessibility
119+
run: make test-accessibility
114120
- name: Archive accessibility results
115121
uses: actions/upload-artifact@v4
116122
with:
@@ -131,6 +137,10 @@ jobs:
131137
with:
132138
name: sandbox_tf_outputs.json
133139
path: ./
140+
- uses: actions/download-artifact@v4
141+
with:
142+
name: amplify_outputs.json
143+
path: ./frontend
134144
- name: "Repo setup"
135145
run: |
136146
npm ci
@@ -147,7 +157,6 @@ jobs:
147157
aws-region: eu-west-2
148158
- name: "Run ui component test"
149159
run: |
150-
npm run create-amplify-outputs file
151160
cd tests/test-team
152161
npm run test:local-ui
153162
- name: Archive component test results
@@ -156,11 +165,50 @@ jobs:
156165
with:
157166
name: component test report
158167
path: "tests/test-team/playwright-report"
168+
test-api:
169+
name: "API test"
170+
runs-on: ubuntu-latest
171+
needs: [sandbox-set-up]
172+
environment: dev
173+
timeout-minutes: 10
174+
steps:
175+
- name: "Checkout code"
176+
uses: actions/checkout@v4
177+
- uses: actions/download-artifact@v4
178+
with:
179+
name: sandbox_tf_outputs.json
180+
path: './'
181+
- uses: actions/download-artifact@v4
182+
with:
183+
name: amplify_outputs.json
184+
path: ./frontend
185+
- name: "Repo setup"
186+
run: |
187+
npm ci
188+
- name: Configure AWS credentials
189+
uses: aws-actions/configure-aws-credentials@v4
190+
with:
191+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ASSUME_ROLE_NAME }}
192+
role-session-name: deployInfra
193+
aws-region: eu-west-2
194+
- name: "Run API test"
195+
run: |
196+
cd tests/test-team
197+
npm run test:api
198+
- name: Archive API test results
199+
uses: actions/upload-artifact@v4
200+
with:
201+
name: API test report
202+
path: "tests/test-team/playwright-report"
203+
159204
sandbox-tear-down:
160205
name: "Sandbox tear down"
161206
if: success() || failure()
162207
runs-on: ubuntu-latest
163-
needs: [test-accessibility, test-ui-component]
208+
needs:
209+
- test-accessibility
210+
- test-ui-component
211+
- test-api
164212
environment: dev
165213
steps:
166214
- uses: hashicorp/setup-terraform@v3

frontend/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const nextConfig = (phase) => {
1515
basePath,
1616
env: {
1717
basePath,
18-
BACKEND_API_URL: amplifyConfig?.meta?.backend_api_url,
18+
API_BASE_URL: amplifyConfig?.meta?.api_base_url,
1919
},
2020

2121
experimental: {

frontend/src/components/molecules/ManageTemplates/ManageTemplates.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
previewTemplatePages,
1111
Template,
1212
TemplateStatus,
13-
templateStatustoDisplayMappings,
13+
templateStatusToDisplayMappings,
1414
templateTypeDisplayMappings,
1515
viewSubmittedTemplatePages,
1616
} from 'nhs-notify-web-template-management-utils';
@@ -78,7 +78,7 @@ export function ManageTemplates({
7878
: undefined
7979
}
8080
>
81-
{templateStatustoDisplayMappings(template.templateStatus)}
81+
{templateStatusToDisplayMappings(template.templateStatus)}
8282
</Tag>
8383
</Table.Cell>
8484
<Table.Cell>

frontend/src/components/molecules/PreviewTemplate/PreviewTemplate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import concatClassNames from '@utils/concat-class-names';
33
import {
44
Template,
55
TemplateStatus,
6-
templateStatustoDisplayMappings,
6+
templateStatusToDisplayMappings,
77
templateTypeDisplayMappings,
88
} from 'nhs-notify-web-template-management-utils';
99
import styles from './PreviewTemplate.module.scss';
@@ -53,7 +53,7 @@ export function PreviewTemplate({
5353
: undefined
5454
}
5555
>
56-
{templateStatustoDisplayMappings(template.templateStatus)}
56+
{templateStatusToDisplayMappings(template.templateStatus)}
5757
</Tag>
5858
</Col>
5959
</Row>

infrastructure/terraform/components/app/amplify_app.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ resource "aws_amplify_app" "main" {
3434
ACCOUNT_ID = var.aws_account_id
3535
NEXT_PUBLIC_DISABLE_CONTENT = var.disable_content
3636
AMPLIFY_MONOREPO_APP_ROOT = "frontend"
37-
BACKEND_API_URL = module.backend_api.api_base_url
37+
API_BASE_URL = module.backend_api.api_base_url
3838
USER_POOL_ID = jsondecode(data.aws_ssm_parameter.cognito_config.value)["USER_POOL_ID"]
3939
USER_POOL_CLIENT_ID = jsondecode(data.aws_ssm_parameter.cognito_config.value)["USER_POOL_CLIENT_ID"]
4040
}

infrastructure/terraform/components/sandbox/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ output "cognito_user_pool_client_id" {
1010
value = aws_cognito_user_pool_client.sandbox.id
1111
}
1212

13-
output "dynamodb_table_templates" {
14-
value = module.backend_api.dynamodb_table_templates
13+
output "templates_table_name" {
14+
value = module.backend_api.templates_table_name
1515
}

infrastructure/terraform/modules/backend-api/api_gateway_stage_main.tf

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,64 @@ resource "aws_api_gateway_stage" "main" {
33
description = "Templates API stage ${var.environment}"
44
rest_api_id = aws_api_gateway_rest_api.main.id
55
deployment_id = aws_api_gateway_deployment.main.id
6+
7+
access_log_settings {
8+
destination_arn = aws_cloudwatch_log_group.api_gateway_access.arn
9+
10+
// Context variables reference - https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference
11+
// This is useful https://aws.amazon.com/blogs/compute/troubleshooting-amazon-api-gateway-with-enhanced-observability-variables/
12+
// We're not using WAF, custom domain, mTLS etc at the moment, but we might want to add variables around these in the future if we start using them
13+
format = jsonencode({
14+
"accountId" : "$context.accountId"
15+
"apiId" : "$context.apiId"
16+
"authorize" : {
17+
"error" : "$context.authorize.error"
18+
"latency" : "$context.authorize.latency"
19+
"status" : "$context.authorize.status"
20+
}
21+
"authorizer" : {
22+
"error" : "$context.authorizer.error"
23+
"integrationLatency" : "$context.authorizer.integrationLatency"
24+
"integrationStatus" : "$context.authorizer.integrationStatus"
25+
"latency" : "$context.authorizer.latency"
26+
"principalId" : "$context.authorizer.principalId"
27+
"requestId" : "$context.authorizer.requestId"
28+
"status" : "$context.authorizer.status"
29+
}
30+
"awsEndpointRequestId" : "$context.awsEndpointRequestId"
31+
"deploymentId" : "$context.deploymentId"
32+
"domainName" : "$context.domainName"
33+
"domainPrefix" : "$context.domainPrefix"
34+
"endpointType" : "$context.endpointType"
35+
"error" : {
36+
"message" : "$context.error.message"
37+
"responseType" : "$context.error.responseType"
38+
"validationErrorString" : "$context.error.validationErrorString"
39+
}
40+
"extendedRequestId" : "$context.extendedRequestId"
41+
"httpMethod" : "$context.httpMethod"
42+
"identity" : {
43+
"sourceIp" : "$context.identity.sourceIp"
44+
"userAgent" : "$context.identity.userAgent"
45+
}
46+
"integration" : {
47+
"error" : "$context.integration.error"
48+
"integrationStatus" : "$context.integration.integrationStatus"
49+
"latency" : "$context.integration.latency"
50+
"requestId" : "$context.integration.requestId"
51+
"status" : "$context.integration.status"
52+
}
53+
"path" : "$context.path"
54+
"protocol" : "$context.protocol"
55+
"requestId" : "$context.requestId"
56+
"requestTime" : "$context.requestTime"
57+
"requestTimeEpoch" : "$context.requestTimeEpoch"
58+
"responseLatency" : "$context.responseLatency"
59+
"responseLength" : "$context.responseLength"
60+
"resourceId" : "$context.resourceId"
61+
"resourcePath" : "$context.resourcePath"
62+
"stage" : "$context.stage"
63+
"status" : "$context.status"
64+
})
65+
}
666
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource "aws_cloudwatch_log_group" "api_gateway_access" {
2+
name = "/aws/api-gateway/${aws_api_gateway_rest_api.main.id}/${var.environment}/access-logs"
3+
retention_in_days = var.log_retention_in_days
4+
}

infrastructure/terraform/modules/backend-api/iam_role_api_gateway_execution_role.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ resource "aws_iam_role" "api_gateway_execution_role" {
44
assume_role_policy = data.aws_iam_policy_document.api_gateway_service_trust_policy.json
55
}
66

7+
resource "aws_iam_role_policy_attachment" "cloudwatch_logs" {
8+
role = aws_iam_role.api_gateway_execution_role.name
9+
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs"
10+
11+
}
12+
713
resource "aws_iam_role_policy" "api_gateway_execution_policy" {
814
role = aws_iam_role.api_gateway_execution_role.name
915
name = "${local.csi}-apig-execution-policy"

0 commit comments

Comments
 (0)