浏览代码

fix: tests

Tienson Qin 5 天之前
父节点
当前提交
8d0c2f9887

+ 18 - 17
deps/db/src/logseq/db.cljs

@@ -70,14 +70,16 @@
               data))
           tx-data)))
 
-(defn assert-no-entities
+(defn entity->db-id
   [tx-data]
   (walk/prewalk
    (fn [f]
      (if (de/entity? f)
-       (throw (ex-info "ldb/transact! doesn't support Entity"
-                       {:entity f
-                        :tx-data tx-data}))
+       (if-let [id (:db/id f)]
+         id
+         (throw (ex-info "ldb/transact! doesn't support Entity"
+                         {:entity f
+                          :tx-data tx-data})))
        f))
    tx-data))
 
@@ -138,19 +140,18 @@
   ([repo-or-conn tx-data]
    (transact! repo-or-conn tx-data nil))
   ([repo-or-conn tx-data tx-meta]
-   (when (or (exists? js/process)
-             (and (exists? js/goog) js/goog.DEBUG))
-     (assert-no-entities tx-data))
-   (let [tx-data (map (fn [m]
-                        (if (map? m)
-                          (cond->
-                           (dissoc m :block/children :block/meta :block/top? :block/bottom? :block/anchor
-                                   :block/level :block/container :db/other-tx
-                                   :block/unordered)
-                            (not @*transact-fn)
-                            (dissoc :block.temp/load-status))
-                          m)) tx-data)
-         tx-data (->> (remove-temp-block-data tx-data)
+   (let [tx-data (->> tx-data
+                      entity->db-id
+                      (map (fn [m]
+                             (if (map? m)
+                               (cond->
+                                (dissoc m :block/children :block/meta :block/top? :block/bottom? :block/anchor
+                                        :block/level :block/container :db/other-tx
+                                        :block/unordered)
+                                 (not @*transact-fn)
+                                 (dissoc :block.temp/load-status))
+                               m)))
+                      (remove-temp-block-data)
                       (common-util/fast-remove-nils)
                       (remove empty?))
          delete-blocks-tx (when-not (string? repo-or-conn)

+ 0 - 2
deps/outliner/src/logseq/outliner/core.cljs

@@ -288,8 +288,6 @@
                   (dissoc :block/children :block/meta :block/unordered
                           :block.temp/ast-title :block.temp/ast-body :block/level :block.temp/load-status
                           :block.temp/has-children?)
-                  common-util/remove-nils
-
                   (fix-tag-ids db {:db-graph? db-based?}))
                (not collapse-or-expand?)
                block-with-updated-at)

+ 3 - 1
src/test/frontend/db/db_based_model_test.cljs

@@ -33,8 +33,10 @@
              ["class1" "class2"]))
            (set (map :block/title (model/get-all-classes repo)))))))
 
+;; TODO: Async test
 (deftest ^:fix-me get-class-objects-test
-  (let [opts {:redirect? false}
+  (let [opts {:class? true
+              :redirect? false}
         _ (test-helper/create-page! "class1" opts)
         class (db/get-case-page "class1")
         _ (test-helper/save-block! repo fbid "Block 1" {:tags ["class1"]})]

+ 6 - 3
src/test/frontend/test/helper.cljs

@@ -6,7 +6,7 @@
             [frontend.config :as config]
             [frontend.db :as db]
             [frontend.db.conn :as conn]
-            [frontend.handler.db-based.page :as db-page-handler]
+            [frontend.handler.db-based.property :as db-property-handler]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.file-based.repo :as file-repo-handler]
             [frontend.handler.file-based.status :as status]
@@ -189,7 +189,9 @@ This can be called in synchronous contexts as no async fns should be invoked"
      [;; page
       {:block/uuid page-uuid
        :block/name "test"
-       :block/title "Test"}
+       :block/title "Test"
+       ;; :block/tags #{:logseq.class/Page}
+       }
       ;; first block
       {:block/uuid first-block-uuid
        :block/page page-id
@@ -240,7 +242,8 @@ This can be called in synchronous contexts as no async fns should be invoked"
   [repo block-uuid content {:keys [tags]}]
   (editor-handler/save-block! repo block-uuid content)
   (doseq [tag tags]
-    (db-page-handler/add-tag repo block-uuid (db/get-page tag))))
+    (db-property-handler/set-block-property! block-uuid :block/tags
+                                             (db/get-page tag))))
 
 (defn create-page!
   [title & {:as opts}]