test_name: Test the creation of accounts through the cic_user_ussd_server entrypoint.
marks:
  - usefixtures:
    - gift_value
    - server_url
    - token_symbol
    - generate_session_id
    - first_account_phone_number
    - second_account_phone_number
    - first_account_pin_number
    - second_account_pin_number
    - first_account_family_name
    - second_account_family_name
    - first_account_given_name
    - second_account_given_name
    - first_account_location
    - second_account_location
    - first_account_product
    - second_account_product
    - first_metadata_entry_session_id
    - second_metadata_entry_session_id
  - first

stages:
  - name: Initiate account creation process [first account].
    request:
      url: "{server_url}"
      data:
        serviceCode: "*483*46#"
        sessionId: "{generate_session_id}"
        phoneNumber: "{first_account_phone_number}"
        text: ""
      headers:
        content-type: "application/x-www-form-urlencoded"
      method: POST
    response:
      status_code:
        - 200
      headers:
        Content-Length: '91'
        Content-Type: "text/plain"
      verify_response_with:
        function: ext.validator:validate_response
        extra_kwargs:
          expected_response: "END Akaunti yako ya Sarafu inatayarishwa. Utapokea ujumbe wa SMS akaunti yako ikiwa tayari."
    delay_after: 5

  - name: Initiate account creation process [second account].
    request:
      url: "{server_url}"
      data:
        serviceCode: "*483*46#"
        sessionId: "{generate_session_id}"
        phoneNumber: "{second_account_phone_number}"
        text: ""
      headers:
        content-type: "application/x-www-form-urlencoded"
      method: POST
    response:
      status_code:
        - 200
      headers:
        Content-Length: '91'
        Content-Type: "text/plain"
      verify_response_with:
        function: ext.validator:validate_response
        extra_kwargs:
          expected_response: "END Akaunti yako ya Sarafu inatayarishwa. Utapokea ujumbe wa SMS akaunti yako ikiwa tayari."
    delay_after: 5

  - name: Initaite account metadata entry [first account]
    request:
      url: "{server_url}"
      data:
        serviceCode: "*483*46#"
        sessionId: "{first_metadata_entry_session_id}"
        phoneNumber: "{first_account_phone_number}"
        text: ""
      headers:
        content-type: "application/x-www-form-urlencoded"
      method: POST
    response:
      status_code:
        - 200
      headers:
        Content-Length: '57'
        Content-Type: "text/plain"
      verify_response_with:
        function: ext.validator:validate_response
        extra_kwargs:
          expected_response: "CON Karibu Sarafu Network\n1. English\n2. Kiswahili\n3. Help"

  - name: Initaite account metadata entry [second account]
    request:
      url: "{server_url}"
      data:
        serviceCode: "*483*46#"
        sessionId: "{second_metadata_entry_session_id}"
        phoneNumber: "{second_account_phone_number}"
        text: ""
      headers:
        content-type: "application/x-www-form-urlencoded"
      method: POST
    response:
      status_code:
        - 200
      headers:
        Content-Length: '57'
        Content-Type: "text/plain"
      verify_response_with:
        function: ext.validator:validate_response
        extra_kwargs:
          expected_response: "CON Karibu Sarafu Network\n1. English\n2. Kiswahili\n3. Help"

  - name: Select preferred language [English]
    request:
      url: "{server_url}"
      data:
        serviceCode: "*483*46#"
        sessionId: "{first_metadata_entry_session_id}"
        phoneNumber: "{first_account_phone_number}"
        text: "1"
      headers:
        content-type: "application/x-www-form-urlencoded"
      method: POST
    response:
      status_code:
        - 200
      headers:
        Content-Length: '71'
        Content-Type: "text/plain"
      verify_response_with:
        function: ext.validator:validate_response
        extra_kwargs:
          expected_response: "CON Tafadhali weka pin mpya yenye nambari nne kwa akaunti yako\n0. Nyuma"
    delay_after: 5

  - name: Select preferred language [Kiswahili]
    request:
      url: "{server_url}"
      data:
        serviceCode: "*483*46#"
        sessionId: "{second_metadata_entry_session_id}"
        phoneNumber: "{second_account_phone_number}"
        text: "2"
      headers:
        content-type: "application/x-www-form-urlencoded"
      method: POST
    response:
      status_code:
        - 200
      headers:
        Content-Length: '71'
        Content-Type: "text/plain"
      verify_response_with:
        function: ext.validator:validate_response
        extra_kwargs:
          expected_response: "CON Tafadhali weka pin mpya yenye nambari nne kwa akaunti yako\n0. Nyuma"
    delay_after: 5

  - name: Enter pin number [{first_account_pin_number} - first account]
    request:
      url: "{server_url}"
      data:
        serviceCode: "*483*46#"
        sessionId: "{first_metadata_entry_session_id}"
        phoneNumber: "{first_account_phone_number}"
        text: "1*{first_account_pin_number}"
      headers:
        content-type: "application/x-www-form-urlencoded"
      method: POST
    response:
      status_code:
        - 200
      headers:
        Content-Length: '44'
        Content-Type: "text/plain"
      verify_response_with:
        function: ext.validator:validate_response
        extra_kwargs:
          expected_response: "CON Enter your four number PIN again\n0. Back"
    delay_after: 5

  - name: Enter pin number [second_account_pin_number - second account]
    request:
      url: "{server_url}"
      data:
        serviceCode: "*483*46#"
        sessionId: "{second_metadata_entry_session_id}"
        phoneNumber: "{second_account_phone_number}"
        text: "2*{second_account_pin_number}"
      headers:
        content-type: "application/x-www-form-urlencoded"
      method: POST
    response:
      status_code:
        - 200
      headers:
        Content-Length: '31'
        Content-Type: "text/plain"
      verify_response_with:
        function: ext.validator:validate_response
        extra_kwargs:
          expected_response: "CON Weka PIN yako tena\n0. Nyuma"
    delay_after: 5

  - name: Pin number confirmation [first_account_pin_number - first account]
    request:
      url: "{server_url}"
      data:
        serviceCode: "*483*46#"
        sessionId: "{first_metadata_entry_session_id}"
        phoneNumber: "{first_account_phone_number}"
        text: "1*{first_account_pin_number}*{first_account_pin_number}"
      headers:
        content-type: "application/x-www-form-urlencoded"
      method: POST
    response:
      status_code:
        - 200
      headers:
        Content-Length: '51'
        Content-Type: "text/plain"
      verify_response_with:
        function: ext.validator:validate_response
        extra_kwargs:
          expected_response: "CON Balance {gift_value} {token_symbol}\n1. Send\n2. My Account\n3. Help"
    delay_before: 10

  - name: Pin number confirmation [{second_account_pin_number} - second account]
    request:
      url: "{server_url}"
      data:
        serviceCode: "*483*46#"
        sessionId: "{second_metadata_entry_session_id}"
        phoneNumber: "{second_account_phone_number}"
        text: "2*{second_account_pin_number}*{second_account_pin_number}"
      headers:
        content-type: "application/x-www-form-urlencoded"
      method: POST
    response:
      status_code:
        - 200
      headers:
        Content-Length: '56'
        Content-Type: "text/plain"
      verify_response_with:
        function: ext.validator:validate_response
        extra_kwargs:
          expected_response: "CON Salio {gift_value} {token_symbol}\n1. Tuma\n2. Akaunti yangu\n3. Usaidizi"
    delay_before: 10
