diff --git a/test/datomish/test.cljs b/test/datomish/test.cljs index 10070500..5ba4cde5 100644 --- a/test/datomish/test.cljs +++ b/test/datomish/test.cljs @@ -7,10 +7,12 @@ datomish.db-test datomish.query-test datomish.sqlite-user-version-test + datomish.tofinoish-test datomish.test.util datomish.test.transforms datomish.test.query - datomish.test-macros-test)) + datomish.test-macros-test + )) (doo-tests 'datomish.places.import-test @@ -18,6 +20,7 @@ 'datomish.db-test 'datomish.query-test 'datomish.sqlite-user-version-test + 'datomish.tofinoish-test 'datomish.test.util 'datomish.test.transforms 'datomish.test.query diff --git a/test/datomish/tofinoish_test.cljc b/test/datomish/tofinoish_test.cljc new file mode 100644 index 00000000..770da734 --- /dev/null +++ b/test/datomish/tofinoish_test.cljc @@ -0,0 +1,266 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. + +(ns datomish.tofinoish-test + #?(:cljs + (:require-macros + [datomish.pair-chan :refer [go-pair !]]]) + #?@(:cljs [[datomish.promise-sqlite] + [datomish.pair-chan] + [datomish.test-macros :refer-macros [deftest-async deftest-db]] + [datomish.node-tempfile :refer [tempfile]] + [cljs.test :as t :refer-macros [is are deftest testing async]] + [cljs.core.async :as a :refer [!]]])) + #?(:clj + (:import [clojure.lang ExceptionInfo])) + #?(:clj + (:import [datascript.db DB]))) + +#?(:cljs + (def Throwable js/Error)) + + +(def page-schema + [{:db/id (d/id-literal :db.part/user) + :db/ident :page/url + :db/valueType :db.type/string ; Because not all URLs are java.net.URIs. For JS we may want to use /uri. + :db/cardinality :db.cardinality/one + :db/unique :db.unique/identity + :db/doc "A page's URL." + :db.install/_attribute :db.part/db} + {:db/id (d/id-literal :db.part/user) + :db/ident :page/title + :db/valueType :db.type/string + :db/cardinality :db.cardinality/one ; We supersede as we see new titles. + :db/doc "A page's title." + :db.install/_attribute :db.part/db} + {:db/id (d/id-literal :db.part/user) + :db/ident :page/starred + :db/valueType :db.type/boolean + :db/cardinality :db.cardinality/one + :db/doc "Whether the page is starred." + :db.install/_attribute :db.part/db} + {:db/id (d/id-literal :db.part/user) + :db/ident :page/visit + :db/valueType :db.type/ref + :db/cardinality :db.cardinality/many + :db/doc "A visit to the page." + :db.install/_attribute :db.part/db}]) + +(def visit-schema + [{:db/id (d/id-literal :db.part/user) + :db/ident :visit/visitAt + :db/valueType :db.type/instant + :db/cardinality :db.cardinality/many + :db/doc "The instant of the visit." + :db.install/_attribute :db.part/db}]) + +(def session-schema + [{:db/id (d/id-literal :db.part/user) + :db/ident :session/startedFromAncestor + :db/valueType :db.type/ref ; To a session. + :db/cardinality :db.cardinality/one + :db/doc "The ancestor of a session." + :db.install/_attribute :db.part/db} + {:db/id (d/id-literal :db.part/user) + :db/ident :session/startedInScope + :db/valueType :db.type/string + :db/cardinality :db.cardinality/one + :db/doc "The parent scope of a session." + :db.install/_attribute :db.part/db} + {:db/id (d/id-literal :db.part/user) + :db/ident :session/startReason + :db/valueType :db.type/string ; TODO: enum? + :db/cardinality :db.cardinality/many + :db/doc "The start reasons of a session." + :db.install/_attribute :db.part/db} + {:db/id (d/id-literal :db.part/user) + :db/ident :session/endReason + :db/valueType :db.type/string ; TODO: enum? + :db/cardinality :db.cardinality/many + :db/doc "The end reasons of a session." + :db.install/_attribute :db.part/db} + {:db/id (d/id-literal :db.part/user) + :db/ident :event/session + :db/valueType :db.type/ref ; To a session. + :db/cardinality :db.cardinality/one + :db/doc "The session in which a tx took place." + :db.install/_attribute :db.part/db}]) + +(def tofino-schema (concat page-schema visit-schema session-schema)) + +(defn instant [x] + #?(:cljs x) + #?(:clj (.getTime x))) + +(defn now [] + #?(:cljs (js/Date.)) + #?(:clj (java.util.Date.))) + +;; Returns the session ID. +(defn + (map (fn [[uri title lastVisited]] + {:uri uri :title title :lastVisited lastVisited}) + raw (> + raw + (sort-by first) + (partition-by first) + (map most-recent) + (sort-by descending-time) + (take limit) + (map row->map)))))) + +(defn = (instant (:lastVisited (first visited))) (instant (:lastVisited (second visited))))))) + + (is (= "Example Philanthropy New" + (