Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
[GH-1356] Fix Coercion Failure for TDR Snapshots Source (#429)
Browse files Browse the repository at this point in the history
RR: https://broadinstitute.atlassian.net/browse/GH-1356
Caused by metosin/reitit#494
Fix as per https://broadinstitute.atlassian.net/browse/GH-1348

Included integration test for reitit coercions to catch this sooner.
  • Loading branch information
ehigham committed Jun 9, 2021
1 parent 6ca1393 commit a6c1884
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion api/src/wfl/api/spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@
::column
::dataset
::table
::snapshotReaders]))
::snapshotReaders]
:opt-un [::snapshots]))

(s/def ::snapshot-list-source
(s/keys :req-un [::name ::snapshots]))
Expand Down
48 changes: 48 additions & 0 deletions api/test/wfl/integration/modules/covid_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 ["[email protected]"]}
(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)))))

0 comments on commit a6c1884

Please sign in to comment.