Permalink
Browse files

Add tests

  • Loading branch information...
mcramm committed Dec 14, 2016
1 parent 0fc4038 commit 0c1fbe527b442ebdbc342385cc75b0beef2171fc
@@ -2,8 +2,8 @@
(:require [ragtime.repl]
[ragtime.jdbc]
[environ.core :refer [env]]
[postgres-example.components.postgres :as postgres]
))
[eftest.runner :as eftest]
[postgres-example.components.postgres :as postgres]))

(def config
{:datastore (ragtime.jdbc/sql-database (env :database-url))
@@ -23,3 +23,7 @@

(defn create-store []
(postgres/build (env :database-url)))

(defn test []
(let [path "test/postgres_example/integration"]
(eftest/run-tests (eftest/find-tests path))))
@@ -16,7 +16,7 @@
:target-path "target/%s"
:profiles {:uberjar {:aot :all}
:dev [:project/dev]
:project/dev {:dependencies []
:project/dev {:dependencies [[eftest "0.1.2"]]
:resource-paths ["resources/"]
:source-paths ["dev"]
:repl-options {:init-ns user}}})
@@ -5,7 +5,6 @@
[postgres-example.components.postgres])
(:import [postgres_example.components.postgres Postgres]))


(defprotocol AccountOps
(by-id [this id])
(create! [this status])
@@ -0,0 +1,32 @@
(ns postgres-example.integration.entities.accounts
(:require [clojure.test :refer :all]
[postgres-example.test-helpers :refer [store db-transaction-fixture]]
[postgres-example.entities.accounts :refer :all]))

(use-fixtures :each db-transaction-fixture)

(deftest create!-test
(testing "create! creates and returns an account"
(let [account (create! store "open")]
(is (not (nil? (:account/id account))))
(is (= "open" (:account/status account))))))

(deftest by-id-test
(testing "by-id returns the correct account by id"
(let [account (create! store "open")]
(is (= account
(by-id store (:account/id account)))))))

(deftest set-opened!-test
(testing "set-opened! sets an account's status to opened-status"
(let [account (create! store "closed")]
(set-opened! store account)
(is (= opened-status
(:account/status (by-id store (:account/id account))))))))

(deftest set-closed!-test
(testing "set-closed! sets an account's status to closed-status"
(let [account (create! store "open")]
(set-closed! store account)
(is (= closed-status
(:account/status (by-id store (:account/id account))))))))
@@ -0,0 +1,14 @@
(ns postgres-example.test-helpers
(:require [clojure.java.jdbc :as jdbc]
[environ.core :refer [env]]
[postgres-example.components.postgres :as postgres]))

(def ^:dynamic store nil)

(def test-db-uri (str (:database-url env) "_test"))

(defn db-transaction-fixture [f]
(jdbc/with-db-transaction [conn test-db-uri]
(jdbc/db-set-rollback-only! conn)
(binding [store (postgres/build conn)]
(f))))

0 comments on commit 0c1fbe5

Please sign in to comment.