   {: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]

                            (json/parse-string keyword)
                            :importId)
              _           (is (some? import-id))
              dataset-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" import-id)))
                                         :body (json/parse-string keyword))
                                 status (:status job)]
                             (when (= "OK" status)
                               (:datasetId job))))]
          (let [dataset (-> (h (get* (api-url "/datasets" dataset-id)))
                            :body (json/parse-string keyword))]
            (is (= {:transformations []
                    :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}]
                    :name title
                    ;;                :modified 1551089874635,
                    ;;                :author nil,
                    :rows
                    [["Bob" 22.0 2.0 4.0 7.0 "A"]
                     ["Jane" 34.0 4.0 8.0 2.0 "B"]

       :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*))]
