55 lines
2.2 KiB
Clojure
55 lines
2.2 KiB
Clojure
|
(ns grub.db-spec
|
||
|
(:require [speclj.core :refer :all]
|
||
|
[grub.db :as db]
|
||
|
[monger.collection :as mc]
|
||
|
[clojure.core.async :refer [>!! <!! timeout]]))
|
||
|
|
||
|
(def test-db "grub-test")
|
||
|
|
||
|
(defn short-delay []
|
||
|
(<!! (timeout 1)))
|
||
|
|
||
|
(describe
|
||
|
"grub.db"
|
||
|
(before (do (db/connect-and-handle-events test-db)
|
||
|
(mc/drop db/grub-collection)))
|
||
|
(describe "Create grub"
|
||
|
(it "should create a grub when a create event comes"
|
||
|
(let [test-grub "testgrub"
|
||
|
test-id 12345]
|
||
|
(>!! @db/incoming-events {:event :create :_id test-id :grub test-grub})
|
||
|
(short-delay)
|
||
|
(should=
|
||
|
{:_id test-id :grub test-grub :completed false}
|
||
|
(mc/find-one-as-map db/grub-collection {:_id test-id})))))
|
||
|
|
||
|
(describe "Complete grub"
|
||
|
(it "should complete a grub when a complete event comes"
|
||
|
(let [test-grub {:_id 123456 :completed false}]
|
||
|
(mc/insert db/grub-collection test-grub)
|
||
|
(>!! @db/incoming-events {:event :complete :_id (:_id test-grub)})
|
||
|
(short-delay)
|
||
|
(should=
|
||
|
{:_id (:_id test-grub) :completed true}
|
||
|
(mc/find-one-as-map db/grub-collection {:_id (:_id test-grub)})))))
|
||
|
|
||
|
(describe "Uncomplete grub"
|
||
|
(it "should uncomplete a grub when an uncomplete event comes"
|
||
|
(let [test-grub {:_id 123456 :completed true}]
|
||
|
(mc/insert db/grub-collection test-grub)
|
||
|
(>!! @db/incoming-events {:event :uncomplete :_id (:_id test-grub)})
|
||
|
(short-delay)
|
||
|
(should=
|
||
|
{:_id (:_id test-grub) :completed false}
|
||
|
(mc/find-one-as-map db/grub-collection {:_id (:_id test-grub)})))))
|
||
|
|
||
|
(describe "Delete grub"
|
||
|
(it "should delete a grub when a delete event comes"
|
||
|
(let [test-grub {:_id 123456 :completed true}]
|
||
|
(mc/insert db/grub-collection test-grub)
|
||
|
(>!! @db/incoming-events {:event :delete :_id (:_id test-grub)})
|
||
|
(short-delay)
|
||
|
(should=
|
||
|
nil
|
||
|
(mc/find-one-as-map db/grub-collection {:_id (:_id test-grub)}))))))
|