-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2665a72
commit 1d92648
Showing
3 changed files
with
56 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -736,6 +736,24 @@ | |
[:xtdb.api/fn :biff/ensure-unique {:user/name \"example\"}]])" | ||
bxt/tx-fns) | ||
|
||
(defn test-xtdb-node | ||
"Returns an in-memory node that's initialized with the given docs and with biff/tx-fns. | ||
Each element of docs will be given a random UUID for :xt/id, unless you | ||
supply one. The docs are inserted with :xtdb.api/put operations, i.e. they're | ||
inserted verbatim without schema checking or any other biff/submit-tx | ||
features. | ||
Example: | ||
(deftest my-test | ||
(with-open [node (test-xtdb-node [{:user/email \"[email protected]\"} | ||
{:user/email \"[email protected]\"}])] | ||
(let [db (xt/db node)] | ||
...)))" | ||
[docs] | ||
(bxt/test-node docs)) | ||
|
||
;;;; Rum | ||
|
||
(defn render | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
(ns com.biffweb.impl.xtdb-test | ||
(:require [clojure.test :refer [deftest is]] | ||
[xtdb.api :as xt] | ||
[com.biffweb :as biff] | ||
[com.biffweb :as biff :refer [test-xtdb-node]] | ||
[malli.core :as malc] | ||
[malli.registry :as malr])) | ||
|
||
|
@@ -28,23 +28,8 @@ | |
|
||
(def malli-opts {:registry (malr/composite-registry malc/default-registry schema)}) | ||
|
||
(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)) | ||
|
||
(deftest ensure-unique | ||
(with-open [node (test-node [{:foo "bar"}])] | ||
(with-open [node (test-xtdb-node [{:foo "bar"}])] | ||
(let [db (xt/db node)] | ||
(is (nil? (xt/with-tx | ||
db | ||
|
@@ -58,7 +43,7 @@ | |
[::xt/fn :biff/ensure-unique {:foo "bar"}]])))))) | ||
|
||
(deftest tx-upsert | ||
(with-open [node (test-node [{:xt/id :id/foo | ||
(with-open [node (test-xtdb-node [{:xt/id :id/foo | ||
:foo "bar"}])] | ||
(is (= (biff/tx-xform-upsert | ||
{:biff/db (xt/db node)} | ||
|
@@ -116,10 +101,10 @@ | |
:user/email "[email protected]"}]) | ||
|
||
(deftest tx-default | ||
(with-open [node (test-node (into test-docs | ||
[{:xt/id :user/carol | ||
:user/email "[email protected]" | ||
:user/foo "x"}]))] | ||
(with-open [node (test-xtdb-node (into test-docs | ||
[{:xt/id :user/carol | ||
:user/email "[email protected]" | ||
:user/foo "x"}]))] | ||
(is (= (biff/biff-tx->xt | ||
(get-context node) | ||
[{:db/doc-type :user | ||
|
@@ -144,7 +129,7 @@ | |
{:user/email "[email protected]", :user/foo "x", :xt/id :user/carol}]))))) | ||
|
||
(deftest tx-all | ||
(with-open [node (test-node test-docs)] | ||
(with-open [node (test-xtdb-node test-docs)] | ||
(is (= (biff/biff-tx->xt | ||
(get-context node) | ||
[{:db/doc-type :user | ||
|
@@ -168,22 +153,22 @@ | |
{:user/email "[email protected]", :xt/id :user/bob, :user/bar "baz"}]))))) | ||
|
||
(deftest lookup | ||
(with-open [node (test-node [{:xt/id :user/alice | ||
:user/email "[email protected]" | ||
:user/foo "foo"} | ||
{:xt/id :user/bob | ||
:user/email "[email protected]" | ||
:user/foo "foo"} | ||
{:xt/id :user/carol | ||
:user/email "[email protected]"} | ||
{:xt/id :msg/a | ||
:msg/user :user/alice | ||
:msg/text "hello" | ||
:msg/sent-at #inst "1970"} | ||
{:xt/id :msg/b | ||
:msg/user :user/alice | ||
:msg/text "there" | ||
:msg/sent-at #inst "1971"}])] | ||
(with-open [node (test-xtdb-node [{:xt/id :user/alice | ||
:user/email "[email protected]" | ||
:user/foo "foo"} | ||
{:xt/id :user/bob | ||
:user/email "[email protected]" | ||
:user/foo "foo"} | ||
{:xt/id :user/carol | ||
:user/email "[email protected]"} | ||
{:xt/id :msg/a | ||
:msg/user :user/alice | ||
:msg/text "hello" | ||
:msg/sent-at #inst "1970"} | ||
{:xt/id :msg/b | ||
:msg/user :user/alice | ||
:msg/text "there" | ||
:msg/sent-at #inst "1971"}])] | ||
(let [db (xt/db node)] | ||
(is (= :user/alice (biff/lookup-id db :user/email "[email protected]"))) | ||
(is (= '(:user/alice :user/bob) (sort (biff/lookup-id-all db :user/foo "foo")))) | ||
|