Skip to content

Commit

Permalink
Added unit testing for PUT and DELETE gene update-other-names API end…
Browse files Browse the repository at this point in the history
…points
  • Loading branch information
mluypaert committed Oct 2, 2020
1 parent fdddbb9 commit eda2c93
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
38 changes: 38 additions & 0 deletions test/integration/update_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require
[clojure.spec.gen.alpha :as gen]
[clojure.test :as t]
[clojure.set :as cset]
[datomic.api :as d]
[ring.util.http-predicates :as ru-hp]
[wormbase.constdata :refer [basic-prov]]
Expand Down Expand Up @@ -231,6 +232,43 @@
(t/is (not= orig-cgc-name (:gene/cgc-name ent)))
(t/is (= new-cgc-name (:gene/cgc-name ent)))))))))

(t/deftest update-other-names-gene
(t/testing "Testing successful addition to / removal from gene's other-names."
(let [gid (first (gen/sample gsg/id 1))
sample* (first (tu/gen-sample gsg/uncloned 1))
sample (-> sample*
(wnu/qualify-keys "gene")
(tu/species->ref)
(select-keys [:gene/other-names]))
sample-data (assoc sample
:gene/id gid
:gene/other-names (gsg/gen-other-names 2))]
(tu/with-gene-fixtures
[sample-data]
(fn [_]
; Test successful PUT /gene/*/update-other-names operation
(let [original-other-names (:gene/other-names sample-data)
add-names (gsg/gen-other-names 2)
payload {:data add-names :prov nil}
response (api-tc/add-other-names "gene" gid payload)]
(t/is (ru-hp/ok? response))
; Compare successful PUT /gene/*/update-other-names operation return value to expected results
(let [add-result (some-> response :body)
expected-add-result (distinct (concat original-other-names add-names))]
(t/is (= (set add-result) (set expected-add-result)) (pr-str add-result))
; Test successful DELETE /gene/*/update-other-names operation
(let [n (- (count add-result) 1)
retract-names (take n (shuffle add-result))
payload {:data retract-names :prov nil}
response (api-tc/retract-other-names "gene" gid payload)]
(t/is (ru-hp/ok? response))
; Compare successful DELETE /gene/*/update-other-names operation return value to expected results
(let [retract-result (some-> response :body)
expected-retract-result (cset/difference (set add-result) (set retract-names))]
(t/is (= (set retract-result) (set expected-retract-result)) (pr-str retract-result))
(t/is (= (count retract-result) 1) "Unexpected gene retract other-names result-size"))
))))))))

(t/deftest variation-data-must-meet-spec
(let [identifier (first (gen/sample gsv/id 1))
sample {:variation/name (first (gen/sample gsv/name 1))
Expand Down
10 changes: 10 additions & 0 deletions test/wormbase/api_test_client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
:or {current-user default-user}}]
(send-request entity-kind :put data :sub-path identifier :current-user current-user))

(defn add-other-names
[entity-kind identifier data & {:keys [current-user]
:or {current-user default-user}}]
(send-request entity-kind :put data :sub-path (str identifier "/update-other-names") :current-user current-user))

(defn retract-other-names
[entity-kind identifier data & {:keys [current-user]
:or {current-user default-user}}]
(send-request entity-kind :delete data :sub-path (str identifier "/update-other-names") :current-user current-user))

(defn summary
[entity-kind identifier & {:keys [params extra-headers]
:or {params {}
Expand Down
9 changes: 8 additions & 1 deletion test/wormbase/gen_specs/gene.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
[wormbase.specs.agent :as wna]
[wormbase.specs.gene :as wsg]
[wormbase.specs.species]
[wormbase.gen-specs.util :as util])
[wormbase.gen-specs.util :as util]
[clojure.string :as str])
(:refer-clojure :exclude [identity update]))

(s/def ::non-blank-string (s/and string? (complement str/blank?)))

(defn species-vals [species-kw]
(->> (util/load-seed-data)
(filter species-kw)
Expand Down Expand Up @@ -45,6 +48,10 @@

(def cgc-name (one-of-name-regexps :species/cgc-name-pattern))

(defn gen-other-names
[n]
(gen/sample (s/gen ::non-blank-string) n))

(s/def ::species-id
(s/with-gen
:gene/species
Expand Down

0 comments on commit eda2c93

Please sign in to comment.