;; Copyright 2016 Mozilla ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); you may not use ;; this file except in compliance with the License. You may obtain a copy of the ;; License at http://www.apache.org/licenses/LICENSE-2.0 ;; Unless required by applicable law or agreed to in writing, software distributed ;; under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR ;; CONDITIONS OF ANY KIND, either express or implied. See the License for the ;; specific language governing permissions and limitations under the License. (ns datomish.schema-management-test #?(:cljs (:require-macros [datomish.pair-chan :refer [go-pair !]]]) #?@(:cljs [[datomish.js-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 id-schema (d/id-literal :db.part/db)) (def id-foobar (d/id-literal :db.part/user)) (def trivial-schema-managed-fragment-v1 {:name :com.example.foo :version 1 :attributes {:foo/bar {:db/cardinality :db.cardinality/one :db/valueType :db.type/string}}}) (def additional-schema-managed-fragment-v7 {:name :com.example.bar :version 7 :attributes {:bar/noo {:db/cardinality :db.cardinality/one :db/unique :db.unique/value :db/valueType :db.type/long}}}) (def additional-schema-managed-fragment-v8 {:name :com.example.bar :version 8 :attributes {:bar/choo {:db/cardinality :db.cardinality/many :db/fulltext true :db/valueType :db.type/string} :bar/noo {:db/cardinality :db.cardinality/one :db/unique :db.unique/value :db/valueType :db.type/long}}}) (def trivial-schema-managed-fragment-v2 {:name :com.example.foo :version 2 :attributes {:foo/bar {:db/cardinality :db.cardinality/many :db/valueType :db.type/string}}}) (def trivial-schema-v1 (sm/managed-schema-fragment->datoms trivial-schema-managed-fragment-v1)) ;; TODO (deftest test-managed-schema-fragment->datoms) (defn datoms fragment))) (let [current (symbolic-schema db) [:foo/bar :db/valueType])))) (testing "An empty fragment yields no work." (is (nil? (datoms additional-schema-managed-fragment-v7)] [:call "Y"]] (datoms additional-schema-managed-fragment-v7)))) next-up {:pre "XX" :post "YY" :fragment-pre {:com.example.foo {1 "AA"}} :fragment-post {:com.example.foo {1 "BB"} :com.example.bar {7 "CC"}} :fragments [trivial-schema-managed-fragment-v2 additional-schema-managed-fragment-v8 ]} counter (atom 0) pre (atom nil) post (atom nil) fragment-pre-foo (atom nil) fragment-post-foo (atom nil) fragment-post-bar (atom nil) next-up-but-with-functions {:pre (fn [db _] (reset! pre (swap! counter inc)) nil) :post (fn [db _] (reset! post (swap! counter inc)) nil) :fragment-pre {:com.example.foo {1 (fn [db _] (reset! fragment-pre-foo (swap! counter inc)) nil)}} :fragment-post {:com.example.foo {1 (fn [db _] (reset! fragment-post-foo (swap! counter inc)) nil)} :com.example.bar {7 (fn [db _] (reset! fragment-post-bar (swap! counter inc)) nil)}} :fragments [trivial-schema-managed-fragment-v2 additional-schema-managed-fragment-v8]}] (testing "Make sure our fragment was added correctly." (let [bar (d/entid db :com.example.bar)] (is (integer? bar)) (is (= :com.example.bar (d/ident db bar)))) (is (= {:com.example.foo 1 :com.example.bar 7} (symbolic-schema @db) [:bar/thoo :db/cardinality])))) (is (= (count "hello, world.") ; 13. (