fix(cli): found by case block-upsert-update-id-custom-many-property-json

This commit is contained in:
rcmerci
2026-03-22 16:09:53 +08:00
parent c5995a6652
commit 791b3e98f7
2 changed files with 28 additions and 1 deletions

View File

@@ -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))
{})))

View File

@@ -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"))))))