Add coercion tests for vector data-specs, 0.2.9

This commit is contained in:
Tommi Reiman 2018-11-21 16:02:04 +02:00
parent 8dc1e50c44
commit ed1c2b0c4f
2 changed files with 12 additions and 6 deletions

View file

@ -1,3 +1,9 @@
## 0.2.9 (2018-11-21)
## `reitit-spec`
* support for vector data-specs for request & response parameters by [Heikki Hämäläinen](https://github.com/hjhamala).
## 0.2.8 (2018-11-18)
## `reitit-core`

View file

@ -14,11 +14,11 @@
[["/schema" {:coercion reitit.coercion.schema/coercion}
["/:number/:keyword" {:parameters {:path {:number s/Int
:keyword s/Keyword}
:query (s/maybe {:int s/Int})}}]]
:query (s/maybe {:int s/Int, :ints [s/Int]})}}]]
["/spec" {:coercion reitit.coercion.spec/coercion}
["/:number/:keyword" {:parameters {:path {:number int?
:keyword keyword?}
:query (ds/maybe {:int int?})}}]]
:query (ds/maybe {:int int?, :ints [int?]})}}]]
["/none"
["/:number/:keyword" {:parameters {:path {:number int?
:keyword keyword?}}}]]]
@ -30,8 +30,8 @@
(is (= {:path {:keyword :abba, :number 1}, :query nil}
(coercion/coerce! m))))
(let [m (r/match-by-path r "/schema/1/abba")]
(is (= {:path {:keyword :abba, :number 1}, :query {:int 10}}
(coercion/coerce! (assoc m :query-params {:int "10"}))))))
(is (= {:path {:keyword :abba, :number 1}, :query {:int 10, :ints [1,2,3]}}
(coercion/coerce! (assoc m :query-params {"int" "10", "ints" ["1" "2" "3"]}))))))
(testing "throws with invalid input"
(let [m (r/match-by-path r "/schema/kikka/abba")]
(is (thrown? ExceptionInfo (coercion/coerce! m))))))
@ -42,8 +42,8 @@
(is (= {:path {:keyword :abba, :number 1}, :query nil}
(coercion/coerce! m))))
(let [m (r/match-by-path r "/schema/1/abba")]
(is (= {:path {:keyword :abba, :number 1}, :query {:int 10}}
(coercion/coerce! (assoc m :query-params {:int "10"}))))))
(is (= {:path {:keyword :abba, :number 1}, :query {:int 10, :ints [1,2,3]}}
(coercion/coerce! (assoc m :query-params {"int" "10", "ints" ["1" "2" "3"]}))))))
(testing "throws with invalid input"
(let [m (r/match-by-path r "/spec/kikka/abba")]
(is (thrown? ExceptionInfo (coercion/coerce! m))))))