Unify test pattern around "(... -after tx0)".
This commit is contained in:
parent
296c9cb436
commit
13f33a4915
1 changed files with 132 additions and 140 deletions
|
@ -40,7 +40,7 @@
|
||||||
(let [entids (zipmap (vals (dm/idents db)) (keys (dm/idents db)))]
|
(let [entids (zipmap (vals (dm/idents db)) (keys (dm/idents db)))]
|
||||||
(go-pair
|
(go-pair
|
||||||
(->>
|
(->>
|
||||||
(s/all-rows (:sqlite-connection db) ["SELECT e, a, v, tx FROM datoms WHERE tx >= ?" tx])
|
(s/all-rows (:sqlite-connection db) ["SELECT e, a, v, tx FROM datoms WHERE tx > ?" tx])
|
||||||
(<?)
|
(<?)
|
||||||
(mapv #(vector (:e %) (get entids (:a %) (str "fail" (:a %))) (:v %)))
|
(mapv #(vector (:e %) (get entids (:a %) (str "fail" (:a %))) (:v %)))
|
||||||
(filter #(not (= :db/txInstant (second %))))
|
(filter #(not (= :db/txInstant (second %))))
|
||||||
|
@ -62,7 +62,7 @@
|
||||||
(let [entids (zipmap (vals (dm/idents db)) (keys (dm/idents db)))]
|
(let [entids (zipmap (vals (dm/idents db)) (keys (dm/idents db)))]
|
||||||
(go-pair
|
(go-pair
|
||||||
(->>
|
(->>
|
||||||
(s/all-rows (:sqlite-connection db) ["SELECT e, a, v, tx, added FROM transactions WHERE tx >= ? ORDER BY tx ASC, e, a, v, added" tx])
|
(s/all-rows (:sqlite-connection db) ["SELECT e, a, v, tx, added FROM transactions WHERE tx > ? ORDER BY tx ASC, e, a, v, added" tx])
|
||||||
(<?)
|
(<?)
|
||||||
(mapv #(vector (:e %) (entids (:a %)) (:v %) (:tx %) (:added %)))))))
|
(mapv #(vector (:e %) (entids (:a %)) (:v %) (:tx %) (:added %)))))))
|
||||||
|
|
||||||
|
@ -117,16 +117,15 @@
|
||||||
conn (dm/connection-with-db db)
|
conn (dm/connection-with-db db)
|
||||||
now 0xdeadbeef]
|
now 0xdeadbeef]
|
||||||
(try
|
(try
|
||||||
(is (not (= nil (<? (dm/<transact! conn test-schema now)))))
|
(let [tx0 (tx (<? (dm/<transact! conn test-schema now)))]
|
||||||
|
(let [;; TODO: drop now, allow to set :db/txInstant.
|
||||||
(let [;; TODO: drop now, allow to set :db/txInstant.
|
report (<? (dm/<transact! conn [[:db/add 0 :name "valuex"]] now))
|
||||||
report (<? (dm/<transact! conn [[:db/add 0 :name "valuex"]] now))
|
tx (tx report)]
|
||||||
tx (tx report)]
|
(is (= (<? (<datoms-after (dm/db conn) tx0))
|
||||||
(is (= (<? (<datoms-after (dm/db conn) tx))
|
#{[0 :name "valuex"]}))
|
||||||
#{[0 :name "valuex"]}))
|
(is (= (<? (<transactions-after (dm/db conn) tx0))
|
||||||
(is (= (<? (<transactions-after (dm/db conn) tx))
|
[[0 :name "valuex" tx 1] ;; TODO: true, not 1.
|
||||||
[[0 :name "valuex" tx 1] ;; TODO: true, not 1.
|
[tx :db/txInstant now tx 1]]))))
|
||||||
[tx :db/txInstant now tx 1]])))
|
|
||||||
(finally
|
(finally
|
||||||
(<? (dm/close-db db)))))))
|
(<? (dm/close-db db)))))))
|
||||||
|
|
||||||
|
@ -137,18 +136,17 @@
|
||||||
conn (dm/connection-with-db db)
|
conn (dm/connection-with-db db)
|
||||||
now 0xdeadbeef]
|
now 0xdeadbeef]
|
||||||
(try
|
(try
|
||||||
(is (not (= nil (<? (dm/<transact! conn test-schema now)))))
|
(let [tx0 (tx (<? (dm/<transact! conn test-schema now)))
|
||||||
|
tx1 (tx (<? (dm/<transact! conn [[:db/add 1 :name "Ivan"]] now)))
|
||||||
(let [tx1 (tx (<? (dm/<transact! conn [[:db/add 1 :name "Ivan"]] now)))
|
|
||||||
tx2 (tx (<? (dm/<transact! conn [[:db/add 1 :name "Petr"]] now)))
|
tx2 (tx (<? (dm/<transact! conn [[:db/add 1 :name "Petr"]] now)))
|
||||||
tx3 (tx (<? (dm/<transact! conn [[:db/add 1 :aka "Tupen"]] now)))
|
tx3 (tx (<? (dm/<transact! conn [[:db/add 1 :aka "Tupen"]] now)))
|
||||||
tx4 (tx (<? (dm/<transact! conn [[:db/add 1 :aka "Devil"]] now)))]
|
tx4 (tx (<? (dm/<transact! conn [[:db/add 1 :aka "Devil"]] now)))]
|
||||||
(is (= (<? (<datoms-after (dm/db conn) tx1))
|
(is (= (<? (<datoms-after (dm/db conn) tx0))
|
||||||
#{[1 :name "Petr"]
|
#{[1 :name "Petr"]
|
||||||
[1 :aka "Tupen"]
|
[1 :aka "Tupen"]
|
||||||
[1 :aka "Devil"]}))
|
[1 :aka "Devil"]}))
|
||||||
|
|
||||||
(is (= (<? (<transactions-after (dm/db conn) tx1))
|
(is (= (<? (<transactions-after (dm/db conn) tx0))
|
||||||
[[1 :name "Ivan" tx1 1] ;; TODO: true, not 1.
|
[[1 :name "Ivan" tx1 1] ;; TODO: true, not 1.
|
||||||
[tx1 :db/txInstant now tx1 1]
|
[tx1 :db/txInstant now tx1 1]
|
||||||
[1 :name "Ivan" tx2 0]
|
[1 :name "Ivan" tx2 0]
|
||||||
|
@ -158,6 +156,7 @@
|
||||||
[tx3 :db/txInstant now tx3 1]
|
[tx3 :db/txInstant now tx3 1]
|
||||||
[1 :aka "Devil" tx4 1]
|
[1 :aka "Devil" tx4 1]
|
||||||
[tx4 :db/txInstant now tx4 1]])))
|
[tx4 :db/txInstant now tx4 1]])))
|
||||||
|
|
||||||
(finally
|
(finally
|
||||||
(<? (dm/close-db db)))))))
|
(<? (dm/close-db db)))))))
|
||||||
|
|
||||||
|
@ -169,13 +168,12 @@
|
||||||
conn (dm/connection-with-db db)
|
conn (dm/connection-with-db db)
|
||||||
now 0xdeadbeef]
|
now 0xdeadbeef]
|
||||||
(try
|
(try
|
||||||
(is (not (= nil (<? (dm/<transact! conn test-schema now)))))
|
(let [tx0 (tx (<? (dm/<transact! conn test-schema now)))
|
||||||
|
txa (tx (<? (dm/<transact! conn [[:db/add 0 :x 123]] now)))
|
||||||
(let [txa (tx (<? (dm/<transact! conn [[:db/add 0 :x 123]] now)))
|
|
||||||
txb (tx (<? (dm/<transact! conn [[:db/retract 0 :x 123]] now)))]
|
txb (tx (<? (dm/<transact! conn [[:db/retract 0 :x 123]] now)))]
|
||||||
(is (= (<? (<datoms-after (dm/db conn) txa))
|
(is (= (<? (<datoms-after (dm/db conn) tx0))
|
||||||
#{}))
|
#{}))
|
||||||
(is (= (<? (<transactions-after (dm/db conn) txa))
|
(is (= (<? (<transactions-after (dm/db conn) tx0))
|
||||||
[[0 :x 123 txa 1] ;; TODO: true, not 1.
|
[[0 :x 123 txa 1] ;; TODO: true, not 1.
|
||||||
[txa :db/txInstant now txa 1]
|
[txa :db/txInstant now txa 1]
|
||||||
[0 :x 123 txb 0]
|
[0 :x 123 txb 0]
|
||||||
|
@ -190,9 +188,8 @@
|
||||||
conn (dm/connection-with-db db)
|
conn (dm/connection-with-db db)
|
||||||
now -1]
|
now -1]
|
||||||
(try
|
(try
|
||||||
(is (not (= nil (<? (dm/<transact! conn test-schema now)))))
|
(let [tx0 (tx (<? (dm/<transact! conn test-schema now)))
|
||||||
|
report (<? (dm/<transact! conn [[:db/add (dm/id-literal :db.part/user -1) :x 0]
|
||||||
(let [report (<? (dm/<transact! conn [[:db/add (dm/id-literal :db.part/user -1) :x 0]
|
|
||||||
[:db/add (dm/id-literal :db.part/user -1) :y 1]
|
[:db/add (dm/id-literal :db.part/user -1) :y 1]
|
||||||
[:db/add (dm/id-literal :db.part/user -2) :y 2]
|
[:db/add (dm/id-literal :db.part/user -2) :y 2]
|
||||||
[:db/add (dm/id-literal :db.part/user -2) :y 3]] now))]
|
[:db/add (dm/id-literal :db.part/user -2) :y 3]] now))]
|
||||||
|
@ -200,10 +197,9 @@
|
||||||
[(dm/id-literal :db.part/user -1)
|
[(dm/id-literal :db.part/user -1)
|
||||||
(dm/id-literal :db.part/user -2)]))
|
(dm/id-literal :db.part/user -2)]))
|
||||||
|
|
||||||
(let [tx (get-in report [:db-after :current-tx])
|
(let [eid1 (get-in report [:tempids (dm/id-literal :db.part/user -1)])
|
||||||
eid1 (get-in report [:tempids (dm/id-literal :db.part/user -1)])
|
|
||||||
eid2 (get-in report [:tempids (dm/id-literal :db.part/user -2)])]
|
eid2 (get-in report [:tempids (dm/id-literal :db.part/user -2)])]
|
||||||
(is (= (<? (<datoms-after (dm/db conn) tx))
|
(is (= (<? (<datoms-after (dm/db conn) tx0))
|
||||||
#{[eid1 :x 0]
|
#{[eid1 :x 0]
|
||||||
[eid1 :y 1]
|
[eid1 :y 1]
|
||||||
[eid2 :y 2]
|
[eid2 :y 2]
|
||||||
|
@ -219,19 +215,18 @@
|
||||||
conn (dm/connection-with-db db)
|
conn (dm/connection-with-db db)
|
||||||
now -1]
|
now -1]
|
||||||
(try
|
(try
|
||||||
(is (not (= nil (<? (dm/<transact! conn test-schema now)))))
|
(let [tx0 (tx (<? (dm/<transact! conn test-schema now)))]
|
||||||
|
(testing "Multiple :db/unique values in tx-data violate unique constraint, no tempid"
|
||||||
|
(is (thrown-with-msg?
|
||||||
|
ExceptionInfo #"unique constraint"
|
||||||
|
(<? (dm/<transact! conn [[:db/add 1 :x 0]
|
||||||
|
[:db/add 2 :x 0]] now)))))
|
||||||
|
|
||||||
(testing "Multiple :db/unique values in tx-data violate unique constraint, no tempid"
|
(testing "Multiple :db/unique values in tx-data violate unique constraint, tempid"
|
||||||
(is (thrown-with-msg?
|
(is (thrown-with-msg?
|
||||||
ExceptionInfo #"unique constraint"
|
ExceptionInfo #"unique constraint"
|
||||||
(<? (dm/<transact! conn [[:db/add 1 :x 0]
|
(<? (dm/<transact! conn [[:db/add (dm/id-literal :db.part/user -1) :spouse "Dana"]
|
||||||
[:db/add 2 :x 0]] now)))))
|
[:db/add (dm/id-literal :db.part/user -2) :spouse "Dana"]] now))))))
|
||||||
|
|
||||||
(testing "Multiple :db/unique values in tx-data violate unique constraint, tempid"
|
|
||||||
(is (thrown-with-msg?
|
|
||||||
ExceptionInfo #"unique constraint"
|
|
||||||
(<? (dm/<transact! conn [[:db/add (dm/id-literal :db.part/user -1) :spouse "Dana"]
|
|
||||||
[:db/add (dm/id-literal :db.part/user -2) :spouse "Dana"]] now)))))
|
|
||||||
|
|
||||||
(finally
|
(finally
|
||||||
(<? (dm/close-db db)))))))
|
(<? (dm/close-db db)))))))
|
||||||
|
@ -243,32 +238,31 @@
|
||||||
conn (dm/connection-with-db db)
|
conn (dm/connection-with-db db)
|
||||||
now -1]
|
now -1]
|
||||||
(try
|
(try
|
||||||
(<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1)
|
(let [tx0 (tx (<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1)
|
||||||
:db/ident :test/kw
|
:db/ident :test/kw
|
||||||
:db/unique :db.unique/identity
|
:db/unique :db.unique/identity
|
||||||
:db/valueType :db.type/keyword}
|
:db/valueType :db.type/keyword}
|
||||||
{:db/id :db.part/db :db.install/attribute (dm/id-literal :db.part/user -1)}] now))
|
{:db/id :db.part/db :db.install/attribute (dm/id-literal :db.part/user -1)}] now)))]
|
||||||
|
|
||||||
(let [report (<? (dm/<transact! conn [[:db/add (dm/id-literal :db.part/user -1) :test/kw :test/kw1]] now))
|
(let [report (<? (dm/<transact! conn [[:db/add (dm/id-literal :db.part/user -1) :test/kw :test/kw1]] now))
|
||||||
tx (get-in report [:db-after :current-tx])
|
eid (get-in report [:tempids (dm/id-literal :db.part/user -1)])]
|
||||||
eid (get-in report [:tempids (dm/id-literal :db.part/user -1)])]
|
(is (= (<? (<datoms-after (dm/db conn) tx0))
|
||||||
(is (= (<? (<datoms-after (dm/db conn) tx))
|
#{[eid :test/kw ":test/kw1"]})) ;; Value is raw.
|
||||||
#{[eid :test/kw ":test/kw1"]})) ;; Value is raw.
|
|
||||||
|
|
||||||
(testing "Adding the same value compares existing values correctly."
|
(testing "Adding the same value compares existing values correctly."
|
||||||
(<? (dm/<transact! conn [[:db/add eid :test/kw :test/kw1]] now))
|
(<? (dm/<transact! conn [[:db/add eid :test/kw :test/kw1]] now))
|
||||||
(is (= (<? (<datoms-after (dm/db conn) tx))
|
(is (= (<? (<datoms-after (dm/db conn) tx0))
|
||||||
#{[eid :test/kw ":test/kw1"]}))) ;; Value is raw.
|
#{[eid :test/kw ":test/kw1"]}))) ;; Value is raw.
|
||||||
|
|
||||||
(testing "Upserting retracts existing value correctly."
|
(testing "Upserting retracts existing value correctly."
|
||||||
(<? (dm/<transact! conn [[:db/add eid :test/kw :test/kw2]] now))
|
(<? (dm/<transact! conn [[:db/add eid :test/kw :test/kw2]] now))
|
||||||
(is (= (<? (<datoms-after (dm/db conn) tx))
|
(is (= (<? (<datoms-after (dm/db conn) tx0))
|
||||||
#{[eid :test/kw ":test/kw2"]}))) ;; Value is raw.
|
#{[eid :test/kw ":test/kw2"]}))) ;; Value is raw.
|
||||||
|
|
||||||
(testing "Retracting compares values correctly."
|
(testing "Retracting compares values correctly."
|
||||||
(<? (dm/<transact! conn [[:db/retract eid :test/kw :test/kw2]] now))
|
(<? (dm/<transact! conn [[:db/retract eid :test/kw :test/kw2]] now))
|
||||||
(is (= (<? (<datoms-after (dm/db conn) tx))
|
(is (= (<? (<datoms-after (dm/db conn) tx0))
|
||||||
#{}))))
|
#{})))))
|
||||||
|
|
||||||
(finally
|
(finally
|
||||||
(<? (dm/close-db db)))))))
|
(<? (dm/close-db db)))))))
|
||||||
|
@ -281,36 +275,34 @@
|
||||||
now 0xdeadbeef
|
now 0xdeadbeef
|
||||||
tempids (fn [tx] (into {} (map (juxt (comp :idx first) second) (:tempids tx))))]
|
tempids (fn [tx] (into {} (map (juxt (comp :idx first) second) (:tempids tx))))]
|
||||||
(try
|
(try
|
||||||
(is (not (= nil (<? (dm/<transact! conn test-schema now)))))
|
|
||||||
|
|
||||||
;; Not having DB-as-value really hurts us here. This test only works because all upserts
|
;; Not having DB-as-value really hurts us here. This test only works because all upserts
|
||||||
;; succeed on top of each other, so we never need to reset the underlying store.
|
;; succeed on top of each other, so we never need to reset the underlying store.
|
||||||
(<? (dm/<transact! conn test-schema now))
|
(<? (dm/<transact! conn test-schema now))
|
||||||
(<? (dm/<transact! conn [{:db/id 101 :name "Ivan" :email "@1"}
|
(let [tx0 (tx (<? (dm/<transact! conn [{:db/id 101 :name "Ivan" :email "@1"}
|
||||||
{:db/id 102 :name "Petr" :email "@2"}] now))
|
{:db/id 102 :name "Petr" :email "@2"}] now)))]
|
||||||
|
|
||||||
(testing "upsert with tempid"
|
(testing "upsert with tempid"
|
||||||
(let [report (<? (dm/<transact! conn [[:db/add (dm/id-literal :db.part/user -1) :name "Ivan"]
|
(let [report (<? (dm/<transact! conn [[:db/add (dm/id-literal :db.part/user -1) :name "Ivan"]
|
||||||
[:db/add (dm/id-literal :db.part/user -1) :age 12]] now))]
|
[:db/add (dm/id-literal :db.part/user -1) :age 12]] now))]
|
||||||
(is (= (<? (<shallow-entity (dm/db conn) 101))
|
(is (= (<? (<shallow-entity (dm/db conn) 101))
|
||||||
{:name "Ivan" :age 12 :email "@1"}))
|
{:name "Ivan" :age 12 :email "@1"}))
|
||||||
(is (= (tempids report)
|
(is (= (tempids report)
|
||||||
{-1 101}))))
|
{-1 101}))))
|
||||||
|
|
||||||
(testing "upsert with tempid, order does not matter"
|
(testing "upsert with tempid, order does not matter"
|
||||||
(let [report (<? (dm/<transact! conn [[:db/add (dm/id-literal :db.part/user -1) :age 13]
|
(let [report (<? (dm/<transact! conn [[:db/add (dm/id-literal :db.part/user -1) :age 13]
|
||||||
[:db/add (dm/id-literal :db.part/user -1) :name "Petr"]] now))]
|
[:db/add (dm/id-literal :db.part/user -1) :name "Petr"]] now))]
|
||||||
(is (= (<? (<shallow-entity (dm/db conn) 102))
|
(is (= (<? (<shallow-entity (dm/db conn) 102))
|
||||||
{:name "Petr" :age 13 :email "@2"}))
|
{:name "Petr" :age 13 :email "@2"}))
|
||||||
(is (= (tempids report)
|
(is (= (tempids report)
|
||||||
{-1 102}))))
|
{-1 102}))))
|
||||||
|
|
||||||
(testing "Conflicting upserts fail"
|
(testing "Conflicting upserts fail"
|
||||||
(is (thrown-with-msg? Throwable #"Conflicting upsert: #datomish.db.TempId\{:part :db.part/user, :idx -\d+\} resolves both to \d+ and \d+"
|
(is (thrown-with-msg? Throwable #"Conflicting upsert: #datomish.db.TempId\{:part :db.part/user, :idx -\d+\} resolves both to \d+ and \d+"
|
||||||
(<? (dm/<transact! conn [[:db/add (dm/id-literal :db.part/user -1) :name "Ivan"]
|
(<? (dm/<transact! conn [[:db/add (dm/id-literal :db.part/user -1) :name "Ivan"]
|
||||||
[:db/add (dm/id-literal :db.part/user -1) :age 35]
|
[:db/add (dm/id-literal :db.part/user -1) :age 35]
|
||||||
[:db/add (dm/id-literal :db.part/user -1) :name "Petr"]
|
[:db/add (dm/id-literal :db.part/user -1) :name "Petr"]
|
||||||
[:db/add (dm/id-literal :db.part/user -1) :age 36]] now)))))
|
[:db/add (dm/id-literal :db.part/user -1) :age 36]] now))))))
|
||||||
(finally
|
(finally
|
||||||
(<? (dm/close-db db)))))))
|
(<? (dm/close-db db)))))))
|
||||||
|
|
||||||
|
@ -325,46 +317,46 @@
|
||||||
;; Not having DB-as-value really hurts us here. This test only works because all upserts
|
;; Not having DB-as-value really hurts us here. This test only works because all upserts
|
||||||
;; succeed on top of each other, so we never need to reset the underlying store.
|
;; succeed on top of each other, so we never need to reset the underlying store.
|
||||||
(<? (dm/<transact! conn test-schema now))
|
(<? (dm/<transact! conn test-schema now))
|
||||||
(<? (dm/<transact! conn [{:db/id 101 :name "Ivan" :email "@1"}
|
(let [tx0 (tx (<? (dm/<transact! conn [{:db/id 101 :name "Ivan" :email "@1"}
|
||||||
{:db/id 102 :name "Petr" :email "@2"}] now))
|
{:db/id 102 :name "Petr" :email "@2"}] now)))]
|
||||||
|
|
||||||
(testing "upsert with tempid"
|
(testing "upsert with tempid"
|
||||||
(let [tx (<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :age 35}] now))]
|
(let [tx (<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :age 35}] now))]
|
||||||
(is (= (<? (<shallow-entity (dm/db conn) 101))
|
(is (= (<? (<shallow-entity (dm/db conn) 101))
|
||||||
{:name "Ivan" :email "@1" :age 35}))
|
{:name "Ivan" :email "@1" :age 35}))
|
||||||
(is (= (tempids tx)
|
(is (= (tempids tx)
|
||||||
{-1 101}))))
|
{-1 101}))))
|
||||||
|
|
||||||
(testing "upsert by 2 attrs with tempid"
|
(testing "upsert by 2 attrs with tempid"
|
||||||
(let [tx (<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :email "@1" :age 35}] now))]
|
(let [tx (<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :email "@1" :age 35}] now))]
|
||||||
(is (= (<? (<shallow-entity (dm/db conn) 101))
|
(is (= (<? (<shallow-entity (dm/db conn) 101))
|
||||||
{:name "Ivan" :email "@1" :age 35}))
|
{:name "Ivan" :email "@1" :age 35}))
|
||||||
(is (= (tempids tx)
|
(is (= (tempids tx)
|
||||||
{-1 101}))))
|
{-1 101}))))
|
||||||
|
|
||||||
(testing "upsert with existing id"
|
(testing "upsert with existing id"
|
||||||
(let [tx (<? (dm/<transact! conn [{:db/id 101 :name "Ivan" :age 36}] now))]
|
(let [tx (<? (dm/<transact! conn [{:db/id 101 :name "Ivan" :age 36}] now))]
|
||||||
(is (= (<? (<shallow-entity (dm/db conn) 101))
|
(is (= (<? (<shallow-entity (dm/db conn) 101))
|
||||||
{:name "Ivan" :email "@1" :age 36}))
|
{:name "Ivan" :email "@1" :age 36}))
|
||||||
(is (= (tempids tx)
|
(is (= (tempids tx)
|
||||||
{}))))
|
{}))))
|
||||||
|
|
||||||
(testing "upsert by 2 attrs with existing id"
|
(testing "upsert by 2 attrs with existing id"
|
||||||
(let [tx (<? (dm/<transact! conn [{:db/id 101 :name "Ivan" :email "@1" :age 37}] now))]
|
(let [tx (<? (dm/<transact! conn [{:db/id 101 :name "Ivan" :email "@1" :age 37}] now))]
|
||||||
(is (= (<? (<shallow-entity (dm/db conn) 101))
|
(is (= (<? (<shallow-entity (dm/db conn) 101))
|
||||||
{:name "Ivan" :email "@1" :age 37}))
|
{:name "Ivan" :email "@1" :age 37}))
|
||||||
(is (= (tempids tx)
|
(is (= (tempids tx)
|
||||||
{}))))
|
{}))))
|
||||||
|
|
||||||
(testing "upsert to two entities, resolve to same tempid, fails due to overlapping writes"
|
(testing "upsert to two entities, resolve to same tempid, fails due to overlapping writes"
|
||||||
(is (thrown-with-msg? Throwable #"cardinality constraint"
|
(is (thrown-with-msg? Throwable #"cardinality constraint"
|
||||||
(<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :age 35}
|
(<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :age 35}
|
||||||
{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :age 36}] now)))))
|
{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :age 36}] now)))))
|
||||||
|
|
||||||
(testing "upsert to two entities, two tempids, fails due to overlapping writes"
|
(testing "upsert to two entities, two tempids, fails due to overlapping writes"
|
||||||
(is (thrown-with-msg? Throwable #"cardinality constraint"
|
(is (thrown-with-msg? Throwable #"cardinality constraint"
|
||||||
(<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :age 35}
|
(<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :age 35}
|
||||||
{:db/id (dm/id-literal :db.part/user -2) :name "Ivan" :age 36}] now)))))
|
{:db/id (dm/id-literal :db.part/user -2) :name "Ivan" :age 36}] now))))))
|
||||||
|
|
||||||
(finally
|
(finally
|
||||||
(<? (dm/close-db db)))))))
|
(<? (dm/close-db db)))))))
|
||||||
|
@ -380,30 +372,30 @@
|
||||||
;; Not having DB-as-value really hurts us here. This test only works because all upserts
|
;; Not having DB-as-value really hurts us here. This test only works because all upserts
|
||||||
;; fail until the final one, so we never need to reset the underlying store.
|
;; fail until the final one, so we never need to reset the underlying store.
|
||||||
(<? (dm/<transact! conn test-schema now))
|
(<? (dm/<transact! conn test-schema now))
|
||||||
(<? (dm/<transact! conn [{:db/id 101 :name "Ivan" :email "@1"}
|
(let [tx0 (tx (<? (dm/<transact! conn [{:db/id 101 :name "Ivan" :email "@1"}
|
||||||
{:db/id 102 :name "Petr" :email "@2"}] now))
|
{:db/id 102 :name "Petr" :email "@2"}] now)))]
|
||||||
|
|
||||||
;; TODO: improve error message to refer to upsert inputs.
|
;; TODO: improve error message to refer to upsert inputs.
|
||||||
(testing "upsert conficts with existing id"
|
(testing "upsert conficts with existing id"
|
||||||
(is (thrown-with-msg? Throwable #"unique constraint"
|
(is (thrown-with-msg? Throwable #"unique constraint"
|
||||||
(<? (dm/<transact! conn [{:db/id 102 :name "Ivan" :age 36}] now)))))
|
(<? (dm/<transact! conn [{:db/id 102 :name "Ivan" :age 36}] now)))))
|
||||||
|
|
||||||
;; TODO: improve error message to refer to upsert inputs.
|
;; TODO: improve error message to refer to upsert inputs.
|
||||||
(testing "upsert conficts with non-existing id"
|
(testing "upsert conficts with non-existing id"
|
||||||
(is (thrown-with-msg? Throwable #"unique constraint"
|
(is (thrown-with-msg? Throwable #"unique constraint"
|
||||||
(<? (dm/<transact! conn [{:db/id 103 :name "Ivan" :age 36}] now)))))
|
(<? (dm/<transact! conn [{:db/id 103 :name "Ivan" :age 36}] now)))))
|
||||||
|
|
||||||
;; TODO: improve error message to refer to upsert inputs.
|
;; TODO: improve error message to refer to upsert inputs.
|
||||||
(testing "upsert by 2 conflicting fields"
|
(testing "upsert by 2 conflicting fields"
|
||||||
(is (thrown-with-msg? Throwable #"Conflicting upsert: #datomish.db.TempId\{:part :db.part/user, :idx -\d+\} resolves both to \d+ and \d+"
|
(is (thrown-with-msg? Throwable #"Conflicting upsert: #datomish.db.TempId\{:part :db.part/user, :idx -\d+\} resolves both to \d+ and \d+"
|
||||||
(<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :email "@2" :age 35}] now)))))
|
(<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :email "@2" :age 35}] now)))))
|
||||||
|
|
||||||
(testing "upsert by non-existing value resolves as update"
|
(testing "upsert by non-existing value resolves as update"
|
||||||
(let [report (<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :email "@3" :age 35}] now))]
|
(let [report (<? (dm/<transact! conn [{:db/id (dm/id-literal :db.part/user -1) :name "Ivan" :email "@3" :age 35}] now))]
|
||||||
(is (= (<? (<shallow-entity (dm/db conn) 101))
|
(is (= (<? (<shallow-entity (dm/db conn) 101))
|
||||||
{:name "Ivan" :email "@3" :age 35}))
|
{:name "Ivan" :email "@3" :age 35}))
|
||||||
(is (= (tempids report)
|
(is (= (tempids report)
|
||||||
{-1 101}))))
|
{-1 101})))))
|
||||||
|
|
||||||
(finally
|
(finally
|
||||||
(<? (dm/close-db db)))))))
|
(<? (dm/close-db db)))))))
|
||||||
|
|
Loading…
Reference in a new issue