-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CVSB-19222 - vehicle details and test results endpoints (#1)
* feat(cvsb-19222): added new template * feat(cvsb-19222): First pass at enquiry service * feat(cvsb-19222): added secret manager related files to secignore * test(cvsb-19222): increase test coverage * feat(cvsb-19222): add error handling and results handler * fix(cvsb-19222): fix tests * fix(cvsb-19222): fix typing errors * fix(cvsb-19222): Change references to cvs-svc-template to the enquiry repo * feat(cvsb-19222): match return types to swagger * fix(cvsb-19222): Update tests and fix responses based on new types from previous commit * fix(cvsb-19222): remove unused import * chore(cvsb-19222): updated package-lock * chore(cvsb-19222): Bump husky to fix hooks * feat(cvsb-19222): Updated interfaces to match new swagger * test(cvsb-19222): rename a test * fix(cvsb-19222): temp remove error when there is no API_Version in the envvars * feat(cvsb-19222): get the database name from the schema_name envvar * fix(cvsb-19222): schema name is not a secret * fix(cvsb-19222): really simple queries for vehicle * chore(cvsb-19222): adding logging for vehicle details * fix(cvsb-19222): Update interfaces to match new schema * test(cvsb-19222): added tests for non-existant secrets service * test(cvsb-19222): added tests for non-existant database connection * feat(cvsb-19222): catch failure to instanciate new AWS Secrets Manager * feat(cvsb-19222): handle invalid requests in the api * feat(cvsb-19222): catch non-alphanumeric characters in querystring * feat(cvsb-19222): added new queries * fix(cvsb-19222): label all json responses as 'result' * feat(cvsb-19222): add in additional fields to response * fix(cvsb-19222): Double check the brakes query * fix(cvsb-19222): added spaces to fix SQL syntax errors * fix(cvsb-19222): update routing and query params to match the swagger * test(cvsb-19222): update tests to match updated routes and query params * feat(cvsb-19222): fully hydrate test results * fix(cvsb-19222): remove unused interfaces * fix(cvsb-19222): only update testRecord fields if there's something to update them with * fix(cvsb-19222): use a single connection for all DB calls in a given request * fix(cvsb-19222): run the subqueries in parallel to improve response times * feat(cvsb-19222_: change custom defect to array and add tests to check array handling works as expected * fix(cvsb-19222): update query to cast value as true/false * fix(cvsb-19222): remove errant comma from query * fix(cvsb-19222): convert manufactureDate to string * fix(cvsb-19222): code review changes * fix(cvsb-19222): change to new way of doing routing * chore(cvsb-19222): rename testRecord to testResult * chore(cvsb-19222): change name of brakes to psvBrakes * fix(cvsb-19222): 405 only for known routes, 404 for everything else * chore(cvsb-19222): added missing envvars to example file * fix(cvsb-1922): correctly name tests * test(cvsb-19222): add test to check empty response * feat(cvsb-19222): return a 404 error if the vehicle is not found * feat(cvsb-19222): return a 404 error if the test is not found * fix(cvsb-19222): try explicitly checking for undefined when 404ing * fix(cvsb-19222): fix typo in column names * Revert "fix(cvsb-19222): fix typo in column names" This reverts commit af95ba9.
- Loading branch information
Showing
102 changed files
with
17,702 additions
and
8,372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
# Matches multiple files with brace expansion notation | ||
# Set default charset | ||
[*.{js,ts, *.json, *.yml}] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
# Tab indentation (no size specified) | ||
[Makefile] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
node_modules | ||
.serverless | ||
.vscode | ||
*.config.js | ||
.webpack | ||
**/*.js | ||
.build, | ||
jest.config.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/README.md | ||
module.exports = { | ||
root: true, | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint', 'jest'], | ||
extends: ['eslint:recommended', 'prettier', 'prettier/@typescript-eslint', '@dvsa/eslint-config-ts'], | ||
rules: { | ||
'jest/no-disabled-tests': 'warn', | ||
'jest/no-commented-out-tests': 'warn', | ||
'jest/no-focused-tests': 'error', | ||
'jest/no-identical-title': 'error', | ||
'jest/prefer-to-have-length': 'warn', | ||
'jest/valid-expect': 'error', | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: 2 | ||
updates: | ||
# Enable version updates for npm | ||
- package-ecosystem: 'npm' | ||
# Look for `package.json` and `lock` files in the `root` directory | ||
directory: '/' | ||
# Check the npm registry for updates every day (weekdays) | ||
schedule: | ||
interval: 'daily' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Ticket title | ||
One line description | ||
[link to ticket number]() | ||
|
||
## Checklist | ||
- [ ] Code has been tested manually | ||
- [ ] PR title includes the JIRA ticket number | ||
- [ ] Branch is rebased against the latest develop | ||
- [ ] Squashed commit contains the JIRA ticket number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6.14.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
# https://docs.npmjs.com/cli/v6/configuring-npm/npmrc | ||
# ~/.npm-init.js | ||
# https://docs.npmjs.com/cli/v6/using-npm/config | ||
# https://docs.npmjs.com/cli/v6/commands/npm-audit | ||
audit-level = high | ||
audit = false | ||
audit = true | ||
init-version = "1.0.0" | ||
# save exact dependencies in case some do not rely on semver toa void dependencies hell | ||
save-exact = true | ||
sign-git-commit = false | ||
# handled by semantic release - format is x.x.x compying with semver standards | ||
# tag-version-prefix | ||
versions = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
10.18.1 | ||
10.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.serverless | ||
.webpack | ||
.artifact | ||
.build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
printWidth: 120, | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"branches": ["develop"], | ||
"repositoryUrl": "https://github.com/dvsa/cvs-svc-enquiry.git", | ||
"tagFormat": "${version}", | ||
"plugins": [ | ||
[ | ||
"@semantic-release/commit-analyzer", | ||
{ | ||
"releaseRules": [ | ||
{ "type": "docs", "release": "patch" }, | ||
{ "type": "breaking", "release": "major" } | ||
], | ||
"parserOpts": { | ||
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING_CHANGES", "BREAKING", "BREAKING_CHANGE"] | ||
} | ||
} | ||
], | ||
"@semantic-release/release-notes-generator", | ||
[ | ||
"@semantic-release/npm", | ||
{ | ||
"npmPublish": false | ||
} | ||
], | ||
"@semantic-release/changelog", | ||
[ | ||
"@semantic-release/git", | ||
{ | ||
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" | ||
} | ||
], | ||
"@semantic-release/github" | ||
], | ||
"preset": "angular" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
.npmrc | ||
src/errors/MissingSecretError.ts | ||
src/infrastructure/secretsManagerService.ts | ||
src/interfaces/SecretsManagerService.ts | ||
tests/unit/infrastructure/secretsService.test.ts | ||
tests/unit/infrastructure/secretsManagerService.test.ts |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,155 @@ | ||
# cvs-svc-enquiry | ||
# cvs-svc-enquiry | ||
|
||
Lambda service to retrieve vehicle and test information for commerical vehicles | ||
|
||
## Dependencies | ||
|
||
The project runs on node 10.x with typescript and serverless framework. For further details about project dependencies, please refer to the `package.json` file. | ||
[nvm](https://github.com/nvm-sh/nvm/blob/master/README.md) is used to managed node versions and configuration explicitely done per project using an `.npmrc` file. | ||
|
||
## Running the project | ||
|
||
Once the dependencies are installed, you will be required to rename the `/config/env.example` file to `.env.local` as we use dotenv files for configuration for local local development for example. Further information about [variables](https://www.serverless.com/framework/docs/providers/aws/guide/variables/) and [environment variables](https://www.serverless.com/framework/docs/environment-variables/) with serverless. | ||
|
||
The application runs on port `:3001` by default when no stage is provided. | ||
|
||
### Environments | ||
|
||
We use `NODE_ENV` environment variable to set multi-stage builds (region, stages) with the help of dotenv through npm scripts to load the relevant `.env.<NODE_ENV>` file from `./config` folder into the `serverless.yml` file as we don't rely on serverless for deployment. | ||
If no `NODE_ENV` value is provided when running the scripts, it will default its `NODE_ENV` value to 'development' with the `.env.development` config file. | ||
|
||
The defaulted values for 'stage' and 'region' are `'local'`. Please refer to the values provided in the `serverless.yml` file. | ||
|
||
The following values can be provided when running the scripts with `NODE_ENV`: | ||
|
||
```ts | ||
// ./config/.env.<NODE_ENV> files | ||
'local'; // used for local development | ||
'development'; // used development staging should we wish to require external services | ||
'test'; // used during test scripts where local services, mocks can be used in conjonction | ||
``` | ||
|
||
```ts | ||
/** Running serverless offline as an example for a specific stage - 'local'. | ||
* Stage 'local' will be injected in the serverless.yml | ||
**/ | ||
NODE_ENV=local serverless offline | ||
|
||
``` | ||
|
||
Further details about environment setup can be found in the provided documentation and `env.example` file. | ||
|
||
All secrets the secrets are will stored in `AWS Secrets Manager`. | ||
|
||
### Scripts | ||
|
||
The following scripts are available, for further information please refer to the project `package.json` file: | ||
|
||
- <b>start</b>: `npm start` - _launch serverless offline service_ | ||
- <b>dev</b>: `npm run dev` - _run in parallel the service and unit tests in_ `--watch` _mode with live reload_. | ||
- <b>test</b>: `npm t` - _execute the unit test suite_ | ||
- <b>build</b>: `npm run build` - _bundle the project for production_ | ||
|
||
### Offline | ||
|
||
Serverless-offline with webpack is used to run the project locally. Please use `npm run dev` script to do so. Go to `http://localhost:3001/local/version` to confirm that everything has loaded correctly, you should see that the version is the same as the version in the `package.json` | ||
|
||
### Lambda locally | ||
|
||
Serverless can invoke lambda functions locally which provide a close experience to the real service if you decide not use the offline mode. `events` and `paths` can be found under `/local` folder. | ||
For further details using lambda locally please refer to the [serverless documentation](https://www.serverless.com/framework/docs/providers/aws/cli-reference/invoke-local/). | ||
|
||
### Debugging | ||
|
||
Existing configuration to debug the running service has been made available for vscode, please refer to `.vscode/launch.json` file. Serverless offline will be available on port `:4000`. 2 jest configurations are also provided which will allow to run a test or multiple tests. | ||
|
||
For further information about debugging, please refer to the following documentation: | ||
|
||
- [Run-a-function-locally-on-source-changes](https://github.com/serverless-heaven/serverless-webpack#run-a-function-locally-on-source-changes) | ||
|
||
- [VSCode debugging](https://github.com/serverless-heaven/serverless-webpack#vscode-debugging) | ||
|
||
- [Debug process section](https://www.serverless.com/plugins/serverless-offline#usage-with-webpack) | ||
|
||
## Testing | ||
|
||
[json-serverless](https://github.com/pharindoko/json-serverless) has been added to the repository should we wish to mock external services during development and can be used in conjunction with the `test` environment. | ||
|
||
### Unit | ||
|
||
Jest is used for unit testing. | ||
Please refer to the [Jest documentation](https://jestjs.io/docs/en/getting-started) for further details. | ||
|
||
### Integration | ||
|
||
To be added and customised depending on needs, supertest is used but we could be looking at other packages such as nock, ts-mockito, typemoq, wiremock, etc.. or testing (pactjs, hoverfly, mockserver, etc..) | ||
|
||
## Infrastructure | ||
|
||
<Insert Design> | ||
|
||
### Release | ||
|
||
Releases (tag, release notes, changelog, github release, assets) are automatically managed by [semantic-release](https://semantic-release.gitbook.io/semantic-release/) and when pushing (or merging) to `master` branch which is protected. [semver](https://semver.org/) convention is followed. | ||
|
||
Please be familiar with conventional commit as described in the Contributing section below. | ||
|
||
Default preset used is angular for conventional commits, please see the [angular conventions](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum). | ||
|
||
The `<type>` `'breaking'` in the commit message will trigger a major version bump as well as any of the following text contained in the commit body: `"BREAKING CHANGE", "BREAKING CHANGES", "BREAKING_CHANGES", "BREAKING", "BREAKING_CHANGE"`. Please refer to the `.releaserc.json` file for the full configuration. | ||
|
||
The script `npm run release` will automatically trigger the release in CI. To manually test the release the following flags -`--dry-run --no-ci` - can be passed to the release script. | ||
|
||
Publishing and artifacts are managed separately by the pipeline. | ||
|
||
## Contributing | ||
|
||
To facilitate the standardisation of the code, a few helpers and tools have been adopted for this repository. | ||
|
||
### External dependencies | ||
|
||
The projects has multiple hooks configured using [husky](https://github.com/typicode/husky#readme) which will execute the following scripts: `audit`, `lint`, `build`, `test` and format your code with [eslint](https://github.com/typescript-eslint/typescript-eslint#readme) and [prettier](https://github.com/prettier/prettier). | ||
|
||
You will be required to install [git-secrets](https://github.com/awslabs/git-secrets) (_brew approach is recommended_) and DVSA [repo-security-scanner](https://github.com/UKHomeOffice/repo-security-scanner) that runs against your git log history to find accidentally committed passwords, private keys. | ||
|
||
We follow the [conventional commit format](https://www.conventionalcommits.org/en/v1.0.0/) when we commit code to the repository and follow the [angular convention](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum). | ||
|
||
The type is mandatory and must be all lowercase. | ||
The scope of your commit remain is also mandatory, it must include your ticket number and be all lowercase. The format for the ticket number can be set in the commitlint.config.js file. | ||
|
||
```js | ||
// Please see /commitlint.config.js for customised format | ||
|
||
type(scope?): subject | ||
|
||
// examples | ||
'chore(cvsb-1234): my commit msg' // pass | ||
'CHORE(cvsb-1234): my commit msg' // will fail | ||
|
||
``` | ||
### Code standards | ||
#### Code structure | ||
Domain Drive Design diagram with Interfaces, Application, Domain layers and Infrastructure across the layers. | ||
<p align="center"> | ||
<img src="./docs/DDD_architecture.jpg" alt="Domain Drive Design diagram with Interfaces, Application, Domain layers and Infrastructure across the layers" > | ||
</p> | ||
#### Toolings | ||
The code uses [eslint](https://eslint.org/docs/user-guide/getting-started), [typescript clean code standards](https://github.com/labs42io/clean-code-typescript) 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_: | ||
- Install sonarqube using brew | ||
- Change `sonar.host.url` to point to localhost, by default, sonar runs on `http://localhost:9000` | ||
- run the sonar server `sonar start`, then perform your analysis `npm run sonar-scanner` | ||
|
||
- _Manual_: | ||
- 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` |
Oops, something went wrong.