(ns grub.db-spec (:require [speclj.core :refer :all] [grub.db :as db] [monger.collection :as mc] [clojure.core.async :refer [>!! !! @db/incoming-events {:event :add :_id test-id :grub test-grub :completed false}) (short-delay) (should= {:_id test-id :grub test-grub :completed false} (mc/find-one-as-map db/grub-collection {:_id test-id}))))) (describe "Complete" (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" (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 "Update" (it "should update grub info when an update event comes" (let [test-grub {:_id 123456 :grub "original"}] (mc/insert db/grub-collection test-grub) (>!! @db/incoming-events {:event :update :_id (:_id test-grub) :grub "updated"}) (short-delay) (should= {:_id (:_id test-grub) :grub "updated"} (mc/find-one-as-map db/grub-collection {:_id (:_id test-grub)}))))) (describe "Delete" (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)}))))) (describe "Clear all" (it "should delete all grubs" (let [test-grub {:_id 123456 :completed true}] (mc/insert db/grub-collection test-grub) (>!! @db/incoming-events {:event :clear-all}) (short-delay) (should (empty? (mc/find-maps db/grub-collection)))))))