   {:functional true}
   (:require [akvo.lumen.fixtures :refer [*system* system-fixture *tenant-conn* tenant-conn-fixture *error-tracker* error-tracker-fixture]]
             [akvo.lumen.protocols :as p]
+            [clojure.string :as str]
             [cheshire.core :as json]
             [clojure.java.io :as io]
             [clojure.test :refer :all]

(def tenant-host "http://t1.lumen.local:3030")

(defn api-url [api-url & args]
  (str  "/api" api-url (when args (str "/" (apply str args)))))

(defn with-body [method uri body & [query-params]]
  (cond->

       :headers {"host" "t1.lumen.local:3030" "content-type" "application/json"}
       :uri uri}
    query-params (assoc :query-params query-params)))

(defn job-execution-dataset-id [h job-id]
  (dh/with-retry {:retry-if (fn [v e] (not v))
                                         :max-retries 20
                                         :delay-ms 100}
                           (let [job (-> (h (get* (api-url "/job_executions" job-id)))
                                         :body (json/parse-string keyword))
                                 status (:status job)]
                             (when (= "OK" status)
                               (:datasetId job)))))

(def dataset-link-columns [{:key false,
                            :type "text",
                            :title "Name",
                            :multipleId nil,
                            :hidden false,
                            :multipleType nil,
                            :columnName "c1",
                            :direction nil,
                            :sort nil}
                           {:key false,
                            :type "number",
                            :title "Age",
                            :multipleId nil,
                            :hidden false,
                            :multipleType nil,
                            :columnName "c2",
                            :direction nil,
                            :sort nil}
                           {:key false,
                            :type "number",
                            :title "Score",
                            :multipleId nil,
                            :hidden false,
                            :multipleType nil,
                            :columnName "c3",
                            :direction nil,
                            :sort nil}
                           {:key false,
                            :type "number",
                            :title "Temperature",
                            :multipleId nil,
                            :hidden false,
                            :multipleType nil,
                            :columnName "c4",
                            :direction nil,
                            :sort nil}
                           {:key false,
                            :type "number",
                            :title "Humidity",
                            :multipleId nil,
                            :hidden false,
                            :multipleType nil,
                            :columnName "c5",
                            :direction nil,
                            :sort nil}
                           {:key false,
                            :type "text",
                            :title "Cat",
                            :multipleId nil,
                            :hidden false,
                            :multipleType nil,
                            :columnName "c6",
                            :direction nil,
                            :sort nil}])

(deftest handler-test
  (let [h (:handler (:akvo.lumen.component.handler/handler *system*))]
