Jelajahi Sumber

refactor: keep testing concerns in tests

Move testing requirement to relevant test to make production code easier
to maintain. Where possible we should avoid helpers like util/node-test? as
they couple testing concerns with production code
Gabriel Horner 6 bulan lalu
induk
melakukan
6042c8b112

+ 2 - 7
src/main/frontend/db/query_dsl.cljs

@@ -732,13 +732,8 @@ Some bindings in this fn:
 
 (def db-block-attrs
   "Block attributes for db graph queries"
-  ;; '*' needed as we need to pull user properties and don't know their names in advance
-  (if util/node-test?
-    '[*
-      {:block/page [:db/id :block/name :block/title :block/journal-day]}
-      {:block/_parent ...}]
-    ;; db graphs needs :db/id only for query view
-    [:db/id]))
+  ;; only needs :db/id for query/view
+  [:db/id])
 
 (defn query
   "Runs a dsl query with query as a string. Primary use is from '/query' or '{{query }}'"

+ 13 - 3
src/test/frontend/db/query_dsl_test.cljs

@@ -18,6 +18,12 @@
 ;; Test helpers
 ;; ============
 
+(def db-block-attrs
+  ;; '*' needed as we need to pull user properties and don't know their names in advance
+  '[*
+    {:block/page [:db/id :block/name :block/title :block/journal-day]}
+    {:block/_parent ...}])
+
 (def dsl-query*
   "Overrides dsl-query/query with ENV variables. When $EXAMPLE is set, prints query
   result of build query. This is useful for documenting examples and debugging.
@@ -48,10 +54,13 @@
                                     :query (apply list 'has-property (rest (:query m)))}
                                    :else
                                    m)]
-                          m'))]
+                          m'))
+                      query-dsl/db-block-attrs db-block-attrs]
           (apply query-dsl/query args))))
     :else
-    query-dsl/query))
+    (fn dsl-query-star [& args]
+      (with-redefs [query-dsl/db-block-attrs db-block-attrs]
+        (apply query-dsl/query args)))))
 
 (defn- ->smart-query
   "Updates to file version if js/process.env.DB_GRAPH is not set"
@@ -70,7 +79,8 @@
 (defn- custom-query
   [query]
   (db/clear-query-state!)
-  (when-let [result (query-dsl/custom-query test-helper/test-db query {})]
+  (when-let [result (with-redefs [query-dsl/db-block-attrs db-block-attrs]
+                      (query-dsl/custom-query test-helper/test-db query {}))]
     (map first (deref result))))
 
 ;; Tests