@fixture.usm
@fixture.boto3
Feature: Log in using USM

  Scenario: First-time user
    When I visit the USM login page
    Then I should get redirected to the USM authorization URL with
      | query param   | value                                    |
      | response_type | code                                     |
      | scope         | openid email                             |
      | client_id     | fake_client_id                           |
      | state         | <any>                                    |
      | redirect_uri  | https://atlas_um.test/usm/login/callback |
      | nonce         | <any>                                    |
    And I should be assigned a session state matching the state param
    And I should be assigned a session nonce matching the nonce param
    Given USM is prepared to issue an ID token for me
    And USM graph has the following data for me
      | field             | value                                                |
      | givenName         | Jason                                                |
      | surname           | Whittle                                              |
      | country           | US                                                   |
      | jobTitle          | Software Developer                                   |
    When I complete my USM login and return to the login callback
    Then I should see unauthorized error


  Scenario: Existing user
    And there exists a DNA account
      | field              | value                                    |
      | sub                | sme-dna/6eca3c0bc7828ec06577129552b006e2 |
      | preferred_username | jason.whittle.sme@sonymusic.com          |
      | given_name         | Jason                                    |
      | family_name        | Whittle                                  |
      | email              | jason.whittle.sme@sonymusic.com          |
      | usm_account        | JSWH01                                   |

    When I visit the USM login page
    Then I should get redirected to the USM authorization URL with
      | query param   | value                                    |
      | response_type | code                                     |
      | scope         | openid email                             |
      | client_id     | fake_client_id                           |
      | state         | <any>                                    |
      | redirect_uri  | https://atlas_um.test/usm/login/callback |
      | nonce         | <any>                                    |
    And I should be assigned a session state matching the state param
    And I should be assigned a session nonce matching the nonce param
    Given USM is prepared to issue an ID token for me
    And USM graph has the following data for me
      | field             | value                                                |
      | givenName         | Jason                                                |
      | surname           | Whittle                                              |
      | country           | US                                                   |
      | jobTitle          | Software Developer                                   |
    When I complete my USM login and return to the login callback
    Then I should be assigned a valid DNA bearer token
    And I should be redirected to the userinfo page
    And DNA account data should match the following
      | field             | value                                                |
      | given_name        | Jason                                                |
      | family_name       | Whittle                                              |
      | location          | US                                                   |
      | job_title         | Software Developer                                   |

  Scenario: Suspended user
    And there exists an expired DNA account
      | field              | value                                    |
      | sub                | sme-dna/6eca3c0bc7828ec06577129552b006e2 |
      | preferred_username | jason.whittle.sme@sonymusic.com          |
      | given_name         | Jason                                    |
      | family_name        | Whittle                                  |
      | email              | jason.whittle.sme@sonymusic.com          |
      | usm_account        | JSWH01                                   |
    When I visit the USM login page
    Then I should get redirected to the USM authorization URL with
      | query param   | value                                    |
      | response_type | code                                     |
      | scope         | openid email                             |
      | client_id     | fake_client_id                           |
      | state         | <any>                                    |
      | redirect_uri  | https://atlas_um.test/usm/login/callback |
      | nonce         | <any>                                    |
    And I should be assigned a session state matching the state param
    And I should be assigned a session nonce matching the nonce param
    Given USM is prepared to issue an ID token for me
    When I complete my USM login and return to the login callback
    Then I should receive response with "401" status
    And No DNA bearer token should be assigned
