<commit_before>---
setup:
  - do:
      cluster.health:
          wait_for_status: yellow

---
teardown:
  - do:
      xpack.watcher.delete_watch:
        id: "test_watch"
        ignore: 404

---
"Test execute watch api with configured trigger data timestamps":
  - do:
      xpack.watcher.put_watch:
        id: "test_watch"
        body:  >
          {
            "trigger": {
              "schedule" : { "cron" : "0 0 0 1 * ? 2099" }
            },
            "input": {
              "simple": {
                "foo": "bar"
              }
            },
            "condition": {
              "always": {}
            },
            "actions": {
              "log" : {
                "logging" : {
                  "text" : "execute_watch/10.yaml payload: {{ctx.payload}}"
                }
              }
            }
          }
  - match: { _id: "test_watch" }
  - match: { created: true }

  - do:
      xpack.watcher.execute_watch:
        id: "test_watch"
        body: >
          {
            "trigger_data" : {
              "triggered_time" : "2012-12-12T12:12:12.120Z",
              "scheduled_time" : "2000-12-12T12:12:12.120Z"
            }
          }

  - match: { watch_record.watch_id: "test_watch" }
  - match: { watch_record.trigger_event.type: "manual" }
  - match: { watch_record.trigger_event.triggered_time: "2012-12-12T12:12:12.120Z" }
  - match: { watch_record.trigger_event.manual.schedule.scheduled_time: "2000-12-12T12:12:12.120Z" }
  - match: { watch_record.state: "executed" }<commit_msg>Watcher: Add REST test for execute watch API<commit_after>---
setup:
  - do:
      cluster.health:
          wait_for_status: yellow

---
teardown:
  - do:
      xpack.watcher.delete_watch:
        id: "test_watch"
        ignore: 404

---
"Test execute watch api with configured trigger data timestamps":
  - do:
      xpack.watcher.put_watch:
        id: "test_watch"
        body:  >
          {
            "trigger": {
              "schedule" : { "cron" : "0 0 0 1 * ? 2099" }
            },
            "input": {
              "simple": {
                "foo": "bar"
              }
            },
            "condition": {
              "always": {}
            },
            "actions": {
              "log" : {
                "logging" : {
                  "text" : "execute_watch/10.yaml payload: {{ctx.payload}}"
                }
              }
            }
          }
  - match: { _id: "test_watch" }
  - match: { created: true }

  - do:
      xpack.watcher.execute_watch:
        id: "test_watch"
        body: >
          {
            "trigger_data" : {
              "triggered_time" : "2012-12-12T12:12:12.120Z",
              "scheduled_time" : "2000-12-12T12:12:12.120Z"
            }
          }

  - match: { watch_record.watch_id: "test_watch" }
  - match: { watch_record.trigger_event.type: "manual" }
  - match: { watch_record.trigger_event.triggered_time: "2012-12-12T12:12:12.120Z" }
  - match: { watch_record.trigger_event.manual.schedule.scheduled_time: "2000-12-12T12:12:12.120Z" }
  - match: { watch_record.state: "executed" }

---
"Execute unknown watch results in 404":

  - do:
      xpack.watcher.execute_watch:
        id: "non-existent-watch"
      catch: missing
{'fraction_non_alphanumeric': 0.1416256157635468, 'fraction_numerical': 0.05080049261083744, 'mean_word_length': 1.4391891891891893, 'pattern_counts': {'":': 17, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3145116', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1068, 'n_words': 177}