Move core, sync, and transit from platform-specific .clj/.cljs to shared .cljc files with reader conditionals. This enables testing the full sync logic on the JVM and using SyncedAtom from Clojure clients. Key changes: - PStore protocol (store.cljc) decouples core from storage backend - IDB store (store/idb.cljs) and memory store (store/memory.cljc) - SyncedAtom implements CLJ IDeref/IAtom/IRef + CLJS equivalents - Sync client uses java.net.http on CLJ, fetch on CLJS - SSE remains CLJS-only; JVM clients use polling - API change: store passed explicitly instead of pb/open - 7 new JVM tests: local ops, persistence, watches, two-client sync - 28 tests total, 87 assertions, all passing
38 lines
1.1 KiB
Clojure
38 lines
1.1 KiB
Clojure
(ns pocketbook.transit-test
|
|
(:require [clojure.test :refer [deftest is testing]]
|
|
[pocketbook.transit :as t]))
|
|
|
|
(deftest roundtrip-basic-types
|
|
(doseq [v [42
|
|
"hello"
|
|
:keyword
|
|
true
|
|
nil
|
|
[1 2 3]
|
|
{:a 1 :b {:c 2}}
|
|
#{1 2 3}]]
|
|
(is (= v (t/decode (t/encode v)))
|
|
(str "Roundtrip failed for: " (pr-str v)))))
|
|
|
|
(deftest roundtrip-clojure-types
|
|
(let [uuid (java.util.UUID/randomUUID)
|
|
inst #inst "2026-04-04T10:00:00Z"]
|
|
(is (= uuid (t/decode (t/encode uuid))))
|
|
(is (= inst (t/decode (t/encode inst))))))
|
|
|
|
(deftest roundtrip-complex-structure
|
|
(let [data [{:id "todo:1"
|
|
:value {:text "Buy milk" :tags #{:groceries :urgent}}
|
|
:version 3
|
|
:updated 1743760800000}
|
|
{:id "todo:2"
|
|
:deleted true
|
|
:version 5}]]
|
|
(is (= data (t/decode (t/encode data))))))
|
|
|
|
(deftest encode-returns-string
|
|
(let [v {:hello "world" :nums [1 2 3]}
|
|
s (t/encode v)]
|
|
(is (string? s))
|
|
(is (= v (t/decode s)))))
|