mirror of
https://github.com/logseq/logseq.git
synced 2026-05-23 12:14:06 +00:00
fix(cli): found by case block-upsert-update-id-custom-many-property-json
This commit is contained in:
@@ -595,6 +595,16 @@
|
||||
{}))))
|
||||
(p/resolved {})))
|
||||
|
||||
(defn- merge-fetched-property-value
|
||||
[existing value]
|
||||
(cond
|
||||
(nil? existing) value
|
||||
(= existing value) existing
|
||||
(sequential? existing) (if (some #(= % value) existing)
|
||||
existing
|
||||
(conj (vec existing) value))
|
||||
:else [existing value]))
|
||||
|
||||
(defn- fetch-user-properties
|
||||
[config repo block-ids]
|
||||
(if (seq block-ids)
|
||||
@@ -613,7 +623,7 @@
|
||||
(p/let [rows (transport/invoke config :thread-api/q false
|
||||
[repo [props-query ids (vec property-idents)]])]
|
||||
(reduce (fn [acc [block-id attr value]]
|
||||
(update acc block-id assoc attr value))
|
||||
(update-in acc [block-id attr] merge-fetched-property-value value))
|
||||
{}
|
||||
rows))
|
||||
{})))
|
||||
|
||||
@@ -72,3 +72,20 @@
|
||||
(is (false? (:ok? result)))
|
||||
(is (= :invalid-options (get-in result [:error :code])))
|
||||
(is (string/includes? (get-in result [:error :message]) "id")))))
|
||||
|
||||
(deftest test-merge-fetched-property-value
|
||||
(let [merge-value #'show-command/merge-fetched-property-value]
|
||||
(testing "first value is kept as scalar"
|
||||
(is (= "Step 1" (merge-value nil "Step 1"))))
|
||||
|
||||
(testing "second distinct value upgrades scalar to vector"
|
||||
(is (= ["Step 1" "Step 2"]
|
||||
(merge-value "Step 1" "Step 2"))))
|
||||
|
||||
(testing "additional values are appended"
|
||||
(is (= ["Step 1" "Step 2" "Step 3"]
|
||||
(merge-value ["Step 1" "Step 2"] "Step 3"))))
|
||||
|
||||
(testing "duplicate values are deduplicated"
|
||||
(is (= ["Step 1" "Step 2"]
|
||||
(merge-value ["Step 1" "Step 2"] "Step 2"))))))
|
||||
|
||||
Reference in New Issue
Block a user