Feature: API v2

  Scenario: Resource groups
    Given the following Claims
      | resource_group       | claim_name         | claim_values     | multi |
      | Apollo               | Role               | User, Superuser  | No    |
      | Apollo               | Market permissions | USA, UAE, UK     | Yes   |
      | RTI                  | Role               | User, Superuser  | No    |
      | RTI                  | Artists            | Artist1, Artist2 | Yes   |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/resource_groups"
    Then I should get JSON response with "200" status and the following body
      """
      {
        "count": 2,
        "limit": 100,
        "results": [
          {
            "id": "apollo",
            "name": "Apollo"
          },
          {
            "id": "rti",
            "name": "RTI"
          }
        ]
      }
      """

  Scenario: Claim names
    Given the following Claims
      | resource_group       | claim_name         | claim_values     | multi |
      | Apollo               | Role               | User, Superuser  | No    |
      | Apollo               | Market permissions | USA, UAE, UK     | Yes   |
      | RTI                  | Role               | User, Superuser  | No    |
      | RTI                  | Artists            | Artist1, Artist2 | Yes   |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/resource_groups/rti/claim_names"
    Then I should get JSON response with "200" status and the following body
      """
      {
        "count": 2,
        "limit": 100,
        "results": [
          {
            "id": "artists",
            "name": "Artists"
          },
          {
            "id": "role",
            "name": "Role"
          }
        ]
      }
      """

  Scenario: Global claim names
    Given the following global Claims
      | claim_name | claim_values     | multi |
      | Labels     | Columbia, Arista | No    |
      | Artists    | Artist1, Artist2 | Yes   |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/claim_names"
    Then I should get JSON response with "200" status and the following body
      """
      {
        "count": 2,
        "limit": 100,
        "results": [
          {
            "id": "artists",
            "name": "Artists"
          },
          {
            "id": "labels",
            "name": "Labels"
          }
        ]
      }
      """

  Scenario: Claim values
    Given the following Claims
      | resource_group       | claim_name         | claim_values     | multi |
      | Apollo               | Role               | User, Superuser  | No    |
      | Apollo               | Market permissions | USA, UAE, UK     | Yes   |
      | RTI                  | Role               | User, Superuser  | No    |
      | RTI                  | Artists            | Artist1, Artist2 | Yes   |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/resource_groups/rti/claim_names/artists"
    Then I should get JSON response with "200" status and the following body
      """
      {
        "count": 2,
        "limit": 100,
        "results": [
          {
            "id": "artist1",
            "name": "Artist1",
            "components": {}
          },
          {
            "id": "artist2",
            "name": "Artist2",
            "components": {}
          }
        ]
      }
      """

  Scenario: Global claim values
    Given the following global Claims
      | claim_name | claim_values     | multi |
      | Labels     | Columbia, Arista | No    |
      | Artists    | Artist1, Artist2 | Yes   |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/claim_names/artists"
    Then I should get JSON response with "200" status and the following body
      """
      {
        "count": 2,
        "limit": 100,
        "results": [
          {
            "id": "artist1",
            "name": "Artist1",
            "components": {}
          },
          {
            "id": "artist2",
            "name": "Artist2",
            "components": {}
          }
        ]
      }
      """

  Scenario: Claim value users
    Given the following DNA accounts
      | sub          | name       | email               |
      | sme-dna-1705 | Carol Cruz | carol.cruz@sme.test |
    Given the following Claims
      | resource_group       | claim_name         | claim_values     | multi |
      | Apollo               | Role               | User, Superuser  | No    |
      | Apollo               | Market permissions | USA, UAE, UK     | Yes   |
      | RTI                  | Role               | User, Superuser  | No    |
      | RTI                  | Artists            | Artist1, Artist2 | Yes   |
    And the following assigned claim values for DNA sub "sme-dna-1705"
      | claim_name         | claim_value      |
      | Role               | User             |
      | Artists            | Artist1, Artist2 |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/resource_groups/rti/claim_names/artists/artist1/users"
    Then I should get JSON response with "200" status and the following body
      """
      {
        "count": 1,
        "limit": 100,
        "results": [
          {
            "business_unit": "test_business_unit",
            "email": "carol.cruz@sme.test",
            "family_name": "Cruz",
            "given_name": "Carol",
            "id": "sme-dna-1705",
            "is_sony_employee": false,
            "is_vip": false,
            "job_category": "test_job_category",
            "job_title": "test_job_title",
            "location": "test_location",
            "personnel_type": "test_personnel_type",
            "preferred_username": "test_preferred_username",
            "status": "active",
            "supervisor_email": "test_supervisor_email@sme.com",
            "supervisor_name": "test_supervisor_name"
          }
        ]
      }
      """

  Scenario: Users
    Given the following DNA accounts
      | sub          | name       | email               |
      | sme-dna-1705 | Carol Cruz | carol.cruz@sme.test |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/users"
    Then I should get JSON response with "200" status and the following body
      """
      {
        "count": 1,
        "limit": 100,
        "results": [
          {
            "business_unit": "test_business_unit",
            "email": "carol.cruz@sme.test",
            "family_name": "Cruz",
            "given_name": "Carol",
            "id": "sme-dna-1705",
            "is_sony_employee": false,
            "is_vip": false,
            "job_category": "test_job_category",
            "job_title": "test_job_title",
            "location": "test_location",
            "personnel_type": "test_personnel_type",
            "preferred_username": "test_preferred_username",
            "status": "active",
            "supervisor_email": "test_supervisor_email@sme.com",
            "supervisor_name": "test_supervisor_name"
          }
        ]
      }
      """

  Scenario: Users status lookup
    Given the following DNA accounts
      | sub          | name       | email               |
      | sme-dna-1705 | Carol Cruz | carol.cruz@sme.test |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/users/status_lookup?email=carol.cruz@sme.test"
    Then I should get JSON response with "200" status and body containing items
      """
      [
        {
          "email": "carol.cruz@sme.test",
          "is_active": true
        }
      ]
      """

  Scenario: User details
    Given the following DNA accounts
      | sub          | name       | email               |
      | sme-dna-1705 | Carol Cruz | carol.cruz@sme.test |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/users/sme-dna-1705"
    Then I should get JSON response with "200" status and body containing
      """
      {
          "id": "sme-dna-1705",
          "email": "carol.cruz@sme.test",
          "given_name": "Carol",
          "family_name": "Cruz",
          "status": "active"
      }
      """

  Scenario: User claims
    Given the following DNA accounts
      | sub          | name       | email               |
      | sme-dna-1705 | Carol Cruz | carol.cruz@sme.test |
    Given the following Claims
      | resource_group       | claim_name         | claim_values     | multi |
      | Apollo               | Role               | User, Superuser  | No    |
      | Apollo               | Market permissions | USA, UAE, UK     | Yes   |
      | RTI                  | Role               | User, Superuser  | No    |
      | RTI                  | Artists            | Artist1, Artist2 | Yes   |
    And the following assigned claim values for DNA sub "sme-dna-1705"
      | claim_name         | claim_value      |
      | Role               | User             |
      | Artists            | Artist1, Artist2 |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/users/sme-dna-1705/claims"
    Then I should get JSON response with "200" status and the following body
      """
      {
          "sub": "sme-dna-1705",
          "email": "carol.cruz@sme.test",
          "name": "Carol Cruz",
          "apollo/role": {},
          "rti/artists": [{}, {}],
          "rti/role": {}
      }
      """

  Scenario: User resource groups
    Given the following DNA accounts
      | sub          | name       | email               |
      | sme-dna-1705 | Carol Cruz | carol.cruz@sme.test |
    Given the following Claims
      | resource_group       | claim_name         | claim_values     | multi |
      | Apollo               | Role               | User, Superuser  | No    |
      | Apollo               | Market permissions | USA, UAE, UK     | Yes   |
      | RTI                  | Role               | User, Superuser  | No    |
      | RTI                  | Artists            | Artist1, Artist2 | Yes   |
    And the following assigned claim values for DNA sub "sme-dna-1705"
      | claim_name         | claim_value      |
      | Role               | User             |
      | Artists            | Artist1, Artist2 |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/users/sme-dna-1705/resource_groups"
    Then I should get JSON response with "200" status and the following body
      """
      {
        "count": 2,
        "limit": 100,
        "results": [
          {
            "id": "apollo",
            "name": "Apollo"
          },
          {
            "id": "rti",
            "name": "RTI"
          }
        ]
      }
      """

    Scenario: User resource group claims
    Given the following DNA accounts
      | sub          | name       | email               |
      | sme-dna-1705 | Carol Cruz | carol.cruz@sme.test |
    Given the following Claims
      | resource_group       | claim_name         | claim_values     | multi |
      | Apollo               | Role               | User, Superuser  | No    |
      | Apollo               | Market permissions | USA, UAE, UK     | Yes   |
      | RTI                  | Role               | User, Superuser  | No    |
      | RTI                  | Artists            | Artist1, Artist2 | Yes   |
    And the following assigned claim values for DNA sub "sme-dna-1705"
      | claim_name         | claim_value      |
      | Role               | User             |
      | Artists            | Artist1, Artist2 |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/users/sme-dna-1705/resource_groups/rti/claims"
    Then I should get JSON response with "200" status and the following body
      """
      {
          "sub": "sme-dna-1705",
          "email": "carol.cruz@sme.test",
          "name": "Carol Cruz",
          "rti/artists": [{}, {}],
          "rti/role": {}
      }
      """

  Scenario: User claim names
    Given the following DNA accounts
      | sub          | name       | email               |
      | sme-dna-1705 | Carol Cruz | carol.cruz@sme.test |
    Given the following Claims
      | resource_group       | claim_name         | claim_values     | multi |
      | Apollo               | Role               | User, Superuser  | No    |
      | Apollo               | Market permissions | USA, UAE, UK     | Yes   |
      | RTI                  | Role               | User, Superuser  | No    |
      | RTI                  | Artists            | Artist1, Artist2 | Yes   |
    And the following assigned claim values for DNA sub "sme-dna-1705"
      | claim_name         | claim_value      |
      | Role               | User             |
      | Artists            | Artist1, Artist2 |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/users/sme-dna-1705/resource_groups/rti/claim_names"
    Then I should get JSON response with "200" status and the following body
      """
      {
        "count": 2,
        "limit": 100,
        "results": [
          {
            "id": "artists",
            "name": "Artists"
          },
          {
            "id": "role",
            "name": "Role"
          }
        ]
      }
      """

  Scenario: User claim values
    Given the following DNA accounts
      | sub          | name       | email               |
      | sme-dna-1705 | Carol Cruz | carol.cruz@sme.test |
    Given the following Claims
      | resource_group       | claim_name         | claim_values     | multi |
      | Apollo               | Role               | User, Superuser  | No    |
      | Apollo               | Market permissions | USA, UAE, UK     | Yes   |
      | RTI                  | Role               | User, Superuser  | No    |
      | RTI                  | Artists            | Artist1, Artist2 | Yes   |
    And the following assigned claim values for DNA sub "sme-dna-1705"
      | claim_name         | claim_value      |
      | Role               | User             |
      | Artists            | Artist1, Artist2 |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/users/sme-dna-1705/resource_groups/rti/claim_names/artists"
    Then I should get JSON response with "200" status and the following body
      """
      {
        "count": 2,
        "limit": 100,
        "results": [
          {
            "id": "artist1",
            "name": "Artist1",
            "components": {}
          },
          {
            "id": "artist2",
            "name": "Artist2",
            "components": {}
          }
        ]
      }
      """

    Scenario: User claim name claims
    Given the following DNA accounts
      | sub          | name       | email               |
      | sme-dna-1705 | Carol Cruz | carol.cruz@sme.test |
    Given the following Claims
      | resource_group       | claim_name         | claim_values     | multi |
      | Apollo               | Role               | User, Superuser  | No    |
      | Apollo               | Market permissions | USA, UAE, UK     | Yes   |
      | RTI                  | Role               | User, Superuser  | No    |
      | RTI                  | Artists            | Artist1, Artist2 | Yes   |
    And the following assigned claim values for DNA sub "sme-dna-1705"
      | claim_name         | claim_value      |
      | Role               | User             |
      | Artists            | Artist1, Artist2 |
    And I authenticated as api client
    When I send "GET" request to "/api/v2/users/sme-dna-1705/resource_groups/rti/claim_names/role/claims"
    Then I should get JSON response with "200" status and the following body
      """
      {
          "sub": "sme-dna-1705",
          "email": "carol.cruz@sme.test",
          "name": "Carol Cruz",
          "rti/role": {}
      }
      """
