Explorar el Código

chore: mv db tests to correct project

Also tweak test so that errors aren't printed confusingly when tests
pass
Gabriel Horner hace 2 semanas
padre
commit
73f8dfc421
Se han modificado 2 ficheros con 34 adiciones y 44 borrados
  1. 34 1
      deps/db/test/logseq/db_test.cljs
  2. 0 43
      src/test/logseq/db_test.cljs

+ 34 - 1
deps/db/test/logseq/db_test.cljs

@@ -1,5 +1,5 @@
 (ns logseq.db-test
-  (:require [cljs.test :refer [deftest is]]
+  (:require [cljs.test :refer [deftest is testing]]
             [datascript.core :as d]
             [logseq.db :as ldb]
             [logseq.db.test.helper :as db-test]))
@@ -76,3 +76,36 @@
     (is (= nil
            (ldb/page-exists? @conn "movie" #{:logseq.class/Property}))
         "Class pages correctly not found for given class")))
+
+(deftest test-transact-with-multiple-tx-datoms
+  (testing "last write wins with same tx"
+    (let [conn (d/create-conn)]
+      (d/transact! conn [[:db/add -1 :property :v1]])
+      (let [tx (:max-tx @conn)]
+        (ldb/transact! conn
+                       [(d/datom 1 :property :v1 (inc tx) false)
+                        (d/datom 1 :property :v1 (inc tx) true)]))
+      (is (= :v1 (:property (d/entity @conn 1))))))
+  (testing "last write wins with different tx"
+    (let [conn (d/create-conn)]
+      (d/transact! conn [[:db/add -1 :property :v1]])
+      (let [tx (:max-tx @conn)]
+        (ldb/transact! conn
+                       [(d/datom 1 :property :v1 (inc tx) false)
+                        (d/datom 1 :property :v1 (+ tx 2) true)]))
+      (is (= :v1 (:property (d/entity @conn 1)))))))
+
+(deftest test-transact-with-temp-conn!
+  (testing "DB validation should be running after the whole transaction"
+    (let [conn (db-test/create-conn)]
+      (testing "#Task shouldn't be converted to property"
+        (is (thrown? js/Error
+                     (with-out-str (ldb/transact! conn [{:db/ident :logseq.class/Task
+                                                         :block/tags :logseq.class/Property}])))))
+      (ldb/transact-with-temp-conn!
+       conn
+       {}
+       (fn [temp-conn]
+         (ldb/transact! temp-conn [{:db/ident :logseq.class/Task
+                                    :block/tags :logseq.class/Property}])
+         (ldb/transact! temp-conn [[:db/retract :logseq.class/Task :block/tags :logseq.class/Property]]))))))

+ 0 - 43
src/test/logseq/db_test.cljs

@@ -1,43 +0,0 @@
-(ns logseq.db-test
-  (:require [cljs.test :refer [deftest is testing] :as t]
-            [datascript.core :as d]
-            [frontend.db.conn :as conn]
-            [frontend.test.helper :as test-helper]
-            [logseq.db :as ldb]))
-
-;; TODO: move tests to deps/db
-
-(t/use-fixtures :each
-  test-helper/db-based-start-and-destroy-db-map-fixture)
-
-(deftest test-transact-with-multiple-tx-datoms
-  (testing "last write wins with same tx"
-    (let [conn (d/create-conn)]
-      (d/transact! conn [[:db/add -1 :property :v1]])
-      (let [tx (:max-tx @conn)]
-        (ldb/transact! conn
-                       [(d/datom 1 :property :v1 (inc tx) false)
-                        (d/datom 1 :property :v1 (inc tx) true)]))
-      (is (= :v1 (:property (d/entity @conn 1))))))
-  (testing "last write wins with different tx"
-    (let [conn (d/create-conn)]
-      (d/transact! conn [[:db/add -1 :property :v1]])
-      (let [tx (:max-tx @conn)]
-        (ldb/transact! conn
-                       [(d/datom 1 :property :v1 (inc tx) false)
-                        (d/datom 1 :property :v1 (+ tx 2) true)]))
-      (is (= :v1 (:property (d/entity @conn 1)))))))
-
-(deftest test-transact-with-temp-conn!
-  (testing "DB validation should be running after the whole transaction"
-    (let [conn (conn/get-db false)]
-      (testing "#Task shouldn't be converted to property"
-        (is (thrown? js/Error (ldb/transact! conn [{:db/ident :logseq.class/Task
-                                                    :block/tags :logseq.class/Property}]))))
-      (ldb/transact-with-temp-conn!
-       conn
-       {}
-       (fn [temp-conn]
-         (ldb/transact! temp-conn [{:db/ident :logseq.class/Task
-                                    :block/tags :logseq.class/Property}])
-         (ldb/transact! temp-conn [[:db/retract :logseq.class/Task :block/tags :logseq.class/Property]]))))))