dredd icon indicating copy to clipboard operation
dredd copied to clipboard

Ability to test the same transaction multiple times

Open e-compton opened this issue 5 years ago • 0 comments

Is your feature request related to a problem? Please describe. I have an API that takes two query string parameters a and b. Both parameters are required, and the API should return 400 when either of them are missing.

It is possible to test 1 parameter is missing, by adding a hook to 400 and deleting that parameter before the request is sent. But it is not possible to test both cases, as only one request is sent for a 400 response.

Describe the solution you'd like The ability to configure Dredd to call a specific request more than once. This could be in the form of a custom parameter in the specification x-times, that defaults to 1 when omitted.

  /:
    get:
      description: Demo Page
      produces:
      - text/html
      parameters:
      - name: a
        in: query
        type: string
        required: true
        x-example: value1
      - name: b
        in: query
        type: string
        required: true
        x-example: value2
      responses:
        200:
          description: Successful response
        400:
          description: Bad request
          x-times: 2

Then in the hooks:

before('Demo Page  > 400 > text/html > 1', (transaction) => {
  transaction.fullPath = transaction.fullPath.replace('&a=value1', '');
});
before('Demo Page  > 400 > text/html > 2', (transaction) => {
  transaction.fullPath = transaction.fullPath.replace('&b=value2', '');
});

Describe alternatives you've considered Alternatively Dredd could automatically issue multiple requests with query parameters missing. But this would be a breaking change to behaviour.

Additional context The API uses an OpenAPI V2 specification.

e-compton avatar Nov 20 '19 10:11 e-compton