javascriptnode.jsstubbingstubby4jstubby4node

stubby4node comma separated query string implementation issue


I have a URL (GET REQUEST) of the following pattern

where pathid query string parameters are comma separated

I have the following stubby mappings to match these url patterns

- request:
    url: ^/testpath/(.*)/test
    query:
      pathid: '1'
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-1.json

- request:
    url: ^/testpath/(.*)/test
    query:
      pathid: '1,2'
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-2.json

- request:
    url: ^/testpath/(.*)/test
    query:
      pathid: '1,2,5'
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-3.json

but I can't get this URL mapping to properly deliver different payloads based on different parameter combinations.

how can this be done?


Solution

  • The trick here is to change the order of request/response mappings in the yaml file.

    - request:
        url: ^/testpath/(.*)/test
        query:
          **pathid: '1,2,5'**
        method: GET
      response:
        headers:
          Content-Type: application/json
        status: 200
        file: response/path-3.json
    
    - request:
        url: ^/testpath/(.*)/test
        query:
          **pathid: '1,2'**
        method: GET
      response:
        headers:
          Content-Type: application/json
        status: 200
        file: response/path-2.json
    
    - request:
        url: ^/testpath/(.*)/test
        query:
          **pathid: '1'**
        method: GET
      response:
        headers:
          Content-Type: application/json
        status: 200
        file: response/path-1.json
    

    note the path ids added in the descending order, so that more deeper matches will be executed first.

    This way I was able to achieve this following requirement, of passing different path ids separated by a comma