Rework tests slightly
This commit is contained in:
parent
16a0a5cb97
commit
a7ac7665df
3 changed files with 28 additions and 16 deletions
|
@ -60,14 +60,13 @@
|
||||||
(handler/site routes))))
|
(handler/site routes))))
|
||||||
|
|
||||||
(def default-port 3000)
|
(def default-port 3000)
|
||||||
(def integration-test-port 3456)
|
|
||||||
|
|
||||||
(defn start-server [port]
|
(defn start-server [port]
|
||||||
(httpkit/run-server app {:port port}))
|
(httpkit/run-server app {:port port}))
|
||||||
|
|
||||||
(defn run-integration-test []
|
(defn run-integration-test []
|
||||||
(let [stop-server (start-server integration-test-port)]
|
(let [stop-server (start-server integration-test/server-port)]
|
||||||
(integration-test/run integration-test-port)
|
(integration-test/run)
|
||||||
(stop-server)))
|
(stop-server)))
|
||||||
|
|
||||||
(defn start-production-server [{:keys [port mongo-url]}]
|
(defn start-production-server [{:keys [port mongo-url]}]
|
||||||
|
|
|
@ -12,6 +12,13 @@
|
||||||
(defn clear-grubs []
|
(defn clear-grubs []
|
||||||
(mc/drop @db grub-collection))
|
(mc/drop @db grub-collection))
|
||||||
|
|
||||||
|
(defn clear-recipes []
|
||||||
|
(mc/drop @db recipe-collection))
|
||||||
|
|
||||||
|
(defn clear-all []
|
||||||
|
(clear-grubs)
|
||||||
|
(clear-recipes))
|
||||||
|
|
||||||
(defmulti handle-event :event :default :unknown-event)
|
(defmulti handle-event :event :default :unknown-event)
|
||||||
|
|
||||||
(defn insert-grub [event]
|
(defn insert-grub [event]
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
[clj-webdriver.core :as webdriver]
|
[clj-webdriver.core :as webdriver]
|
||||||
[clojure.test :as test]))
|
[clojure.test :as test]))
|
||||||
|
|
||||||
|
(def server-port 3456)
|
||||||
|
(def site-url (str "http://localhost:" server-port))
|
||||||
|
|
||||||
;; Hard-coded path to chromedriver
|
;; Hard-coded path to chromedriver
|
||||||
(defn set-chromedriver-path! []
|
(defn set-chromedriver-path! []
|
||||||
(System/setProperty "webdriver.chrome.driver" "bin/chromedriver"))
|
(System/setProperty "webdriver.chrome.driver" "bin/chromedriver"))
|
||||||
|
@ -57,9 +60,9 @@
|
||||||
(taxi/to driver2 url)
|
(taxi/to driver2 url)
|
||||||
(let [recipes (repeatedly 4 get-rand-recipe )]
|
(let [recipes (repeatedly 4 get-rand-recipe )]
|
||||||
(doseq [recipe recipes]
|
(doseq [recipe recipes]
|
||||||
(add-recipe driver2 recipe))
|
(add-recipe driver1 recipe))
|
||||||
(doseq [{:keys [name]} recipes]
|
(doseq [{:keys [name]} recipes]
|
||||||
(test/is (taxi/find-element driver2 {:text name})
|
(test/is (taxi/find-element driver2 {:value name})
|
||||||
"Added recipes should appear in other browser"))))
|
"Added recipes should appear in other browser"))))
|
||||||
|
|
||||||
(defn run-tests [site-url driver1 driver2]
|
(defn run-tests [site-url driver1 driver2]
|
||||||
|
@ -67,15 +70,18 @@
|
||||||
(test-added-grubs-sync site-url driver1 driver2)
|
(test-added-grubs-sync site-url driver1 driver2)
|
||||||
(test-added-recipes-sync site-url driver1 driver2))
|
(test-added-recipes-sync site-url driver1 driver2))
|
||||||
|
|
||||||
(defn run [port]
|
(defn start-db-and-websocket-server! []
|
||||||
|
(let [db-chan (db/connect-and-handle-events "grub-integration-test")]
|
||||||
|
(db/clear-all)
|
||||||
|
(ws/pass-received-events-to-clients-and-db db-chan)))
|
||||||
|
|
||||||
|
(defn run []
|
||||||
|
(println "Starting integration test")
|
||||||
(set-chromedriver-path!)
|
(set-chromedriver-path!)
|
||||||
(let [db-chan (db/connect-and-handle-events "grub-integration-test")
|
(start-db-and-websocket-server!)
|
||||||
site-url (str "http://localhost:" port)]
|
(let [driver1 (get-driver site-url)
|
||||||
(println "Starting integration test")
|
driver2 (get-driver site-url)]
|
||||||
(ws/pass-received-events-to-clients-and-db db-chan)
|
(run-tests site-url driver1 driver2)
|
||||||
(let [driver1 (get-driver site-url)
|
(taxi/quit driver1)
|
||||||
driver2 (get-driver site-url)]
|
(taxi/quit driver2))
|
||||||
(run-tests site-url driver1 driver2)
|
(db/clear-all))
|
||||||
(taxi/quit driver1)
|
|
||||||
(taxi/quit driver2)))
|
|
||||||
(db/clear-grubs))
|
|
Loading…
Reference in a new issue