Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

account detail - web: e2e testing #5

Merged
merged 3 commits into from Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -14,3 +14,5 @@ pom.xml.asc
.cpcache/
*DS_Store
*~
*#*
/logs/
42 changes: 41 additions & 1 deletion dev/user.clj
@@ -1,5 +1,9 @@
(ns user
(:require [mount.core :as mount]
(:require [clojure.tools.namespace.repl :as tn]
[mount.core :as mount]
[io.pedestal.http :as http]
[io.pedestal.test :as test]
[accounts.web.server :as server]
[accounts.db.conn :as c]
[accounts.logging :as l]
[accounts.db.queries :as q]))
Expand All @@ -11,3 +15,39 @@

(defn stop []
(mount/stop))

(defn refresh []
(stop)
(tn/refresh))

(defn refresh-all []
(stop)
(tn/refresh-all))

(defn go
"starts all states defined by defstate"
[]
(start)
:ready)

(defn reset
"stops all states defined by defstate, reloads modified source files, and restarts the states"
[]
(stop)
(tn/refresh :after 'user/go)
)

(mount/in-clj-mode)


;###############################################################
;
; Utils
;
;###############################################################

(defn test-request [verb url]
(test/response-for (::http/service-fn server/server) verb url))

(defn account-view []
(test-request :get "/accounts/account-1"))
4 changes: 2 additions & 2 deletions resources/config.edn
@@ -1,3 +1,3 @@
{:datomic
{:uri "datomic:mem://accounts"}
{:datomic {:uri "datomic:mem://accounts"}
:www {:port 8890}
}
4 changes: 3 additions & 1 deletion src/accounts/accounts.clj
@@ -1,5 +1,7 @@
(ns accounts.accounts
(:gen-class))
(:require [mount.core :as mount])
(:gen-class)
)

(defn -main
"I don't do a whole lot ... yet."
Expand Down
4 changes: 2 additions & 2 deletions src/accounts/web/interceptors/display.clj
Expand Up @@ -10,9 +10,9 @@
context))})

(def account-view
{:name :account-view
{:name :display-account-view
:leave
(fn [context]
(if-let [the-account (get-in context [:request :accounts :report])]
(if-let [the-account (get-in context [:retrieved :accounts :report])]
(assoc context :result the-account)
context))})
3 changes: 1 addition & 2 deletions src/accounts/web/interceptors/sets.clj
Expand Up @@ -4,5 +4,4 @@

(def account-view
(into [] (concat base/common-interceptors
account-view/validate
account-view/display)))
account-view/set)))
Expand Up @@ -13,3 +13,7 @@
(def display
[display/entity-render
display/account-view])

(def set
(into [] (concat display
validate)))
4 changes: 2 additions & 2 deletions test/accounts/web/interceptors/display_test.clj
Expand Up @@ -12,7 +12,7 @@

(deftest can-account-view
(testing "account view"
(let [context-1 {:request {:accounts {:report "account-1"}}}
context-2 {:request {:accounts {:debit "account-1"}}}]
(let [context-1 {:retrieved {:accounts {:report "account-1"}}}
context-2 {:retrieved {:accounts {:debit "account-1"}}}]
(is (= "account-1" (:result ((:leave account-view) context-1))))
(is (= context-2 ((:leave account-view) context-2))))))