/
get_else_tx_instant_test.clj
56 lines (49 loc) · 2.23 KB
/
get_else_tx_instant_test.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(ns no.nsd.get-else-tx-instant-test
(:require [clojure.test :refer :all]
[no.nsd.utils :as u]
[datomic.api :as d]
[no.nsd.rewriting-history.impl :as impl]))
(deftest get-else-tx-instant-test
(let [conn (u/empty-conn)]
#_(ft/auto-inc! conn (fn [{:keys [years]}] (swap! years inc)))
@(d/transact conn impl/schema)
@(d/transact conn #d/schema[[:m/id :one :string :id]
[:m/info :one :string]])
@(d/transact conn [{:m/id "id" :m/info "info"}])
(is (= #{#inst"1973"}
(into #{} (d/q '[:find [?inst ...]
:in $
:where
[?e :m/id "id"]
[?e :m/info "info" ?tx true]
[?tx :db/txInstant ?inst]]
(d/history (d/db conn))))))
(is (= #{#inst"1973"}
(into #{} (d/q '[:find [?inst ...]
:in $
:where
[?e :m/id "id"]
[?e :m/info "info" ?tx true]
[?tx :db/txInstant ?inst-default]
[(get-else $ ?tx :tx/txInstant ?inst-default) ?inst]]
(d/history (d/db conn))))))
(u/rewrite-noop! conn [:m/id "id"])
; rewriting-history cannot set :db/txInstant arbitrarly:
(is (= #{#inst"1973" #inst"1984"}
(into #{} (d/q '[:find [?inst ...]
:in $
:where
[?e :m/id "id"]
[?e :m/info "info" ?tx true]
[?tx :db/txInstant ?inst]]
(d/history (d/db conn))))))
; using get-else fixes this problem though:
(is (= #{#inst"1973"}
(into #{} (d/q '[:find [?inst ...]
:in $
:where
[?e :m/id "id"]
[?e :m/info "info" ?tx true]
[?tx :db/txInstant ?inst-default]
[(get-else $ ?tx :tx/txInstant ?inst-default) ?inst]]
(d/history (d/db conn))))))))