Model rules with Corticon.js
- Last Updated: April 14, 2021
- 2 minute read
- Corticon.js
- Version 2.3
- Documentation
Every Corticon.js rule project starts with a vocabulary. The vocabulary is where you specify the data model your rules operate on by defining the entities, attributes, and associations between entities.
![]()
Next, you create Rulesheets that contain the rules for your application. A Rulesheet contains one or more rules where each rule includes conditions that, if true, result in the corresponding action being performed. In this example, the conditions are to check the membership type and the total amount of the order. If membership type is equal to Gold and the total amount of the order is greater than or equal to $50, then the action sets the discount equal to 10 percent.
![]()
With your Rulesheets created, you are ready to test them. In Corticon.js Studio, you define Testsheets. Each Testsheet defines test input data and the expected output. Running Testsheets confirms that the expected results are produced and protects against regressions when future rule changes are made.
In this example, the Testsheet input order has no value assigned to the
discount attribute. The expected discount is 10
percent, based on the input values for membershipType
and order.totalAmount. When the test is run, the
output is generated, and the expected discount can be compared to the output discount value assigned by the rule that fired.
![]()
Rulesheets are then added to a Ruleflow. A Ruleflow automates complex decisions by dividing the rules across multiple Rulesheets. This modularity simplifies development and testing, and enables reuse. You can even use Ruleflows within other Ruleflows. You can add a Testsheet for a Ruleflow to test the output for the Ruleflow.
![]()
With the rule modeling complete, the next step is to package the rule for deployment on the JavaScript platform of your choice. For more information on rule modeling, see Introduction to Corticon.js rule modeling .