Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Automated validators

Marc-AntoineA edited this page Jan 4, 2020 · 1 revision

From version 2.0, it's possible to add automatic validators/reviewers which are triggered after every applicant submission. While the applicant doesn't achieve these validators, its submission cannot be reviewed by the supervisor.

How to use these validators?

If you want to add a validator to any question, you just have to select it in the process editor. Be careful by defining the options - you can copy paste the example and edit it.

How to create a new validator?

A validator is mainly a JavaScript function which takes two arguments: the answer and some parameters (a JavaScript object).

  • Create a new file named <myAwesomeValidator>.js into the folder backend/validators/automated/
  • Create a function validator which takes two arguments.

_For example: _

function validator(value, { minWords }) {

}

This function should throw an explicit error message if it fails. This error message is sent to the applicant by email.

For example

throw `Your answer contains only ${nbWords} words and ${minWords} are expected`;
  • Export your function
module.exports.validator = validator;
  • Add a new entry to the validators object in index.js with the function, a label, a description, and an option example. The key should be MY_AWESOME_VALIDATOR

  • Add some tests in backend/test/automated_validators.js