#
# Explore and cover resources API with gabbi tests when there are a
# small number of pre-existing resources
#

fixtures:
    - ConfigFixture
    - SampleDataFixture

tests:

    - name: list all resources
      url: /v2/resources
      response_json_paths:
          $[0].user_id: farmerjon
          $[0].links[1].rel: livestock

    - name: get one resource
      desc: get a resource via the links in the first resource listed above
      url: $RESPONSE['$[0].links[0].href']
      response_json_paths:
          $.resource_id: $RESPONSE['$[0].resource_id']

    - name: list resources limit user_id
      url: /v2/resources?q.field=user_id&q.value=farmerjon
      response_json_paths:
          $[0].user_id: farmerjon
          $[0].links[1].rel: livestock

    - name: list resources limit metadata
      url: /v2/resources?q.field=metadata.breed&q.value=sheep
      response_json_paths:
          $[0].user_id: farmerjon
          $[0].links[1].rel: livestock

    - name: list resources limit metadata no match
      url: /v2/resources?q.field=metadata.breed&q.value=llamma
      response_strings:
          - "[]"

    - name: fail to get one resource
      url: /v2/resources/nosirnothere
      status: 404

    - name: list resource meter links present
      url: /v2/resources?meter_links=1
      response_json_paths:
          $[0].links[0].rel: self
          $[0].links[1].rel: livestock
          $[0].links[-1].rel: livestock

    - name: list resource meter links not present
      url: /v2/resources?meter_links=0
      desc: there is only one links entry when meter_links is 0
      response_json_paths:
          $[0].links[0].rel: self
          $[0].links[-1].rel: self

# limit resource results

    - name: get resources ulimited
      url: /v2/resources
      response_json_paths:
          $.`len`: 1

    - name: get resources limited
      url: /v2/resources?limit=1
      response_json_paths:
          $.`len`: 1

    - name: get resources double limit
      url: /v2/resources?limit=1&limit=1
      status: 400

    - name: get resources filter limit
      desc: expressing limit this way is now disallowed
      url: /v2/resources?q.field=limit&q.op=eq&q.type=&q.value=1
      status: 400
      response_strings:
          - 'Unknown argument: \"limit\": unrecognized field in query'

    - name: get resources filter limit and limit
      url: /v2/resources?q.field=limit&q.op=eq&q.type=&q.value=1&limit=1
      status: 400
      response_strings:
          - 'Unknown argument: \"limit\": unrecognized field in query'
