diff --git a/api/src/wfl/api/spec.clj b/api/src/wfl/api/spec.clj index d71dfe65e..5a37d9630 100644 --- a/api/src/wfl/api/spec.clj +++ b/api/src/wfl/api/spec.clj @@ -139,7 +139,8 @@ ::column ::dataset ::table - ::snapshotReaders])) + ::snapshotReaders] + :opt-un [::snapshots])) (s/def ::snapshot-list-source (s/keys :req-un [::name ::snapshots])) diff --git a/api/test/wfl/integration/modules/covid_test.clj b/api/test/wfl/integration/modules/covid_test.clj index 8360bc2fc..e105121db 100644 --- a/api/test/wfl/integration/modules/covid_test.clj +++ b/api/test/wfl/integration/modules/covid_test.clj @@ -3,6 +3,10 @@ (:require [clojure.test :refer :all] [clojure.spec.alpha :as s] [clojure.string :as str] + [reitit.coercion.spec] + [reitit.ring :as ring] + [reitit.ring.coercion :as coercion] + [wfl.api.spec :as spec] [wfl.api.spec :as spec] [wfl.integration.modules.shared :as shared] [wfl.jdbc :as jdbc] @@ -643,3 +647,47 @@ {:skipValidation true} {:skipValidation true} {:skipValidation true})))) + +(defn ^:private create-app [input-spec output-spec handler] + (let [app + (ring/ring-handler + (ring/router + [["/test" {:post {:parameters {:body input-spec} + :responses {200 {:body output-spec}} + :handler (fn [{:keys [body-params]}] + {:status 200 + :body (handler body-params)})}}]] + {:data {:coercion reitit.coercion.spec/coercion + :middleware [coercion/coerce-exceptions-middleware + coercion/coerce-request-middleware + coercion/coerce-response-middleware]}}))] + (fn [request] + (app {:request-method :post + :uri "/test" + :body-params request})))) + +(deftest test-create-workload-coercion + (let [app (create-app ::spec/workload-request + ::spec/workload-response + (comp util/to-edn workloads/create-workload!)) + request (workloads/covid-workload-request + {} + {:skipValidation true} + {:skipValidation true})] + (testing "Workload with a TDR Source" + (let [{:keys [status body]} + (->> {:name "Terra DataRepo" + :dataset testing-dataset + :table testing-table-name + :column testing-column-name + :snapshotReaders ["workflow-launcher-dev@firecloud.org"]} + (assoc request :source) + app)] + (is (== 200 status) body))) + (testing "Workload with a TDR Snapshots Source" + (let [{:keys [status body]} + (->> {:name "TDR Snapshots" + :snapshots [testing-snapshot]} + (assoc request :source) + app)] + (is (== 200 status) body)))))