something
This commit is contained in:
1 parent
440206e924
commit
b972e6e69f
15 files changed
+230
-141
No files matched your search
@@ -0,0 +1,21 @@
|
||||
(ns skirmish.broker.db-test
|
||||
(:require [midje.sweet :refer :all]
|
||||
[orchestra.spec.test :as st]
|
||||
[datomic.api :as d]
|
||||
[skirmish.broker.db :refer [create-connection]]))
|
||||
|
||||
(st/instrument)
|
||||
|
||||
(defn create-conn []
|
||||
(let [mem-url "datomic:mem://skirmish"]
|
||||
(d/delete-database mem-url)
|
||||
(create-connection mem-url)))
|
||||
|
||||
(facts "about the db functions."
|
||||
(fact "should be able to create new users"
|
||||
(let [conn (create-conn)
|
||||
email "foo@gmail.com"
|
||||
_ @(d/transact conn [[:skirmish.broker.user/create-user email]])
|
||||
db (d/db conn)
|
||||
user (d/pull db '[*] [:skirmish.broker.user/email email])]
|
||||
(:skirmish.broker.user/email user) => email)));
|
||||
@@ -24,7 +24,7 @@
|
||||
(defn create-conn []
|
||||
(let [mem-url "datomic:mem://skirmish"]
|
||||
(d/delete-database mem-url)
|
||||
(create-connection mem-url)))
|
||||
(create-connection mem-url false)))
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
(def mock-currencies [[:zimbabwean-dollar 1000000 :currency "zimbabwean dollar" "rot13" "zd"]])
|
||||
|
||||
|
||||
;;
|
||||
(defn create-some-securities [conn]
|
||||
(let [cs (create-security conn)
|
||||
create-security-1 {:body (edn->stream (get mock-securities 0)) :headers {"accept" "application/edn"}}
|
||||
@@ -126,7 +126,15 @@
|
||||
empty-res => (spec-check ::ok)
|
||||
one-res => (spec-check ::ok)
|
||||
(body empty-res) => {:securities []}
|
||||
(body one-res) => {:securities [{:sec-id :new-currency :url "/api/1/ledger/securities/new-currency"}]})))
|
||||
(body one-res) => {:securities [{:sec-id :new-currency :url "http://localhost:1604/api/1/ledger/securities/new-currency"}]}))
|
||||
|
||||
(fact "it should add default currencies when creating new db"
|
||||
(let [mem-url "datomic:mem://skirmish-in-test"
|
||||
_ (d/delete-database mem-url)
|
||||
conn (create-connection mem-url true)
|
||||
request {:route-params {} :headers {"accept" "application/edn"}}
|
||||
resp ((get-available-securities conn) request)]
|
||||
(->> resp body :securities (map :sec-id) sort) => [:apac :apax :apbm :apdr :apmh :dapm])))
|
||||
|
||||
|
||||
(facts "about the emitting securities"
|
||||
@@ -162,10 +170,10 @@
|
||||
(fact "we should be able to get list of all accounts"
|
||||
(let [conn (create-some-securities-and-accounts (create-conn))
|
||||
req {:route-params {} :headers {"accept" "application/edn"}}
|
||||
expt [{:account-public-key "1-sec-1" :url "/api/1/ledger/accounts/1-sec-1"}
|
||||
{:account-public-key "1-sec-2" :url "/api/1/ledger/accounts/1-sec-2"}
|
||||
{:account-public-key "2-sec-1" :url "/api/1/ledger/accounts/2-sec-1"}
|
||||
{:account-public-key "2-sec-2" :url "/api/1/ledger/accounts/2-sec-2"}]]
|
||||
expt [{:account-public-key "1-sec-1" :url "http://localhost:1604/api/1/ledger/accounts/1-sec-1"}
|
||||
{:account-public-key "1-sec-2" :url "http://localhost:1604/api/1/ledger/accounts/1-sec-2"}
|
||||
{:account-public-key "2-sec-1" :url "http://localhost:1604/api/1/ledger/accounts/2-sec-1"}
|
||||
{:account-public-key "2-sec-2" :url "http://localhost:1604/api/1/ledger/accounts/2-sec-2"}]]
|
||||
((get-available-accounts conn) req) => (spec-check ::ok)
|
||||
(-> ((get-available-accounts conn) req) body :accounts sec->hash-set) => (sec->hash-set expt)))
|
||||
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
(ns skirmish.test-routes
|
||||
(ns skirmish.routes.test-api
|
||||
(:require [midje.sweet :refer :all]
|
||||
[skirmish.routes :refer :all]))
|
||||
[skirmish.routes.api :refer :all]))
|
||||
|
||||
(def my-ledger-routes {
|
||||
:name :ledger
|
||||
:domain "http://localhost:1604" ;; should somehow be in some config
|
||||
:path "/api/1/ledger"
|
||||
:routes [{:name :home :path "/"}
|
||||
{:name :accounts :path "/accounts"}
|
||||
{:name :account :path "/accounts/:account-id"}]})
|
||||
|
||||
(def my-all-routes
|
||||
[my-ledger-routes])
|
||||
(def wui-routes {
|
||||
:name :wui
|
||||
:domain "http://localhost:1534"
|
||||
:path "/api/1/wui"
|
||||
:routes [{:name :home :path "/home"}]})
|
||||
|
||||
|
||||
(def my-all-routes [my-ledger-routes wui-routes])
|
||||
|
||||
(facts "About routes"
|
||||
(fact "it should be easy to get routes"
|
||||
@@ -21,8 +23,8 @@
|
||||
|
||||
(fact "it should be able to retrieve routes"
|
||||
(get-path-for my-all-routes :ledger/accounts) => "/api/1/ledger/accounts"
|
||||
(get-path-for my-all-routes :ledger/account {:account-id "one-two"}) => "/api/1/ledger/accounts/one-two")
|
||||
(get-path-for my-all-routes :ledger/account {:account-id "one-two"}) => "/api/1/ledger/accounts/one-two"
|
||||
(get-path-for my-all-routes :wui/home) => "http://localhost:1534/api/1/wui/home")
|
||||
|
||||
(fact "it should be able to retrieve the contect"
|
||||
(get-context my-all-routes :ledger) => "/api/1/ledger"))
|
||||
;;
|
||||
@@ -4,21 +4,3 @@
|
||||
|
||||
|
||||
;; midje testing
|
||||
(facts "About events overlapping"
|
||||
(let [evt-1 #:calendar.event{:start 10 :end 15}
|
||||
evt-2 #:calendar.event{:start 12 :end 17}
|
||||
evt-3 #:calendar.event{:start 15 :end 25}
|
||||
|
||||
evt-4 #:calendar.event{:start 30 :end 40}
|
||||
evt-5 #:calendar.event{:start 33 :end 34}]
|
||||
|
||||
(fact "about edge cases"
|
||||
(get-overlapping-events nil) => empty?
|
||||
(get-overlapping-events []) => empty?)
|
||||
|
||||
(fact "about regular situations"
|
||||
(get-overlapping-events [evt-1 evt-2]) => [[evt-1 evt-2]]
|
||||
(get-overlapping-events [evt-1 evt-2 evt-3]) => [[evt-1 evt-2] [evt-2 evt-3]]
|
||||
(get-overlapping-events [evt-4 evt-5]) => [[evt-4 evt-5]])))
|
||||
|
||||
;;
|
||||
Reference in new issue
Block a user