The test-station microservice contains some reference data to be used for CVS services and mobile application for DVSA.
The project runs on node >18.x with typescript and serverless framework. For further details about project dependencies, please refer to the package.json
file.
nvm is used to managed node versions and configuration explicitly done per project using an .npmrc
file.
Please install and run the following securiy programs as part of your development process:
-
git-secrets After installing, do a one-time set up with
git secrets --register-aws
. Run withgit secrets --scan
.
These will be run as part of your projects hooks so you don't accidentally introduce any new security vulnerabilities.
Data is used is made available to VTA for searching a vehicle. Please refer to the the docs for the API specification and samples of postman requests.
More information about technical designs can be found under the Test Stations Microservice section.
Set up your nodejs environment running nvm use
and once the dependencies are installed using npm i
, you can run the scripts from package.json
to build your project.
This code repository uses serverless framework to mock AWS capabilities for local development.
You will also require to install dynamodb serverless to run your project with by running the following command npm run tools-setup
in your preferred shell.
Please refer to the local development section to configure your project locally.
The project has multiple hooks configured using husky which will execute the following scripts: security-checks
, audit
, tslint
, prepush
.
The latest version of husky has changed in two important ways.
- Hooks are no longer specified in package.json, but are in the .husky folder. They still point back to the npm scripts in package.json. Details of why can be seen on github.
- Hooks are not automatically installed via
npm install
any more. The installation of the hooks has been added to thenpm run tools-setup
script. Details of why can be seen on github.
It is very important that husky is installed, otherwise none of the security and code standard checks will run prior to commiting or pushing to github.
SonarQube code coverage analysis has been added as part of the git prepush hook. This is to better align with what happens in the pipeline.
To get it working locally, follow these steps:
- Ensure husky hooks are installed by running
npm i && npm run tools-setup
. - Ensure SonarQube is installed. Running in a container is a great option.
- Within SonarQube, Disable Force user authentication via Administration -> Configuration -> Security.
- Install jq with
sudo apt install jq
orbrew install jq
.
When running git push
, it will run tests followed by the sonarqube scan. If the scan fails or the unit test coverage is below 80%, the push is cancelled.
- The
BRANCH
environment variable indicates in which environment is this application running. UseBRANCH=local
for local development. This variable is required when starting the application or running tests.
The following scripts are available, however you can refer to the package.json
to see the details:
- installing dependencies:
npm install
- local development by starting the service:
npm start
- building the project:
npm run build
- unit tests:
npm t
- integration tests:
npm run test-i
You won't need to change the configuration.
However, if you want the database to be populated with mock data on start, in your serverless.yml
file, you need to set seed
to true
. You can find this setting under custom > dynamodb > start
.
If you choose to run the DynamoDB instance separately, you can send the seed command with the following command:
sls dynamodb seed --seed=test-stations
Under custom > dynamodb > seed
you can define new seed operations with the following config:
custom:
dynamodb:
seed:
[SEED NAME HERE]:
sources:
- table: [TABLE TO SEED]
sources: [./path/to/resource.json]
Default DynamoDB configuration for seeding the data:
migrate: true
seed: true
noStart: false
The following environmental variables can be given to your serverless scripts to trace and debug your service:
AWS_XRAY_CONTEXT_MISSING = LOG_ERROR
SLS_DEBUG = *
BRANCH = local
GET operations are exposed to the VTA App via API Gateway.
In AWS:
https://api.gateway.uri/develop/test-stations/P12345
Locally:
http://localhost:3004/test-stations/P12345
UPSERT operations are via direct lambda invocation with an EventBridgeEvent object.
{
"version":"0",
"id":"3b8d813d-9e1c-0c30-72f9-7539de987e31",
"detail-type":"CVS Update Test Stations",
"source":"cvs.update.test.stations",
"account":"1234567890",
"time":"2022-01-26T12:18:26Z",
"region":"eu-west-1",
"resources":[],
"detail":{
"testStationId": "fb342fef-725e-ec11-8f8f-002248437f2d",
"testStationAccessNotes": null,
"testStationAddress": "Test Street 1, null",
"testStationContactNumber": "0115 0115115,
"testStationEmails": [ "[email protected]" ],
"testStationGeneralNotes": "Some words.",
"testStationLongitude": -1.5882060527801514,
"testStationLatitude": 55.01923751831055,
"testStationName": "Test ATF",
"testStationPNumber": "P12345",
"testStationPostcode": "NE12 3AB",
"testStationStatus": "active",
"testStationTown": "Testtown",
"testStationType": "atf"
}
}
In AWS:
Either via direct lambda invocation via the AWS CLI or the Lambda Test Event feature in the AWS Console.
Locally:
Upsert operations can be achieved locally via a POST to http://localhost:3004/{apiVersion}/functions/cvs-svc-test-station-dev-getTestStations/invocations.
The test station will either be inserted or updated based on the absence or presense of a test station with the same testStationPNumber.
Jest is used for unit testing. Please refer to the Jest documentation for further details.
In order to test, you need to run the following:
npm run test # unit tests
In order to test, you need to run the following, with the service running locally:
npm run test-i # for integration tests
We follow a gitflow approach for development. For the CI/CD and automation please refer to the following pages for further details:
Please familiarise yourself with commitlint and conventional commits conventions as a hook is in place to enforce standards.
The project follow the a Kanban delivery workflow.
The codebase uses typescript clean code standards as well as sonarqube for static analysis.
SonarQube is available locally, please follow the instructions below if you wish to run the service locally (brew is the preferred approach).
Brew (recommended):
- Install sonarqube using brew
- Change
sonar.host.url
to point to localhost, by default, sonar runs onhttp://localhost:9000
- run the sonar server
sonar start
, then perform your analysisnpm run sonar-scanner
Manual:
- Download sonarqube
- Add sonar-scanner in environment variables in your profile file add the line:
export PATH=<PATH_TO_SONAR_SCANNER>/sonar-scanner-3.3.0.1492-macosx/bin:$PATH
- Start the SonarQube server:
cd <PATH_TO_SONARQUBE_SERVER>/bin/macosx-universal-64 ./sonar.sh start
- In the microservice folder run the command:
npm run sonar-scanner