bbyars / mountebank

Over the wire test doubles
http://www.mbtest.org
MIT License
2k stars 262 forks source link

:zap: Expose `request` data directly into imposters #672

Closed x80486 closed 1 year ago

x80486 commented 2 years ago

I've been testing Mountebank and I stumble with some things I've already seen implemented in other software of the same nature. For instance, let's take a look at this imposter:

{
  "name": "characters-api.create",
  "port": 8090,
  "protocol": "http",
  "stubs": [
    {
      "predicates": [
        {
          "equals": {
            "headers": {
              "Accept": "application/json",
              "Content-Type": "application/json"
            },
            "method": "POST",
            "path": "/api/characters"
          }
        }
      ],
      "responses": [
        {
          "is": {
            "headers": {
              "Location": "<% ${request.uri.path}/${uuid.generate} %>"
            },
            "statusCode": 201
          }
        }
      ]
    }
  ]
}

At that point, all I'm interested is in grabbing the URI that was used (from the request), generate some data on the fly (a UUID) and send the response back.

Is it possible to accomplish that in the way I'm describing it, or is it required to use behaviors.decorate / inject?