started the rest api
This commit is contained in:
1 parent
516cccf4cd
commit
ad924ca5c7
10 files changed
+320
-91
No files matched your search
@@ -1,13 +0,0 @@
|
||||
(ns book.core-test
|
||||
(:require [midje.sweet :refer :all]))
|
||||
|
||||
(facts "big fact"
|
||||
(fact "about trivialities"
|
||||
(let [expt 3]
|
||||
(inc 2) => expt
|
||||
(inc 2) => expt))
|
||||
|
||||
(fact "about trivialities 2"
|
||||
(let [expt 3]
|
||||
(inc 2) => expt
|
||||
(inc 2) => expt)))
|
||||
@@ -0,0 +1,28 @@
|
||||
(ns book.exchange-test
|
||||
(:require [midje.sweet :refer :all]
|
||||
[book.exchange :refer :all]
|
||||
[book.match :refer [create-buy-book
|
||||
create-sell-book]]
|
||||
[clojure.core.async :refer [chan go >!! <!!]]))
|
||||
|
||||
(facts "the exchange as an whole"
|
||||
(fact "sell order followed by a buy order trivialities "
|
||||
(let [incoming-order-channel (chan)
|
||||
trades-channel (chan)
|
||||
new-book-order-channel (chan)
|
||||
master-book {:sell (create-sell-book) :buy (create-buy-book)}]
|
||||
(go (process-orders master-book incoming-order-channel trades-channel new-book-order-channel))
|
||||
(>!! incoming-order-channel {:type :sell :quantity 10 :price 2})
|
||||
(<!! new-book-order-channel) => {:type :sell :quantity 10 :price 2}
|
||||
(>!! incoming-order-channel {:type :buy :quantity 20 :price 2})
|
||||
(<!! trades-channel) => #:book.order{:book-id nil
|
||||
:order-id nil
|
||||
:price 2
|
||||
:quantity 10
|
||||
:type :sell}
|
||||
(<!! new-book-order-channel) => {:type :buy :quantity 10 :price 2})))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
(ns book.rest.util-test
|
||||
(:require [book.rest.util :refer [build-response]]
|
||||
[midje.sweet :refer :all]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(defn expt-response [body content-type status]
|
||||
{:body body
|
||||
:headers {"Content-Type" content-type}
|
||||
:status status})
|
||||
|
||||
(facts "the building the response"
|
||||
(fact "building the response in edn"
|
||||
(let [content-type "application/edn"
|
||||
request {:headers {"accept" content-type}}
|
||||
response "foo"
|
||||
expt (expt-response "foo" "application/edn" 200)]
|
||||
(build-response request response) => expt))
|
||||
(fact "building the response in edn"
|
||||
(let [content-type "application/edn"
|
||||
request {:headers {"accept" content-type}}
|
||||
response {:foo [1 2 3]}
|
||||
expt (expt-response "{:foo [1 2 3]}" "application/edn" 200)]
|
||||
(build-response request response) => expt))
|
||||
(fact "building the response in edn"
|
||||
(let [content-type "application/edn,application/json"
|
||||
request {:headers {"accept" content-type}}
|
||||
response {:foo [1 2 3]}
|
||||
expt (expt-response "{:foo [1 2 3]}" "application/edn" 200)]
|
||||
(build-response request response) => expt))
|
||||
(fact "building the response in json"
|
||||
(let [content-type "text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8"
|
||||
request {:headers {"accept" content-type}}
|
||||
response {:foo [1 2 3]}
|
||||
expt (expt-response "{\"foo\":[1,2,3]}" "application/json" 200)]
|
||||
(build-response request response) => expt))
|
||||
(fact "My browser should receive json"
|
||||
(let [content-type "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
|
||||
request {:headers {"accept" content-type}}
|
||||
response {:foo [1 2 3]}
|
||||
expt (expt-response "{\"foo\":[1,2,3]}" "application/json" 200)]
|
||||
(build-response request response) => expt)))
|
||||
|
||||
|
||||
Reference in new issue
Block a user