[](https://dev.azure.com/dfe-ssp/BFRP/_build/latest?definitionId=415&branchName=develop)
npm install bfrp-bfr-validation-engine
Javascript frameworks frontend or NodeJS server
ES6+ codes, and Jest v24.9.0 with code coverage reporter istanbul/nyc (built in with Jest) to run tests.
yarn is preferred. If you prefer using npm as your package manager, replace yarn with npm in the commands below.
yarn install from project root to install all necessary packages.
src/app contains code for the actual validation engine module. src/index.js is to run and check validation engine functionalities to speed up development
mock in the project src directory and put a file named formData.json with sample form data.
.js files in src directory
bash
yarn start
`
Validation API - Azure Functions
validation-api contains code for the validation engine serverless api. validation-api/ValidationEngine contains the distribution copy of the validation engine.
1. From project root directory, run yarn build to build a production copy of the validation engine. It will also copy the code inside validation-api/ValidationEngine
2. cd validation-api directory
3. Create local.settings.json file with the content below. This also adds the validationFileNameTemplate variable that is used to load right validation configuration file. ENV and BFRTYPE variables used in the previous version of the validation engine are NOT used anymore.
`JSON
{
"IsEncrypted": false,
"Values": {
"validationFileNameTemplate": "validationconfig",
"blobStorageHost": "http://remotehost.url/bfr/"
},
"Host": {
"LocalHttpPort": 7072,
"CORS": "*"
}
}
`
4. Run the following command to run the serverless api project locally. The project would re-run itself when there is any changes in .js files in validation-api directory
`bash
yarn install
func start
`
Build and Test
Testing
Run the following command to test the application based on specs specified in __test__ directory
`bash
yarn test # npm test
`
To run tests in watch mode to changes in the spec files, run-
`bash
yarn test:watch # npm run test:watch
`
To check test coverage, run-
`bash
yarn test:coverage # npm run test:coverage
`
Production Build
Validation Engine
Run the following command to build as ES6+ module in dist directory.
`bash
yarn build # npm run build
`
Validation Azure Serverless Api
Run the following command to have the Azure Functions serverless api with latest version of the validation engine inside validation-api directory.
`bash
yarn build
`
Usage
The module can then be imported to Javascript frameworks or NodeJS applications as
ES6+
`js
import ValidationEngine from './path-to-module'
`
ES5 with Webpack or CommonJS
`js
const ValidationEngine = require('./path-to-module')
`
The module can be instantiated with validation configuration as below
`js
const valEngine = new ValidationEngine(config)
`
Config Data Structure
`json
{
"VAL2260S": {
"type": "SOFT",
"logicRule": "001-Sum of main cells exceeds threshold",
"mainCells": [
"218-1"
],
"threshold": 50,
"warningFlag1": "Some warning data",
"warningFlag2": "VAL2260S: Some additional warning data",
"enabled": true
}
}
``