|
16 | 16 |
|
17 | 17 | (testing "Numbers are not valid input" |
18 | 18 | (is (thrown-with-msg? Exception #"Unsupported Schema input" |
19 | | - (json/validate 1 2))) |
| 19 | + (json/validate 1 2))) |
20 | 20 | (is (thrown-with-msg? Exception #"Unsupported Schema input" |
21 | 21 | (json/validate 1 "2"))) |
22 | 22 | (is (thrown-with-msg? Exception #"Unsupported Schema input" |
23 | 23 | (json/validate "1" 2)))) |
24 | | - |
| 24 | + |
25 | 25 | (testing "Schema has to be a map" |
26 | 26 | (is (thrown-with-msg? Exception #"Unsupported Schema input" |
27 | 27 | (json/validate "1" "2")))) |
28 | | - |
| 28 | + |
29 | 29 | (testing "JSON has to be a map or an array" |
30 | 30 | (is (thrown-with-msg? Exception #"Unsupported JSON input" |
31 | 31 | (json/validate schema "1")))) |
32 | | - |
| 32 | + |
33 | 33 | (testing "ID has to be a number" |
34 | 34 | (is (thrown? RuntimeException (json/validate schema "{\"id\" : \"1\"}")))) |
35 | | - |
| 35 | + |
36 | 36 | (testing "Valid input as JSON string" |
37 | 37 | (let [data "{\"id\": 1}"] (is (= data (json/validate schema data))))) |
38 | | - |
| 38 | + |
39 | 39 | (testing "Valid input as EDN" |
40 | 40 | (let [data {:id 1}] (is (= data (json/validate schema data))))) |
41 | 41 |
|
|
75 | 75 | schema (json/prepare-schema json-schema-edn) |
76 | 76 | json-edn-valid {:id 0.001} |
77 | 77 | json-edn-invalid {:id 0}] |
78 | | - |
| 78 | + |
79 | 79 | (testing "valid input VALIDATES" |
80 | | - (is (= json-edn-valid (json/validate schema json-edn-valid)))) |
| 80 | + (is (= json-edn-valid (json/validate schema json-edn-valid)))) |
81 | 81 |
|
82 | 82 | (testing "valid input does NOT validate" |
83 | 83 | (is (thrown? |
|
116 | 116 | json-str-valid "[{\"some\":\"data\"}]" |
117 | 117 | json-edn-valid [{:some "data"}] |
118 | 118 | json-edn-invalid {:some "data"}] |
119 | | - |
| 119 | + |
120 | 120 | (testing "valid JSON string input VALIDATES" |
121 | | - (is (= json-str-valid (json/validate schema json-str-valid)))) |
| 121 | + (is (= json-str-valid (json/validate schema json-str-valid)))) |
122 | 122 |
|
123 | 123 | (testing "valid EDN input VALIDATES" |
124 | 124 | (is (= json-edn-valid (json/validate schema json-edn-valid)))) |
|
161 | 161 | Exception |
162 | 162 | #"JSON Validation error" |
163 | 163 | (json/validate schema invalid-input))))))))) |
| 164 | + |
| 165 | +(deftest validate-list |
| 166 | + (testing "Validate EDN list as JSON array" |
| 167 | + (let [schema (json/prepare-schema {:$schema "http://json-schema.org/draft-04/schema" |
| 168 | + :type "array"})] |
| 169 | + |
| 170 | + (testing "Valid input as EDN vector" |
| 171 | + (is (= ["a" "b"] (json/validate schema ["a" "b"])))) |
| 172 | + |
| 173 | + (testing "Valid input as EDN list" |
| 174 | + (is (= '("a" "b") (json/validate schema '("a" "b")))))))) |
0 commit comments