Test suite that runs a set of end to end tests against the epr-backend service.
Also provides a data generator facility for local development purposes.
Please install Node.js >= v20 and npm >= v9. You will find it
easier to use the Node Version Manager nvm
To use the correct version of Node.js for this application, via nvm:
nvm useGitleaks is required for pre-commit secret scanning and must be available on your PATH.
The simplest install on macOS/Linux is via mise
mise trust && mise installAlternatively, install directly:
- macOS:
brew install gitleaks - Linux/Windows: see the gitleaks releases page
mise - a polyglot version manager that reads mise.toml in this repo to install the correct pinned versions
Install application dependencies:
npm installFor Linux based machines, you will need to add this entry into your etc/hosts file for the tests to run locally:
127.0.0.1 defra-id-stub
Bring up the relevant Docker containers:
docker compose up -dRun the tests:
npm run testIf you run the epr-backend service as a standalone service (not via Docker Compose) and you wish to test without the logs or audit logs, run the following command:
WITHOUT_LOGS=true npm run testThe testing of logs and audit logs also assumes that you have run the Docker compose command above as it relies on the Dockerised epr-backend service.
For example, if you want to run accreditation tests, you can invoke:
npm run test:tagged @accreditationTo run with report, you can invoke:
npm run test:tagged @accreditation && npm run reportBy default, Proxy is disabled. To enable it, you first need a Proxy server running. You can use MITM Proxy via this Docker container command:
docker run --rm -it --name mitm-proxy --network cdp-tenant -p 7777:7777 -p 127.0.0.1:8081:8081 mitmproxy/mitmproxy mitmweb --web-host 0.0.0.0 --listen-port 7777 --set block_global=false
You can now monitor the proxy traffic via http://localhost:8081/ (Use the token on the console output from the Docker command above)
If you wish to use a port number other than 8081 for MITM Proxy (Web), you can pass in the following option at the end of the docker command (e.g. port 8082):
--web-port 8082
Now, you can run the tests with the following command:
WITH_PROXY=true npm run test
Alternatively, you can also use a non Docker based Proxy client such as Postman. For more information, please refer to the Postman Docs.
To run a non Docker based Proxy client, you need to use the following command:
WITH_EXTERNAL_PROXY=true npm run test
The default Proxy port is 7777. You can change it by modifying the value in test/config/config.js under the ProxyAgent configuration.
Tests are run from the CDP-Portal under the Test Suites section. Before any changes can be run, a new docker image must be built, this will happen automatically when a pull request is merged into the main branch.
You can check the progress of the build under the actions section of this repository. Builds typically take around 1-2 minutes.
The results of the test run are made available in the portal.
You can also run the tests against environments locally. This can be achieved by supplying both the ENVIRONMENT and X_API_KEY variables.
First, you will need to generate your X_API_KEY to use. Follow the CDP README for more information.
Then, to run the tests against the test environment (Where <api_key> = the generated key from the CDP README above):
X_API_KEY=<api_key> ENVIRONMENT=test npm run test:tagged @smoketest
If you want to run the tests with proxy against the test environment, you can do so by supplying the following:
WITH_PROXY=true X_API_KEY=<api_key> ENVIRONMENT=test npm run test:tagged @smoketest
Note that you will need to run the tests tagged with @smoketest to run against the test environment as not all tests can be run against the test environment (e.g. Database checks).
This only applies to local builds. You can generate 10 organisation details, registrations and accreditations (all linked together) in one go with this command:
npm run generatedata
If you want to generate an organisation that has all materials (but varied waste processing types, like Reprocessor Input / Output / Exporter), you can run:
npm run generatedata:allMaterials
If you want to generate an organisation that has all materials and all waste processing types (like Reprocessor Input / Output / Exporter in a single Organisation), you can run:
npm run generatedata:allMaterialsMixed
To generate with user linking (This assumes you have Defra ID Stub and Entra Stub running locally):
npm run generatedata:withLinking
npm run generatedata:allMaterials:withLinking
npm run generatedata:allMaterialsMixed:withLinking
This will create mock approved Organisation datasets with linked users. Only to be used for local development purposes.
There is a built-in spreadsheet generator that can be used to generate a spreadsheet for Summary Logs. Please open the file in Excel (Or equivalent) and save it at least once after the file is generated for it to be readable by the service.
Three generators are available:
For Reprocessor Output:
npm run generate:spreadsheet:output
For Reprocessor Input:
npm run generate:spreadsheet:input
For Exporter:
npm run generate:spreadsheet:exporter
For Registered Only (Unaccredited) Exporter:
npm run generate:spreadsheet:regOnlyExporter
For Registered Only (Unaccredited) Reprocessor:
npm run generate:spreadsheet:regOnlyReprocessor
You can also pass in registration number, accreditation number, material and number of rows to generate if you wish. For example, if you want to generate 20 rows of Reprocessor Output for Steel with registration number reg-number-123 and accreditation number acc-number-123, you can use:
ROWS=20 MATERIAL=ST REG_NUMBER=reg-number-123 ACC_NUMBER=acc-number-123 npm run generate:spreadsheet:output
For glass, material is GR or GO (Glass Re-melt, Glass Other). Plastic is PL, Aluminium is AL, Fibre is FB, Steel is ST, Paper is PO and Wood is WO.
To dynamically populate the spreadsheet, you can use the SHEETS environment variable (0 indexed) to specify which sheets to populate according to its index.
For example, with Reprocessor on Output, to populate only the first sheet (Received) and leave the others empty
SHEETS=0 ROWS=5 npm run generate:spreadsheet:output
To populate the first and third sheets (Reprocessor on Input example) only
SHEETS=0,2 npm run generate:spreadsheet:input
Note that the Cover sheet does not count as the first sheet as the Cover sheet is always mandatory.
Also note that you do not need to pass in an Accreditation Number for Registered Only spreadsheets as it would not be used.
| Test type | Local / PR Checks | Test environment |
|---|---|---|
| Endpoint tests | ✓ | ✓ |
| Mongo / database checks | ✓ | ☒ |
| Logging tests | ✓ | ☒ |
| Email / Notify tests | ☒ | ✓ |
| Slack non-prod tests | ☒ | ✓ |
For more information on the tests, please refer to the Confluence page.
THIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT LICENCE found at:
http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3
The following attribution statement MUST be cited in your products and applications when using this information.
Contains public sector information licensed under the Open Government licence v3
The Open Government Licence (OGL) was developed by the Controller of Her Majesty's Stationery Office (HMSO) to enable information providers in the public sector to license the use and re-use of their information under a common open licence.
It is designed to encourage use and re-use of information freely and flexibly, with only a few conditions.