|
8 | 8 | (d/conn-from-db |
9 | 9 | (d/init-db |
10 | 10 | #{(d/datom 3 :todo/project 2) |
11 | | - (d/datom 2 :project/name "abc")} |
| 11 | + (d/datom 2 :project/name "abc") |
| 12 | + (d/datom 4 :project/name "xyz") |
| 13 | + (d/datom 4 :project/number 23) |
| 14 | + (d/datom 4 :project/completed? true) |
| 15 | + (d/datom 5 :project/name "abc") |
| 16 | + (d/datom 6 :project/name "p4")} |
12 | 17 | {:todo/project {:db/valueType :db.type/ref |
13 | 18 | :db/cardinality :db.cardinality/one}}))) |
14 | 19 |
|
|
110 | 115 | "$where" {"item" {"name" "$any"}}}) |
111 | 116 | (d/create-conn)))) |
112 | 117 | (is (array? (hbjs/q (clj->js "[:find ?e :where [?e :item/name]]") (d/create-conn))))) |
| 118 | + (testing "$any" |
| 119 | + (is (= 4 (count (hbjs/q (clj->js {"$find" "project" |
| 120 | + "$where" {"project" {"name" "$any"}}}) |
| 121 | + test-conn))))) |
| 122 | + (testing "filter by string" |
| 123 | + (is (= 2 (count (hbjs/q (clj->js {"$find" "project" |
| 124 | + "$where" {"project" {"name" "abc"}}}) |
| 125 | + test-conn))))) |
| 126 | + (testing "filter by bool" |
| 127 | + (is (= 1 (count (hbjs/q (clj->js {"$find" "project" |
| 128 | + "$where" {"project" {"isCompleted" true}}}) |
| 129 | + test-conn))))) |
| 130 | + (testing "filter by number" |
| 131 | + (is (= 1 (count (hbjs/q (clj->js {"$find" "project" |
| 132 | + "$where" {"project" {"number" 23}}}) |
| 133 | + test-conn))))) |
| 134 | + (testing "filter by multiple" |
| 135 | + (is (= 1 (count (hbjs/q (clj->js {"$find" "project" |
| 136 | + "$where" {"project" {"number" 23 "isCompleted" true}}}) |
| 137 | + test-conn)))) |
| 138 | + (is (= 0 (count (hbjs/q (clj->js {"$find" "project" |
| 139 | + "$where" {"project" {"number" 23 "isCompleted" false}}}) |
| 140 | + test-conn))))) |
113 | 141 | (testing "should fail with humanized errors" |
114 | 142 | (is (thrown-with-msg? |
115 | 143 | js/Error |
|
145 | 173 | #"(?s)Expected \$where clause to be a nested object, not 1.*For example:" |
146 | 174 | (hbjs/q (clj->js {"$find" "todo" |
147 | 175 | "$where" {"todo" 1}}) (d/create-conn)))) |
| 176 | + (is (thrown-with-msg? |
| 177 | + js/Error |
| 178 | + #"(?s)Expected \$where clause to be a nested object, not yolo.*For example:" |
| 179 | + (hbjs/q (clj->js {"$find" "todo" |
| 180 | + "$where" {"todo" "yolo"}}) (d/create-conn)))) |
148 | 181 | (is (thrown-with-msg? |
149 | 182 | js/Error |
150 | 183 | #"(?s)Cannot parse :find, expected: \(find-rel \| find-coll \| find-tuple \| find-scalar\)" |
|
0 commit comments