Stateful scenarios

A stateful scenario is a type of scenario in which the behavior of the mock service depends on the previous actions or requests made to the service. In other words, the state of the service is retained between requests and can affect the response of the service.

The mock service allows users to create scenarios, which are essentially state machines that can be customized with various states. The starting state for a scenario is always started. Users can configure the service to return different responses based on the current scenario state.

Definition:

  scenario:
    name: <string> # case-insensitive
    requiredState: <string> # a state to match. Initial state is "started"
                            # could be a comma-separated list
    newState: <string> # optional, a new state to set if a call is matched

Examples:

- method: demo.TrafficLights/NextState
  scenario: 
    name: DemoTrafficLights
    requiredState: started, red
    newState: green
  response:
    body:
      trafficLightColor: green
    status: OK

- method: demo.TrafficLights/NextState
  scenario: 
    name: DemoTrafficLights
    requiredState: green
    newState: yellow
  response:
    body:
      trafficLightColor: yellow
    status: OK

- method: demo.TrafficLights/NextState
  scenario: 
    name: DemoTrafficLights
    requiredState: yellow
    newState: red
  response:
    body:
      trafficLightColor: red
    status: OK
In this article