Skip to content

Commit

Permalink
Change validation of map-with-keys and optional value realms.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Frese committed Apr 26, 2024
1 parent 8656c46 commit 76e673b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/active/data/realm/schema.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@
(into {}
(map (fn [[key realm]]
(if (realm-inspection/optional? realm)
;; make both keys and value optional - (:key {}) == (:key {:key nil})
[(schema/optional-key key)
(schema (realm-inspection/optional-realm-realm realm))]
(schema realm)]
[(schema/required-key key)
(schema realm)]))
(realm-inspection/map-with-keys-realm-map realm)))
Expand Down
7 changes: 7 additions & 0 deletions test/active/data/realm/validation_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@
(realm-validation/checking
(twoify "7")))))

(deftest key-value-optional-test
;; optional value realm results in both optional value and optional key schema
(let [map-realm (realm/map-with-keys {:key (realm/optional realm/string)})
check (realm-validation/validator map-realm)]
(is (= {:key nil} (check {:key nil})))
(is (= {} (check {})))
(is (= {:key "foo"} (check {:key "foo"})))))

0 comments on commit 76e673b

Please sign in to comment.