#
# Test the resource history related API
#

fixtures:
    - ConfigFixture

defaults:
  request_headers:
    content-type: application/json
    # User foobar
    authorization: "basic Zm9vYmFyOg=="

tests:
    - name: create archive policy
      POST: /v1/archive_policy
      request_headers:
        # User admin
        authorization: "basic YWRtaW46"
      data:
          name: low
          definition:
              - granularity: 1 hour
      status: 201
      response_headers:
          location: $SCHEME://$NETLOC/v1/archive_policy/low

# Try creating a new generic resource

    - name: post generic resource
      POST: /v1/resource/generic
      data:
          id: f93450f2-d8a5-4d67-9985-02511241e7d1
          started_at: "2014-01-03T02:02:02.000000"
          user_id: 0fbb231484614b1a80131fc22f6afc9c
          project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
      status: 201
      response_headers:
          location: $SCHEME://$NETLOC/v1/resource/generic/f93450f2-d8a5-4d67-9985-02511241e7d1
          content-type: /^application\/json/
      response_json_paths:
          $.creator: foobar
          $.user_id: 0fbb231484614b1a80131fc22f6afc9c

# Update it twice
    - name: patch resource user_id
      PATCH: /v1/resource/generic/f93450f2-d8a5-4d67-9985-02511241e7d1
      data:
          user_id: f53c58a4-fdea-4c09-aac4-02135900be67
      status: 200
      response_json_paths:
          user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea

    - name: patch resource project_id
      PATCH: $LAST_URL
      data:
          project_id: fe20a931-1012-4cc6-addc-39556ec60907
          metrics:
            mymetric:
              archive_policy_name: low
      status: 200
      response_json_paths:
          user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          project_id: fe20a931-1012-4cc6-addc-39556ec60907

# List resources

    - name: list all resources without history
      GET: /v1/resource/generic
      response_json_paths:
          $[0].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[0].project_id: fe20a931-1012-4cc6-addc-39556ec60907

    - name: list all resources with history
      GET: $LAST_URL?details=true&history=true
      response_json_paths:
          $.`len`: 3
          $[0].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[0].user_id: 0fbb231484614b1a80131fc22f6afc9c
          $[0].project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $[1].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[1].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[1].project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $[2].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[2].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[2].project_id: fe20a931-1012-4cc6-addc-39556ec60907

    - name: patch resource metrics
      PATCH: /v1/resource/generic/f93450f2-d8a5-4d67-9985-02511241e7d1
      data:
          metrics:
            foo:
              archive_policy_name: low
      status: 200

    - name: list all resources with history no change after metrics update
      GET: /v1/resource/generic?details=true&history=true
      response_json_paths:
          $.`len`: 3
          $[0].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[0].user_id: 0fbb231484614b1a80131fc22f6afc9c
          $[0].project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $[1].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[1].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[1].project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $[2].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[2].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[2].project_id: fe20a931-1012-4cc6-addc-39556ec60907

    - name: create new metrics
      POST: /v1/resource/generic/f93450f2-d8a5-4d67-9985-02511241e7d1/metric
      data:
        foobar:
          archive_policy_name: low
      status: 200
      response_json_paths:
          $[/name][1].name: foobar
          $[/name][1].resource_id: f93450f2-d8a5-4d67-9985-02511241e7d1

    - name: list all resources with history no change after metrics creation
      GET: /v1/resource/generic?history=true&details=true
      response_json_paths:
          $.`len`: 3
          $[0].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[0].user_id: 0fbb231484614b1a80131fc22f6afc9c
          $[0].project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $[1].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[1].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[1].project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $[2].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[2].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[2].project_id: fe20a931-1012-4cc6-addc-39556ec60907
