|
232 | 232 | (is (= {:x "kikka"} (m/encode [:map [:x keyword?]] {:x :kikka, :y :kukka} strict-json-transformer))))) |
233 | 233 |
|
234 | 234 | (let [transformer (mt/transformer |
235 | | - mt/string-transformer |
236 | | - mt/strip-extra-keys-transformer |
237 | 235 | (mt/key-transformer |
238 | | - {:decode #(-> % name (str "_key") keyword) |
239 | | - :encode #(-> % name (str "_key"))}))] |
| 236 | + {:decode #(-> % (subs 4) keyword) |
| 237 | + :encode #(->> % name (str "key_"))}) |
| 238 | + (mt/string-transformer) |
| 239 | + (mt/strip-extra-keys-transformer))] |
240 | 240 | (testing "decode" |
241 | | - (is (= {:x_key 18 :y_key "john"} |
| 241 | + (is (= {:x 18 :y "john"} |
242 | 242 | (m/decode |
243 | 243 | [:map [:x int?] [:y string?] [[:opt :z] boolean?]] |
244 | | - {:x "18" :y "john" :a "doe"} |
| 244 | + {"key_x" "18" "key_y" "john" "key_a" "doe"} |
245 | 245 | transformer)))) |
246 | 246 | (testing "encode" |
247 | | - (is (= {"x_key" "18" "y_key" "john"} |
| 247 | + (is (= {"key_x" "18" "key_y" "john"} |
248 | 248 | (m/encode |
249 | 249 | [:map [:x int?] [:y string?] [[:opt :z] boolean?]] |
250 | 250 | {:x 18 :y "john" :a "doe"} |
|
283 | 283 | (is (= {"x_key" 18 "y_key" "john" "a_key" "doe"} |
284 | 284 | (m/encode [:map [:x int?] [:y string?] [[:opt :z] boolean?]] |
285 | 285 | {:x 18 :y "john" :a "doe"} |
286 | | - key-transformer)))))) |
| 286 | + key-transformer))))) |
| 287 | + |
| 288 | + (testing "from strings and back" |
| 289 | + (let [schema [:map |
| 290 | + [:id :string] |
| 291 | + [:github-followers pos-int?]] |
| 292 | + transformer (mt/transformer |
| 293 | + (mt/key-transformer {:decode keyword, :encode name}) |
| 294 | + (mt/string-transformer)) |
| 295 | + value {"id" "123", "github-followers" "10"}] |
| 296 | + (is (= {:id "123", :github-followers 10} |
| 297 | + (as-> value $ (m/decode schema $ transformer)))) |
| 298 | + (is (= value |
| 299 | + (as-> value $ (m/decode schema $ transformer) (m/encode schema $ transformer))))))) |
287 | 300 |
|
288 | 301 | (deftest interceptor-style-transformers |
289 | 302 | (testing "map" |
|
0 commit comments