name: Check autoregister node
testcases:
- name: get_login_token
  steps:
  - type: get_login_token

- name: check_autoregister_node
  steps:
  - type: http
    method: GET
    url: '{{.pfserver_webadmin_url}}/api/v1/node/{{.node01_ens7_mac_address_url_encoded}}'
    ignore_verify_ssl: true
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 200
      - result.bodyjson.item.autoreg ShouldEqual yes
      - result.bodyjson.item.category ShouldEqual "{{.wired_dot1x_eap_tls_scep.roles.dot1x_eap_tls.id}}"
      - result.bodyjson.item.pid ShouldEqual "{{.wired_dot1x_eap_tls_scep.certs.user.other_name}}"
      - result.bodyjson.item.status ShouldEqual reg
    vars:
      regdate:
        from: result.bodyjson.item.regdate
      unregdate:
        from: result.bodyjson.item.unregdate

# temp, need a feature in Venom assertion available in 1.0.0 (ShouldHappenBetween)
# convert 5m to 5minutes
# In order to calculate unregdate based on regdate + 5minutes using date command (next testcase)
# - name: convert_access_duration
#   steps:
#   - type: exec
#     script: |
#       perl -I/usr/local/pf/lib -I/usr/local/pf/lib_perl/lib/perl5 -Mpf::config::util \
#       -e 'my @times = get_translatable_time("{{.wired_dot1x_eap_tls_scep.sources.eaptls.access_duration}}"); print("$times[2]$times[1]");'
#     vars:
#       translatable_time:
#         from: result.systemout

# - name: check_unregdate_match_access_duration
#   steps:
#   - type: exec
#     script: "date '+%Y-%m-%d %H:%M:%S' --date='{{.check_autoregister_node.regdate}} {{.convert_access_duration.translatable_time}}'"
#     assertions:
#       - result.systemout ShouldEqual "{{.check_autoregister_node.unregdate}}"
