Add test for monger.result/updated-existing? with WriteResult
This commit is contained in:
parent
c688bfa45b
commit
e5e04f8d51
1 changed files with 20 additions and 2 deletions
|
|
@ -1,9 +1,15 @@
|
||||||
(ns monger.test.result
|
(ns monger.test.result
|
||||||
(:import (com.mongodb BasicDBObject WriteResult WriteConcern))
|
(:import (com.mongodb BasicDBObject WriteResult WriteConcern) (java.util Date))
|
||||||
(:require [monger core collection convertion])
|
(:require [monger core collection convertion])
|
||||||
(:use [clojure.test]))
|
(:use [clojure.test]))
|
||||||
|
|
||||||
|
|
||||||
|
(monger.util/with-ns 'monger.core
|
||||||
|
(defonce ^:dynamic *mongodb-connection* (monger.core/connect))
|
||||||
|
(defonce ^:dynamic *mongodb-database* (monger.core/get-db "monger-test")))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; MongoCommandResult
|
;; MongoCommandResult
|
||||||
;;
|
;;
|
||||||
|
|
@ -31,10 +37,22 @@
|
||||||
(is (monger.result/has-error? result-that-has-error1))))
|
(is (monger.result/has-error? result-that-has-error1))))
|
||||||
|
|
||||||
|
|
||||||
(deftest test-updated-existing?
|
(deftest test-updated-existing?-with-db-object
|
||||||
(let [input1 (doto (BasicDBObject.) (.put "updatedExisting" true))
|
(let [input1 (doto (BasicDBObject.) (.put "updatedExisting" true))
|
||||||
input2 (doto (BasicDBObject.) (.put "updatedExisting" false))
|
input2 (doto (BasicDBObject.) (.put "updatedExisting" false))
|
||||||
input3 (BasicDBObject.)]
|
input3 (BasicDBObject.)]
|
||||||
(is (monger.result/updated-existing? input1))
|
(is (monger.result/updated-existing? input1))
|
||||||
(is (not (monger.result/updated-existing? input2)))
|
(is (not (monger.result/updated-existing? input2)))
|
||||||
(is (not (monger.result/updated-existing? input3)))))
|
(is (not (monger.result/updated-existing? input3)))))
|
||||||
|
|
||||||
|
(deftest test-updated-existing?-with-write-result
|
||||||
|
(monger.collection/remove "libraries")
|
||||||
|
(let [collection "libraries"
|
||||||
|
doc-id (monger.util/random-uuid)
|
||||||
|
date (Date.)
|
||||||
|
doc { :created-at date, :data-store "MongoDB", :language "Clojure", :_id doc-id }
|
||||||
|
modified-doc { :created-at date, :data-store "MongoDB", :language "Erlang", :_id doc-id }]
|
||||||
|
(is (not (monger.result/updated-existing? (monger.collection/update collection { :language "Clojure" } doc :upsert true))))
|
||||||
|
(is (monger.result/updated-existing? (monger.collection/update collection { :language "Clojure" } doc :upsert true)))
|
||||||
|
(monger.result/updated-existing? (monger.collection/update collection { :language "Clojure" } modified-doc :multi false :upsert true))
|
||||||
|
(monger.collection/remove collection)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue