API to track form submissions. Currently tracks file submissions only.
See docs/ for documentation.
Please install the Node.js version in .nvmrc using Node Version Manager nvm via:
cd forms-submission-api
nvm use-
Install Docker
-
Bring up runtime dependencies
docker compose up- Create a
.envfile with the following mandatory environment variables populated at root level:
MONGO_URI=""
MONGO_DATABASE=""
OIDC_JWKS_URI=""
OIDC_VERIFY_AUD=""
OIDC_VERIFY_ISS=""
COGNITO_JWKS_URI=""
COGNITO_CLIENT_ID=""
COGNITO_VERIFY_ISS=""
HTTP_PROXY=
HTTPS_PROXY=
NO_PROXY=
For proxy options, see https://www.npmjs.com/package/proxy-from-env which is used by https://github.com/TooTallNate/proxy-agents/tree/main/packages/proxy-agent. It's currently supports Hapi Wreck only, e.g. in the JWKS lookup.
- Database setup: See Database Migrations for information on how database migrations work in this project.
To run the application in development mode run:
npm run devTo mimic the application running in production mode locally run:
npm startAll available Npm scripts can be seen in package.json To view them in your command line run:
npm runThe integration tests use Docker Compose to create a complete testing environment with MongoDB, LocalStack (for S3 emulation), OIDC mock server, and Newman (Postman CLI) for API testing.
- Docker and Docker Compose installed
- Node.js (version as specified in
.nvmrc)
To run the full integration test suite:
npm run test:integrationThis command will:
- Start all required services (MongoDB, OIDC mock, app)
- Wait for services to be ready
- Run the Postman collection tests
- Clean up all services
For debugging or development purposes, you can run the integration tests step by step:
-
Start infrastructure services:
npm run test:integration:setup
-
Start the application:
npm run test:integration:start
-
Wait for services to be ready:
npm run test:integration:wait
-
Run the tests:
npm run test:integration:run
-
Clean up:
npm run test:integration:stop
The integration tests verify all the key functionality of the forms-submission-api:
- Health Check - Verifies the API is running
- File Ingestion - Tests the CDP callback endpoint (
POST /file) - File Status Check - Tests file existence verification (
GET /file/{fileId}) - Presigned Link Generation - Tests secure file access (
POST /file/link) - File Persistence - Tests moving files from 7-day to 30-day storage (
POST /files/persist) - Form Submission - Tests complete form submission flow (
POST /submit) - Error Handling - Tests validation failures and invalid requests
- Batch Operations - Tests multiple file handling
The integration test environment includes:
- MongoDB: Replica set configuration for transaction support
- OIDC Mock Server: Authentication provider for secure endpoints
- Newman: Postman CLI for running API test collections
When running on the main branch, HTML reports are generated:
- Location:
./newman-reports/newman-report.html - Includes detailed request/response logs and test results
- Available as CI artifacts in GitHub Actions
-
Port conflicts: The tests use ports 3002 (API), 5556, and 27018. Make sure these are available.
-
Docker resources: The integration tests require sufficient Docker resources. Increase Docker memory if needed.
-
Services not ready: If tests fail due to services not being ready, increase the wait time in the
test:integration:waitscript. -
Clean up: If services are left running, use:
npm run test:integration:stop
To view service logs:
docker compose -f docker-compose.integration-test.yml logs [service_name]Available services: mongo_test, oidc, app_test, newman
This project uses migrate-mongo to manage database migrations.
In production, migrations run automatically when the Docker container starts via the scripts/run-migrations-and-start.sh shell script. This script:
- Runs all pending migrations (
migrate-mongo up) - Starts the application server
- Logs migration progress to the container output
No manual intervention is required - migrations execute automatically on container startup.
For local development, you have two options:
Migrations run automatically when using Docker:
docker compose up --build forms-submission-apiThis mimics the production environment and runs migrations via the same shell script.
To work with migrations manually, you can install migrate-mongo globally:
npm install -g migrate-mongoAvailable migration commands:
# Check migration status
npm run migrate:status
# Run all pending migrations
npm run migrate:up
# Rollback the last migration
npm run migrate:down
# Create a new migration
npx migrate-mongo create <migration-name> -f migrate-mongo-config.jsImportant: When running migrations manually, ensure your .env file contains the correct MONGO_URI and MONGO_DATABASE values that match your local MongoDB instance.
| Endpoint | Description |
|---|---|
GET: /health |
Health |
POST: /file |
Ingests a file with a 7 day expiry. Called by the CDP uploader as a callback (upon file upload) |
GET: /file/{fileId} |
Checks that a file has been ingested. |
POST: /file/link |
Creates a link to a file which can be accessed by a user. Valid for 60 minutes. |
POST: /files/persist |
Extends the expiry to 30 days. Called upon form submission. |
Build:
docker build --target development --no-cache --tag forms-submission-api:development .Run:
docker run -e GITHUB_API_TOKEN -p 3008:3008 forms-submission-api:developmentBuild:
docker build --no-cache --tag forms-submission-api .Run:
docker run -e GITHUB_API_TOKEN -p 3002:3002 forms-submission-apiWhen running locally, you can view swagger documentation on http://localhost:3002/documentation this is built automatically from the joi schema and Hapi endpoints using Swagger Hapi.
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 license 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.