Skip to content

Commit

Permalink
SQL-211 make identityPaths fuzzier (#356)
Browse files Browse the repository at this point in the history
* SQL-211 make identityPaths fuzzier

* SQL-211 please linter
  • Loading branch information
milt authored Jan 11, 2024
1 parent 95a586c commit 5281315
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/main/lrsql/util/reaction.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,23 @@

(defn statement-identity
"Given a vector of identity paths and a statement, return a map of paths to
values. Return nil if any are missing or a collection is found."
values. Return nil if no specified paths or a collection is found."
[identity-paths
statement]
(reduce
(fn [m path]
(if-some [found-val (get-in statement
path)]
(if (coll? found-val)
(reduced nil)
(assoc m path found-val))
(reduced nil)))
{}
identity-paths))
(if (empty? identity-paths)
{} ;; empty explicitly covers all statements
(let [found-paths (reduce
(fn [m path]
(if-some [found-val (get-in statement
path)]
(if (coll? found-val)
(reduced nil)
(assoc m path found-val))
m))
{}
identity-paths)]
(when (seq found-paths)
found-paths))))

(s/fdef add-reaction-metadata
:args (s/cat :statement ::xs/statement
Expand Down
15 changes: 14 additions & 1 deletion src/test/lrsql/util/reaction_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,27 @@
[["actor" "mbox"]]
{["actor" "mbox"] "mailto:bob@example.com"}

[["actor" "mbox"]
["actor" "mbox_sha1sum"]
["actor" "openid"]
["actor" "account" "homePage"]
["actor" "account" "name"]]
{["actor" "mbox"] "mailto:bob@example.com"}

[["actor" "mbox"]
["context" "registration"]]
{["actor" "mbox"] "mailto:bob@example.com"
["context" "registration"] "6fbd600f-d17c-4c74-801a-2ec2e53231f7"}

[["actor" "openid"]
["context" "registration"]]
nil))
{["context" "registration"] "6fbd600f-d17c-4c74-801a-2ec2e53231f7"}

[["actor" "openid"]]
nil

[]
{}))

(deftest add-reaction-metadata-test
(let [reaction-id (u/generate-squuid)
Expand Down

0 comments on commit 5281315

Please sign in to comment.