Skip to content

Commit

Permalink
roam/json->edn test runs in clj
Browse files Browse the repository at this point in the history
  • Loading branch information
adamschmideg authored and tiensonqin committed Jan 22, 2021
1 parent 06f7d6d commit b9416ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
org.clojure/tools.namespace {:mvn/version "0.2.11"}
cider/cider-nrepl {:mvn/version "0.25.5"}}
:main-opts ["-m" "shadow.cljs.devtools.cli"]}
:test-cljs
:test
{:extra-paths ["src/test/"]
:extra-deps {
org.clojure/clojurescript {:mvn/version "1.10.764"}
org.clojure/test.check {:mvn/version "RELEASE"}}
:main-opts ["-m" "shadow.cljs.devtools.cli"]}
:test-clj
{;:extra-paths ["src/test/"]
{:extra-paths ["src/test/"]
:extra-deps
{cheshire/cheshire {:mvn/version "5.10.0"}
com.cognitect/test-runner
Expand Down
9 changes: 6 additions & 3 deletions src/main/frontend/external/roam.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@
(apply str))))
files)))

(defn json->edn
[raw-string]
#?(:cljs (-> raw-string js/JSON.parse bean/->clj)
:clj (-> raw-string json/parse-string clojure.walk/keywordize-keys)))

(defrecord Roam []
protocol/External
(toMarkdownFiles [this content _config]
#?(:cljs (let [data (bean/->clj (js/JSON.parse content))]
(->files data))
:clj (-> content json/parse-string ->files))))
(->files content)))

(comment
(defonce test-roam-json (frontend.db/get-file "same.json"))
Expand Down
22 changes: 13 additions & 9 deletions src/test/frontend/external/roam_test.cljc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns frontend.external.roam-test
(:require #?(:clj [clojure.test :refer :all]
:cljs [cljs.test :refer [is deftest]])
;[frontend.external.roam :as roam]
[frontend.external.roam :as roam]
[frontend.external :refer [to-markdown-files]]))

(def minimal-json "
Expand All @@ -23,11 +23,15 @@
\"edit-email\": \"adam@example.com\"}]
")

(deftest roam-import-test
(let [got (to-markdown-files :roam minimal-json {})
md (first got)]
(is (= 1 (count got)))
(is (= "Export JSON" (:title md)))
(is (:created-at md))
(is (:last-modified-at md))
(is (= "---\ntitle: Export JSON\n---\n\n## Hello, world!\n" (:text md)))))
(deftest json->edn-test
(is (= [1 {:foo 42, :bar "baz"} 3] (roam/json->edn "[1, {\"foo\": 42, \"bar\": \"baz\"}, 3]"))))

(comment
(deftest roam-import-test
(let [got (to-markdown-files :roam minimal-json {})
md (first got)]
(is (= 1 (count got)))
(is (= "Export JSON" (:title md)))
(is (:created-at md))
(is (:last-modified-at md))
(is (= "---\ntitle: Export JSON\n---\n\n## Hello, world!\n" (:text md))))))

0 comments on commit b9416ac

Please sign in to comment.