Skip to content

Commit a1ed991

Browse files
authored
[NDR-321] Update make file & E2E test readme (#993)
1 parent 5e32b10 commit a1ed991

File tree

3 files changed

+99
-38
lines changed

3 files changed

+99
-38
lines changed

Makefile

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,44 @@ ZIP_BASE_PATH = ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)/tmp
1818
ZIP_COMMON_FILES = lambdas/utils lambdas/models lambdas/services lambdas/repositories lambdas/enums lambdas/scripts
1919
CONTAINER ?= false
2020

21-
.PHONY: install clean help format list requirements ruff build-and-deploy-sandbox
21+
.PHONY: \
22+
install clean help format list requirements ruff build-and-deploy-sandbox \
23+
aws-login download-api-certs \
24+
test-api-e2e test-fhir-api-e2e test-apim-e2e test-api-e2e-snapshots \
25+
initiate-bulk-upload test-bulk-upload-e2e test-bulk-upload-e2e-snapshots \
26+
test-unit test-unit-coverage test-unit-coverage-html test-unit-collect \
27+
env github_env edge_env \
28+
package edge_zip lambda_layer_zip zip \
29+
install-asdf install-poetry install-dev \
30+
start test-ui test-ui-coverage build build-env-check \
31+
docker-up docker-up-rebuild docker-down \
32+
cypress-open cypress-run cypress-report install-cypress
2233

2334
default: help
2435

25-
help: ## This is a help message
26-
@grep -E --no-filename '^[a-zA-Z-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-42s\033[0m %s\n", $$1, $$2}'
36+
help: ## Show available targets and usage.
37+
@echo ""
38+
@echo "Available commands (documented):"
39+
@echo "--------------------------------"
40+
@grep -E --no-filename '^[a-zA-Z0-9_.-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
41+
sort | \
42+
awk 'BEGIN {FS = ":.*?## "}; { \
43+
desc = $$2; \
44+
if (index(desc, "Usage:") > 0) { \
45+
split(desc, parts, "Usage:"); \
46+
printf "\033[36m%-30s\033[0m\n %s\n \033[1mUsage:\033[0m%s\n\n", $$1, parts[1], parts[2]; \
47+
} else { \
48+
printf "\033[36m%-30s\033[0m\n %s\n\n", $$1, desc; \
49+
} \
50+
}'
51+
@echo "Tip: Add \033[33m## description ... Usage: ...\033[0m to a target line to include it in the documented list."
52+
@echo ""
53+
54+
guard-%:
55+
@ if [ "${${*}}" = "" ]; then \
56+
echo "$* is a required parameter. See make help for usage."; \
57+
exit 1; \
58+
fi
2759

2860
aws-login: ## Login to AWS. Usage: make aws-login AWS_PROFILE=<AWS_PROFILE>
2961
aws sso login --profile $(PROFILE) && export AWS_PROFILE=$(PROFILE)
@@ -83,14 +115,14 @@ download-api-certs: ## Downloads mTLS certificates (use with dev envs only). Usa
83115
rm -rf ./lambdas/mtls_env_certs/$(WORKSPACE)
84116
./scripts/aws/download-api-certs.sh $(WORKSPACE)
85117

86-
test-api-e2e:
118+
test-api-e2e: ## Runs LG FHIR API E2E tests. See readme for required environment variables. Usage: make test-api-e2e CONTAINER=<true|false>
87119
ifeq ($(CONTAINER), true)
88120
cd ./lambdas && PYTHONPATH=. poetry run pytest tests/e2e/api --ignore=tests/e2e/api/fhir -vv
89121
else
90122
cd ./lambdas && ./venv/bin/python3 -m pytest tests/e2e/api --ignore=tests/e2e/api/fhir -vv
91123
endif
92124

93-
test-fhir-api-e2e: ## Runs FHIR API E2E tests. Usage: make test-fhir-api-e2e WORKSPACE=<workspace> CONTAINER=<true|false>
125+
test-fhir-api-e2e: guard-WORKSPACE ## Runs Core FHIR API E2E tests. Usage: make test-fhir-api-e2e WORKSPACE=<workspace> CONTAINER=<true|false>
94126
./scripts/test/run-e2e-fhir-api-tests.sh --workspace $(WORKSPACE) --container $(CONTAINER)
95127
rm -rf ./lambdas/mtls_env_certs/$(WORKSPACE)
96128

lambdas/tests/e2e/README.md

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 🧪 End-to-End Testing Setup
22

3-
These tests focus on the features of the NDR. This will serve as a blended suite of integration and end-to-end (E2E) tests, with the aim to validate API functionality and snapshot comparisons.
3+
These tests serve as a suite of end-to-end (E2E) tests to validate FHIR API functionality and snapshot comparisons.
44

55
There are 2 suites which separately test
66

@@ -11,15 +11,9 @@ as well as APIM E2E tests `lambdas/tests/e2e/apim/`.
1111

1212
## 🔐 AWS Authentication
1313

14-
You must be authenticated with AWS to run the api tests. Use the following commands with a configured profile set up in ~/.aws/config to authenticate:
14+
You must be authenticated with AWS to run the api tests.
1515

16-
```bash
17-
aws sso login --profile <your-aws-profile>
18-
19-
export AWS_PROFILE=<your-aws-profile>
20-
```
21-
22-
An example profile:
16+
Before authenticating, ensure you have a valid AWS profile configured:
2317

2418
```bash
2519
[sso-session PRM]
@@ -34,63 +28,98 @@ region=eu-west-2
3428
output=json
3529
```
3630

37-
Make sure your AWS profile has access to the required resources.
31+
Your profile name (e.g. NDR-Dev-RW) must match what you use in the commands below. Make sure your AWS profile has access to the required resources.
3832

39-
## Using the dev container
33+
### Inside the dev container (preferred method): aws-vault
4034

41-
All of the below make commands can be used in the dev container. To run the below commands you need to append `CONTAINER=true`.
35+
Use `aws-vault` to assume the profile with a secure, temporary-session subshell.
36+
37+
```bash
38+
List configured profiles::
39+
'aws-vault list'
40+
41+
Start an authenticated session::
42+
'aws-vault exec <your-aws-profile>'
43+
44+
If the session expires, start a new one:
45+
'exit'
46+
'aws-vault exec <your-aws-profile>'
47+
```
48+
49+
### Alternative outside the dev container: AWS SSO CLI
50+
51+
Authenticate your profile and set it as the active one:
52+
53+
```bash
54+
aws sso login --profile <your-aws-profile>
55+
56+
export AWS_PROFILE=<your-aws-profile>
57+
```
4258

4359
## 🔧 Available Make Commands
4460

45-
- `make test-fhir-api-e2e WORKSPACE=<workspace>` — Runs the FHIR API E2E tests with mTLS against a given workspace
61+
All of the below make commands can be run either inside or outside the dev container. It is preferable to work inside the dev container as a developer tool to ensure code formatting and pre-commits are consistent throughout the team, keeping a high standard.
62+
63+
* To run inside the dev container append `CONTAINER=true` to each command
64+
65+
* If you need to work outside the dev container you **must** run `make env` first to set up your venv and any required dependencies
66+
67+
```bash
68+
make test-fhir-api-e2e WORKSPACE=<workspace> CONTIANER=true
4669

47-
- `make test-api-e2e` — Runs the E2E tests without mTLS
70+
make test-api-e2e
4871

49-
- `make test-apim-e2e` - Runs the APIM E2E tests
72+
make test-apim-e2e
73+
```
5074

5175
### Snapshots
5276

5377
Snapshots reduce the amount of individual assertions by comparing pre and post an object e.g. a JSON returned from an API.
5478

5579
Snapshot testing is used in the non mTLS test suite only. To update snapshots you can run the following make command:
5680

57-
- `make test-api-e2e-snapshots` — Runs snapshot comparison tests
81+
```bash
82+
make test-api-e2e-snapshots
83+
```
5884

59-
This runs pytest with the additional argument `--snapshot-update` which will replace the existing snapshots.
85+
This runs pytest with the additional argument `--snapshot-update` which will update and replace the existing snapshots.
6086

6187
### Certificate inspection
6288

63-
You can download the mTLS certificates used in the requests if you need to inspect them by running
89+
You can download the mTLS certificates used in the FHIR api requests if you need to inspect them
6490

65-
- `make download-api-certs WORKSPACE=<workspace>` — Downloads mTLS client cert and client key used in the request
91+
```bash
92+
make download-api-certs WORKSPACE=<workspace>
93+
```
6694

6795
❗ Always delete these after use and never commit them.
6896

6997
## 🌍 Required Environment Variables
7098

71-
In order to execute the E2E tests without mTLS (i.e. `make test-api-e2e`) you will need to ensure the following environment variables are set. You can export them in your shell configuration file (`~/.zshrc` or `~/.bashrc`) or **temporarily** add them to the `conftest.py`:
99+
In order to execute the Lloyd George API E2E tests (i.e. `make test-api-e2e`) you will need to ensure the following environment variables are set.
100+
101+
You can export them inside the subshell started by aws-vault exec - these will be scoped to your session and won’t leak to your host environment. Or equivalently, for working outside the dev container, export them in your shell configuration file (`~/.zshrc` or `~/.bashrc`). Or you can **temporarily** add them to the `conftest.py`, but do not commit these:
72102

73103
| Environment Variable | Description |
74104
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
75105
| `NDR_API_KEY` | The API key required to authenticate requests to the NDR API. API Gateway → API Keys for associated env e.g. ndr-dev_apim-api-key |
76-
| `NDR_API_ENDPOINT` | The URI string used to connect to the NDR API. |
77106
| `AWS_WORKSPACE` | The workspace that is being tested. |
78107
| `MOCK_CIS2_KEY` | The value of the Mock CIS2 Key. Found in Parameter Store: /auth/password/MOCK_KEY |
79108

80-
After updating your shell config, reload it:
109+
If you update your shell config, remember to reload it:
81110

82111
```bash
83-
source ~/.zshrc # or source ~/.bashrc
112+
source ~/.zshrc # ~/.bashrc
84113
```
85114

86115
## APIM E2E Tests
87116

88117
The **APIM E2E tests** validate the full integration and behavior of the API Management layer within the system. These tests ensure that:
89118

90-
- FHIR API endpoints (/DocumentReference) are correctly exposed and accessible via APIM.
91-
- mTLS authentication and authorization mechanisms are functioning as expected.
92-
- The routing and transformation logic configured in APIM behaves correctly.
93-
- The downstream services respond appropriately when accessed through APIM.
119+
* FHIR API endpoints (/DocumentReference) are correctly exposed and accessible via APIM.
120+
* mTLS authentication and authorization mechanisms are functioning as expected.
121+
* The routing and transformation logic configured in APIM behaves correctly.
122+
* The downstream services respond appropriately when accessed through APIM.
94123

95124
### Running the Tests
96125

@@ -128,14 +157,14 @@ cd ./lambdas && ./venv/bin/python3 -m pytest tests/e2e/apim -vv \
128157

129158
### Arguments
130159

131-
- `api-name`: Specifies the name of the API being tested. In this case, it's the National Document Repository FHIR R4 API.
132-
- `proxy-name`: Indicates the APIM proxy configuration to use during testing. This ensures the tests target the correct APIM instance and environment.
160+
* `api-name`: Specifies the name of the API being tested. In this case, it's the National Document Repository FHIR R4 API.
161+
* `proxy-name`: Indicates the APIM proxy configuration to use during testing. This ensures the tests target the correct APIM instance and environment.
133162

134163
### Important Notes
135164

136-
- Environment Configuration: Make sure your test environment is properly configured with access to APIM and any required secrets or credentials.
165+
* Environment Configuration: Make sure your test environment is properly configured with access to APIM and any required secrets or credentials.
137166

138-
- You can test your proxygen set up via `proxygen instance list` and expect to see `national-document-repository_FHIR_R4` listed.
167+
* You can test your proxygen set up via `proxygen instance list` and expect to see `national-document-repository_FHIR_R4` listed.
139168
For more information on proxygen credentials see: <https://nhsd-confluence.digital.nhs.uk/pages/viewpage.action?spaceKey=APM&title=Proxygen+CLI+user+guide>
140169

141-
- Dependencies: These tests rely on other services being up and running (e.g. backend API, databases). Ensure all dependencies are available before running the tests.
170+
* Dependencies: These tests rely on other services being up and running (e.g. backend API, databases). Ensure all dependencies are available before running the tests.

lambdas/tests/e2e/helpers/data_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(
3434

3535
def build_env(self, table_name, bucket_name):
3636
if not self.workspace:
37-
raise ValueError("WORKSPACE environment variable is missing or empty.")
37+
raise ValueError("AWS_WORKSPACE environment variable is missing or empty.")
3838
self.dynamo_table = f"{self.workspace}_{table_name}"
3939
self.s3_bucket = f"{self.workspace}-{bucket_name}"
4040

0 commit comments

Comments
 (0)