bfrp-bfr-validation-engine
v1.3.0
Published
[](https://dev.azure.com/dfe-ssp/BFRP/_build/latest?definitionId=415&branchName=develop)
Readme
BFRP-BFR-ValidationEngine
Custom form data validation engine for BFRP-BFR application to be used with Javascript frameworks frontend or NodeJS server
This project was generated with yarn version 1.9.1.
Babel v7.6.4 is being used to transpile ES6+ codes, and Jest v24.9.0 with code coverage reporter istanbul/nyc (built in with Jest) to run tests.
Getting Started
Prerequisites
Node v8+ is required.
yarn is preferred. If you prefer using npm as your package manager, replace yarn with npm in the commands below.
To develop/run the Azure functions serverless API of the validation engine locally, install version 2.x of the Azure Functions Core Tools.
Install packages
Run yarn install from project root to install all necessary packages.
Development with watch mode
Validation Engine
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
Create a directory named
mockin the projectsrcdirectory and put a file namedformData.jsonwith sample form data.Run the following command to run the project in development mode. The project would re-run itself when there is any changes in
.jsfiles insrcdirectory
yarn startValidation API - Azure Functions
validation-api contains code for the validation engine serverless api. validation-api/ValidationEngine contains the distribution copy of the validation engine.
From project root directory, run
yarn buildto build a production copy of the validation engine. It will also copy the code insidevalidation-api/ValidationEnginecd validation-apidirectoryCreate
local.settings.jsonfile with the content below. This also adds thevalidationFileNameTemplatevariable that is used to load right validation configuration file.ENVandBFRTYPEvariables used in the previous version of the validation engine are NOT used anymore.
{
"IsEncrypted": false,
"Values": {
"validationFileNameTemplate": "validationconfig",
"blobStorageHost": "http://remotehost.url/bfr/"
},
"Host": {
"LocalHttpPort": 7072,
"CORS": "*"
}
}- Run the following command to run the serverless api project locally. The project would re-run itself when there is any changes in
.jsfiles invalidation-apidirectory
yarn install
func startBuild and Test
Testing
Run the following command to test the application based on specs specified in __test__ directory
yarn test # npm test To run tests in watch mode to changes in the spec files, run-
yarn test:watch # npm run test:watchTo check test coverage, run-
yarn test:coverage # npm run test:coverageProduction Build
Validation Engine
Run the following command to build as ES6+ module in dist directory.
yarn build # npm run buildValidation 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.
yarn buildUsage
The module can then be imported to Javascript frameworks or NodeJS applications as
ES6+
import ValidationEngine from './path-to-module'ES5 with Webpack or CommonJS
const ValidationEngine = require('./path-to-module')The module can be instantiated with validation configuration as below
const valEngine = new ValidationEngine(config)Config Data Structure
{
"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
}
}