Convert tests to Midje
This commit is contained in:
parent
d7708e1382
commit
15b9ec8927
2 changed files with 76 additions and 92 deletions
|
@ -19,7 +19,8 @@
|
|||
[sablono "0.2.17"]
|
||||
[cljs-uuid "0.0.4"]
|
||||
[net.polyc0l0r/hasch "0.2.3"]]
|
||||
:profiles {:uberjar {:aot :all}}
|
||||
:profiles {:uberjar {:aot :all}
|
||||
:dev {:dependencies [[midje "1.6.3"]]}}
|
||||
:min-lein-version "2.1.2"
|
||||
:plugins [[lein-cljsbuild "1.0.3"]
|
||||
[lein-ring "0.8.6"]
|
||||
|
@ -42,7 +43,7 @@
|
|||
:output-path "target/generated/cljs"
|
||||
:rules :cljs}]}
|
||||
:source-paths ["src/clj" "src/test"]
|
||||
:test-paths ["spec/clj"]
|
||||
:test-paths ["src/test"]
|
||||
:ring {:handler grub.core/app}
|
||||
:uberjar-name "grub-standalone.jar"
|
||||
:main grub.core)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns grub.test.unit.state
|
||||
(:require [grub.shared-state :as state]
|
||||
[clojure.test :refer :all]
|
||||
[midje.sweet :refer :all]
|
||||
[hasch.core :as hasch]
|
||||
[clojure.core.async :as a :refer [<!! >!! chan go]]))
|
||||
|
||||
|
@ -10,33 +11,27 @@
|
|||
:state s}))
|
||||
(into [])))
|
||||
|
||||
(deftest diff-no-server-changes
|
||||
;; Returns empty ACK diff with hash of current state
|
||||
;; when no server changes
|
||||
(fact "Applies diff and returns empty diff when no server changes"
|
||||
(let [states (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}})
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}})
|
||||
states* (atom states)
|
||||
msg {:type :diff
|
||||
:diff {:grubs {:updated {"1" {:completed true}} :deleted #{}}}
|
||||
:hash (:hash (first states))}
|
||||
:diff {:grubs {:updated {"1" {:completed true}} :deleted #{}}}
|
||||
:hash (:hash (first states))}
|
||||
in (chan 1)
|
||||
out (chan 1)]
|
||||
(state/make-server-agent in out states*)
|
||||
(>!! in msg)
|
||||
(let [diff-response (<!! out)]
|
||||
(is (= (hashed-states
|
||||
{:grubs {"1" {:completed false, :text "2 apples"}}, :recipes {}}
|
||||
{:grubs {"1" {:completed true, :text "2 apples"}}, :recipes {}})
|
||||
@states*))
|
||||
(is (= {:type :diff
|
||||
:diff {:grubs {:deleted #{}, :updated nil}
|
||||
:recipes {:deleted #{}, :updated nil}}
|
||||
:hash (:hash (last @states*))}
|
||||
diff-response)))))
|
||||
(let [response (<!! out)]
|
||||
@states* => (hashed-states
|
||||
{:grubs {"1" {:completed false, :text "2 apples"}}, :recipes {}}
|
||||
{:grubs {"1" {:completed true, :text "2 apples"}}, :recipes {}})
|
||||
response => {:type :diff
|
||||
:diff {:grubs {:deleted #{}, :updated nil}
|
||||
:recipes {:deleted #{}, :updated nil}}
|
||||
:hash (:hash (last @states*))})))
|
||||
|
||||
(deftest diff-server-changes
|
||||
;; Returns diff with changes when server has changed
|
||||
;; Client state fetched from history
|
||||
(fact "Applies diff and returns changes when server has changed"
|
||||
(let [states (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
|
@ -44,33 +39,29 @@
|
|||
:recipes {}})
|
||||
states* (atom states)
|
||||
msg {:type :diff
|
||||
:diff {:grubs {:updated {"1" {:completed true}} :deleted #{}}}
|
||||
:hash (:hash (first states))}
|
||||
:diff {:grubs {:updated {"1" {:completed true}} :deleted #{}}}
|
||||
:hash (:hash (first states))}
|
||||
in (chan 1)
|
||||
out (chan 1)]
|
||||
(state/make-server-agent in out states*)
|
||||
(>!! in msg)
|
||||
(let [diff-response (<!! out)]
|
||||
(is (= (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed true}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}})
|
||||
@states*))
|
||||
(is (= {:type :diff
|
||||
:diff {:grubs {:deleted #{}
|
||||
:updated {"2" {:completed false, :text "3 onions"}}}
|
||||
:recipes {:deleted #{}, :updated nil}}
|
||||
:hash (hasch/uuid {:grubs {"1" {:text "2 apples" :completed true}}
|
||||
:recipes {}})}
|
||||
diff-response)))))
|
||||
(let [response (<!! out)]
|
||||
@states* => (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed true}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}})
|
||||
response => {:type :diff
|
||||
:diff {:grubs {:deleted #{}
|
||||
:updated {"2" {:completed false, :text "3 onions"}}}
|
||||
:recipes {:deleted #{}, :updated nil}}
|
||||
:hash (hasch/uuid {:grubs {"1" {:text "2 apples" :completed true}}
|
||||
:recipes {}})})))
|
||||
|
||||
(deftest diff-client-out-of-sync
|
||||
;; Returns full sync if client state not found
|
||||
;; in history
|
||||
(fact "Force full sync if client is out of sync"
|
||||
(let [states (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
|
@ -78,28 +69,25 @@
|
|||
:recipes {}})
|
||||
states* (atom states)
|
||||
msg {:type :diff
|
||||
:diff {:grubs {:updated {"0" {:completed true}} :deleted #{}}}
|
||||
:hash (:hash {:grubs {"0" {:text "milk" :completed false}}
|
||||
:recipes {}})}
|
||||
:diff {:grubs {:updated {"0" {:completed true}} :deleted #{}}}
|
||||
:hash (:hash {:grubs {"0" {:text "milk" :completed false}}
|
||||
:recipes {}})}
|
||||
in (chan 1)
|
||||
out (chan 1)]
|
||||
(state/make-server-agent in out states*)
|
||||
(>!! in msg)
|
||||
(let [diff-response (<!! out)]
|
||||
(is (= (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}})
|
||||
@states*))
|
||||
(is (= {:type :full-sync
|
||||
:state {:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}}}
|
||||
diff-response)))))
|
||||
(let [response (<!! out)]
|
||||
@states* => (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}})
|
||||
response => {:type :full-sync
|
||||
:state {:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}}})))
|
||||
|
||||
(deftest full-sync-request
|
||||
;; Returns full sync if client requests it
|
||||
(fact "Full sync if client requests it"
|
||||
(let [states (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
|
@ -111,21 +99,18 @@
|
|||
out (chan 1)]
|
||||
(state/make-server-agent in out states*)
|
||||
(>!! in msg)
|
||||
(let [diff-response (<!! out)]
|
||||
(is (= (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}})
|
||||
@states*))
|
||||
(is (= {:type :full-sync
|
||||
:state {:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}}}
|
||||
diff-response)))))
|
||||
(let [response (<!! out)]
|
||||
@states* => (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}})
|
||||
response => {:type :full-sync
|
||||
:state {:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}}})))
|
||||
|
||||
(deftest new-state
|
||||
;; Passes diff with new state to client
|
||||
(fact "Passes diffs of new states to client"
|
||||
(let [states (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
|
@ -143,21 +128,19 @@
|
|||
out (chan 1)]
|
||||
(state/make-server-agent in out states* client-state)
|
||||
(>!! in msg)
|
||||
(let [diff-response (<!! out)]
|
||||
(is (= (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}
|
||||
"3" {:text "milk" :completed false}}
|
||||
:recipes {}})
|
||||
@states*))
|
||||
(is (= {:type :diff
|
||||
:diff {:grubs {:deleted #{}
|
||||
:updated {"2" {:text "3 onions" :completed false}
|
||||
"3" {:text "milk" :completed false}}}
|
||||
:recipes {:deleted #{}, :updated nil}}
|
||||
:hash (hasch/uuid client-state)}
|
||||
diff-response)))))
|
||||
(let [response (<!! out)]
|
||||
@states* => (hashed-states
|
||||
{:grubs {"1" {:text "2 apples" :completed false}} :recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}}
|
||||
:recipes {}}
|
||||
{:grubs {"1" {:text "2 apples" :completed false}
|
||||
"2" {:text "3 onions" :completed false}
|
||||
"3" {:text "milk" :completed false}}
|
||||
:recipes {}})
|
||||
response => {:type :diff
|
||||
:diff {:grubs {:deleted #{}
|
||||
:updated {"2" {:text "3 onions" :completed false}
|
||||
"3" {:text "milk" :completed false}}}
|
||||
:recipes {:deleted #{}, :updated nil}}
|
||||
:hash (hasch/uuid client-state)})))
|
||||
|
|
Loading…
Reference in a new issue