Skip to content

Instantly share code, notes, and snippets.

@hmaurer
Created July 24, 2017 22:45
Show Gist options
  • Save hmaurer/44f5c39528fe527e17925d84fc7d7820 to your computer and use it in GitHub Desktop.
Save hmaurer/44f5c39528fe527e17925d84fc7d7820 to your computer and use it in GitHub Desktop.
(ns wef-backend.core-test
(:require [clojure.test :refer :all]
[datomic.api :as d]
[datomock.core :as dm]
[integrant.core :as ig]
[wef-backend.core :refer :all]
[wef-backend.app.identity :as app.identity]))
(defn- transact-hello-identity [conn]
@(d/transact conn [{:identity/email-address "[email protected]"
:identity/user-account
{:user-account/password "azerty"}}]))
(def ^:dynamic *datomic* nil)
(defn setup [f]
(let [datomic-uri "datomic:mem://hello-test"
datomic (ig/init-key :wef-backend/datomic {:uri datomic-uri})]
(binding [*datomic* (:conn datomic)]
(f)
(d/delete-database datomic-uri))))
(use-fixtures :once setup)
(defn- fork-datomic [f]
(let [mocked-conn (dm/mock-conn (d/db *datomic*))]
(f mocked-conn)))
(defmacro fork-datomic! [& forms]
`(binding [*datomic* (dm/mock-conn (d/db *datomic*))]
~@forms))
(deftest identity
(testing "app.identity/authenticate"
(fork-datomic!
(testing
"should return an access token if an identity matches credentials"
(transact-hello-identity *datomic*)
(let [access-token (app.identity/authenticate
*datomic* "[email protected]" "azerty")]
(is (contains? access-token :access-token/value)))))
(testing
"should return nil if no identity matches credentials"
(is (= nil (app.identity/authenticate
*datomic* "[email protected]" "azerty"))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment