Distill
Requirements are expressed as scenarios.
A scenario represents the system's behavior from the user's perspective and follows the Given-When-Then structure to create a testable specification.
The specification is written as executable tests, which are automated and run continuously. These tests cover a full range of scenarios, from happy paths to error cases.

Success Scenario(s)
Focus on a single command!
For the ChangeMenu
command to succeed, you need to specify the required preconditions/events. In this case RestaurantCreated / Exists
is a precondition.
RestaurantCreated / Exists
might not be the only precondition. For example, "The menu must be in a modifiable state (e.g., not locked due to an active promotion or regulations)"

Deno.test(function changeRestaurantMenuDeciderTest() {
const changeRestaurantMenuCommand: RestaurantCommand = restaurantCommandSchema
.parse(
JSON.parse(changeRestaurantMenuCommandJson),
);
const restaurantCreatedEvent: RestaurantEvent = restaurantEventSchema
.parse(
JSON.parse(restaurantCreatedEventJson),
);
const restaurantMenuChangedEvent: RestaurantEvent = restaurantEventSchema
.parse(
JSON.parse(restaurantMenuChangedEventJson),
);
DeciderSpecification.for(restaurantDecider)
.given([restaurantCreatedEvent])
.when(changeRestaurantMenuCommand)
.then([restaurantMenuChangedEvent]);
});
Error Scenario(s)
Focus on a single command!
Define all the possible reasons why ChangeMenu
command can fail. In this case RestaurantCreated / Exists
is missing as a precondition.
RestaurantCreated / Exists
might not be the only missing precondition. For example, "The menu must be in a modifiable state (e.g., not locked due to an active promotion or regulations)"

Deno.test(function changeRestaurantMenuDeciderTest() {
const changeRestaurantMenuCommand: RestaurantCommand = restaurantCommandSchema
.parse(
JSON.parse(changeRestaurantMenuCommandJson),
);
const restaurantMenuNotChangedEvent: RestaurantEvent = restaurantEventSchema
.parse(
JSON.parse(restaurantMenuNotChangedEventJson),
);
DeciderSpecification.for(restaurantDecider)
.given([])
.when(changeRestaurantMenuCommand)
.then([restaurantMenuNotChangedEvent]);
});