Action Simulator
The Action Simulator produces a mock context that you can utilize in your API Extension test files to simulate data from Kibo and verify that your functions run as expected. You can view the Action Simulator library in thenode_modules/mozu-action-simulator directory of your project folder. The simulator provides:
- Test fixtures for your actions that you can leverage to create data for your tests.
- Access to the assert module, which helps you devise assertion tests to determine whether your logic executes as expected.
-
Open the test file that corresponds to one of the actions you have scaffolded. Test files are located in the
assets/testdirectory. -
Require the
mozu-action-simulatorpackage in your test file. For example: -
Access simulator features, such as
Simulator.context()orSimulator.assert, to facilitate writing tests for your function.
Example of Testing with the Simulator
In this example, theembedded.commerce.carts.addItem.before action has been designed to check whether an item added to the cart has a ‘Hazardous’ product attribute. If the new item is hazardous and the cart already contains an existing hazardous item, the action removes the new item from the cart. The following code block demonstrates how you would test this action within its corresponding test file using the Action Simulator.
assets/test/embedded.commerce.carts.addItem.before.t.js

