-
-
Save boxxxie/4332608 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns test.api.add-user-test | |
(:use [zolodeck.utils.debug] | |
[zolodeck.demonic.schema] | |
[zolodeck.demonic.core :only [load-entity] :as demonic] | |
clojure.test) | |
(:require [api.db.datomic-login :as login])) | |
(use '[datomic.api :only [q db] :as d]) | |
(def get-user login/get-user-couchdb-id) | |
(def db-id (str (rand-int 99999))) | |
(def db-uri (str "datomic:mem://" db-id)) | |
(d/create-database db-uri) | |
(def conn (d/connect db-uri)) | |
(def simple-user-schema [ | |
(string-fact-schema :user/couch-id false "A user's login for couchdb") | |
]) | |
(def simple-user-obj {:db/id #db/id[:db.part/user] | |
:user/couch-id "paul"}) | |
(def simple-user-obj-tx [simple-user-obj]) | |
@(d/transact conn [simple-user-schema simple-user-obj-tx]) | |
(def added-user (get-user (:user/couch-id simple-user-obj) db-after-user-added)) | |
(def db-after-user-added (db conn)) | |
(with-test | |
(defn is-user-in-db? [user-name] (= 1 (count (get-user user-name db-after-user-added)))) | |
(is (not (is-user-in-db? "dhdhdhd" ))) | |
(is (is-user-in-db? (:user/couch-id simple-user-obj)))) | |
(with-test | |
(defn does-key-exist? | |
[key entity db] | |
(->> (ffirst entity) (d/entity db) key)) | |
(is (does-key-exist? :user/couch-id added-user db-after-user-added)) | |
(is (not (does-key-exist? :user/couch-id2 added-user db-after-user-added)))) | |
(with-test | |
(defn does-keyval-exist? | |
[val key entity db] | |
(= val (->> (ffirst entity) (d/entity db) key))) | |
(is (does-keyval-exist? "paul" :user/couch-id added-user db-after-user-added)) | |
(is (not (does-keyval-exist? "not paul" :user/couch-id2 added-user db-after-user-added)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment