mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
83 lines
2.9 KiB
Clojure
83 lines
2.9 KiB
Clojure
(ns fixture
|
|
(:require [cljs.test :as t]
|
|
[const]
|
|
[datascript.core :as d]
|
|
[example]
|
|
[frontend.common.missionary :as c.m]
|
|
[frontend.worker.rtc.client-op :as client-op]
|
|
[frontend.worker.rtc.db-listener]
|
|
[frontend.worker.state :as worker-state]
|
|
[helper]
|
|
[missionary.core :as m]))
|
|
|
|
(def graph-schema-version "0")
|
|
|
|
(defn- transact-graph-schema-version
|
|
[conn]
|
|
(d/transact! conn [{:db/ident :logseq.kv/schema-version
|
|
:kv/value graph-schema-version}]))
|
|
|
|
(def install-some-consts
|
|
{:before
|
|
(fn []
|
|
(reset! worker-state/*rtc-ws-url "wss://ws-dev.logseq.com/rtc-sync?token=%s"))})
|
|
|
|
(def install-example-db-fixture
|
|
{:before
|
|
(fn []
|
|
(prn :test-repo const/test-repo)
|
|
(swap! worker-state/*client-ops-conns assoc const/test-repo (d/create-conn client-op/schema-in-db))
|
|
(let [conn (d/conn-from-db example/example-db)]
|
|
(transact-graph-schema-version conn)
|
|
(swap! worker-state/*datascript-conns assoc const/test-repo conn)))
|
|
:after
|
|
(fn []
|
|
(swap! worker-state/*datascript-conns dissoc const/test-repo)
|
|
(swap! worker-state/*client-ops-conns dissoc const/test-repo))})
|
|
|
|
(def clear-test-remote-graphs-fixture
|
|
{:before
|
|
#(when const/is-client1?
|
|
(t/async
|
|
done
|
|
(c.m/run-task-throw
|
|
:clear-test-remote-graphs
|
|
(m/sp
|
|
(m/? helper/new-task--clear-all-test-remote-graphs)
|
|
(done)))))})
|
|
|
|
(def upload-example-graph-fixture
|
|
{:before
|
|
#(when const/is-client1?
|
|
(t/async
|
|
done
|
|
(c.m/run-task-throw
|
|
:upload-example-graph-fixture
|
|
(m/sp
|
|
(swap! worker-state/*datascript-conns dissoc const/downloaded-test-repo)
|
|
(swap! worker-state/*client-ops-conns assoc
|
|
const/downloaded-test-repo (d/create-conn client-op/schema-in-db))
|
|
(let [{:keys [graph-uuid]} (m/? helper/new-task--upload-example-graph)]
|
|
(assert (some? graph-uuid))
|
|
(m/? (helper/new-task--wait-creating-graph graph-uuid))
|
|
(println :uploaded-graph graph-uuid))
|
|
(done)))))})
|
|
|
|
(def build-conn-by-download-example-graph-fixture
|
|
{:before
|
|
#(t/async
|
|
done
|
|
(c.m/run-task-throw
|
|
:build-conn-by-download-example-graph-fixture
|
|
(m/sp
|
|
(swap! worker-state/*datascript-conns dissoc const/downloaded-test-repo)
|
|
(swap! worker-state/*client-ops-conns assoc
|
|
const/downloaded-test-repo (d/create-conn client-op/schema-in-db))
|
|
(let [graph-uuid (m/? helper/new-task--get-remote-example-graph-uuid)]
|
|
(assert (some? graph-uuid))
|
|
(m/? (helper/new-task--download-graph graph-uuid const/downloaded-test-graph-name)))
|
|
(done))))
|
|
:after
|
|
#(do (swap! worker-state/*datascript-conns dissoc const/downloaded-test-repo)
|
|
(swap! worker-state/*client-ops-conns dissoc const/downloaded-test-repo))})
|