This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-22
Channels
- # aleph (18)
- # announcements (4)
- # babashka (72)
- # beginners (63)
- # biff (5)
- # calva (146)
- # cider (5)
- # clj-kondo (18)
- # cljsrn (28)
- # cljtogether (3)
- # clojure (95)
- # clojure-berlin (2)
- # clojure-europe (34)
- # clojure-nl (2)
- # clojure-norway (3)
- # clojure-uk (3)
- # community-development (7)
- # conjure (1)
- # cursive (2)
- # data-science (5)
- # datalevin (9)
- # datomic (17)
- # events (2)
- # figwheel-main (5)
- # fulcro (6)
- # helix (8)
- # hyperfiddle (52)
- # jobs (1)
- # malli (14)
- # off-topic (32)
- # polylith (24)
- # remote-jobs (7)
- # scittle (3)
- # shadow-cljs (13)
- # slack-help (3)
- # spacemacs (3)
- # vim (2)
- # xtdb (6)
Is it possible to unit test biff/submit-tx
?
I'm trying this
(defn test-node [docs]
(let [node (xt/start-node {})]
(when (not-empty docs)
(xt/await-tx
node
(xt/submit-tx node
(vec
(concat
(for [d docs]
[::xt/put (merge {:xt/id (random-uuid)}
d)])
(for [[k f] biff/tx-fns]
[::xt/put {:xt/id k :xt/fn f}]))))))
node))
(defn get-sys [node]
{:biff/db (xt/db node)
:biff.xtdb/retry false
:biff.xtdb/node node
:biff/now #inst "1970"})
(def test-docs [{:xt/id :user/alice
:user/email ""}])
(with-open [node (test-node test-docs)]
(let [sys (get-sys node)]
(biff/submit-tx sys [{:db/doc-type :user
:db/op :upsert
:xt/id :user/alice
:user/email "[email protected]"}])))
But I'm getting this error:
=> Execution error (NullPointerException) at com.biffweb.impl.xtdb/biff-op->xt$valid? (xtdb.clj:231).
Cannot invoke "java.util.concurrent.Future.get()" because "fut" is null
yes, this general approach works. It looks like you're just missing the :biff/malli-opts
key. See the XT unit tests in the biff repo: https://github.com/jacobobryant/biff/blob/master/test/com/biffweb/impl/xtdb_test.clj#L109. Also note the (poetically named) biff/biff-tx->xt
function, which you can use to see the underlying XT transaction that Biff transactions get converted to, https://github.com/jacobobryant/biff/blob/master/test/com/biffweb/impl/xtdb_test.clj#L124.
I really need to get add some parameter validation to Biff's functions so you get a better error message than Cannot invoke "java.util.concurrent.Future.get()" because "fut" is null
:face_palm:
(That snippet from the biff repo doesn't set :biff.xtdb/node
since none of my tests actually call submit-tx
, but assuming you are planning to call submit-tx
, you should leave that in as you've done)
Ah, thank you! I've got it working now! I also got tripped up previously by passing the malli registry without #'
great! I should probably make that work whether you pass it a var or just the data