---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_job:
      job_id: "jobs-get-1"
      body: "{\n  \"job_id\":\"jobs-get-1\",\n  \"description\":\"Job 1\",\n  \"analysis_config\"\
        \ : {\n      \"bucket_span\": \"300s\",\n      \"detectors\" :[{\"function\"\
        :\"count\"}]\n  },\n  \"data_description\" : {\n      \"format\":\"xcontent\"\
        ,\n      \"time_field\":\"time\",\n      \"time_format\":\"epoch\"\n  }\n\
        }\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_job:
      job_id: "jobs-get-2"
      body: "{\n  \"job_id\":\"jobs-get-2\",\n  \"description\":\"Job 2\",\n  \"analysis_config\"\
        \ : {\n      \"bucket_span\": \"600s\",\n      \"detectors\" :[{\"function\"\
        :\"metric\",\"field_name\":\"responsetime\",\"by_field_name\":\"airline\"\
        }]\n  },\n  \"data_description\" : {\n      \"format\" : \"xcontent\",\n \
        \     \"time_field\":\"time\",\n      \"time_format\":\"yyyy-MM-dd'T'HH:mm:ssX\"\
        \n  }\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test get job given missing job_id:
- do:
    catch: "missing"
    ml.get_jobs:
      job_id: "missing-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test get single job:
- do:
    ml.get_jobs:
      job_id: "jobs-get-1"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    jobs.0.job_id: "jobs-get-1"
- match:
    jobs.0.description: "Job 1"
- do:
    ml.get_jobs:
      job_id: "jobs-get-2"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    jobs.0.job_id: "jobs-get-2"
- match:
    jobs.0.description: "Job 2"
---
Test explicit get all jobs:
- do:
    ml.get_jobs:
      job_id: "_all"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    count: 2
- match:
    jobs.0.job_id: "jobs-get-1"
- match:
    jobs.0.description: "Job 1"
- match:
    jobs.1.job_id: "jobs-get-2"
- match:
    jobs.1.description: "Job 2"
---
Test implicit get all jobs:
- do:
    ml.get_jobs: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    count: 2
- match:
    jobs.0.job_id: "jobs-get-1"
- match:
    jobs.0.description: "Job 1"
- match:
    jobs.1.job_id: "jobs-get-2"
- match:
    jobs.1.description: "Job 2"
---
Test get job for export:
- do:
    ml.get_jobs:
      job_id: "jobs-get-1"
      exclude_generated: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    jobs.0.description: "Job 1"
- is_false: "job_type"
- is_false: "job_version"
- is_false: "create_time"
- is_false: "finished_time"
- is_false: "model_snapshot_id"
- is_false: "model_snapshot_min_version"
- is_false: "deleting"
