another test, and some more helper functions
This commit is contained in:
parent
b0463fbbd7
commit
63a74707fa
|
@ -1,5 +1,6 @@
|
|||
(ns net.thegeez.browserchannel.common
|
||||
(:require
|
||||
[clojure.edn :as edn]
|
||||
[clojure.string :as string]
|
||||
[cheshire.core :as json]))
|
||||
|
||||
|
@ -40,6 +41,16 @@
|
|||
(remove string/blank? x)
|
||||
(mapv json/parse-string x))))
|
||||
|
||||
(defn get-raw-from-arrays
|
||||
[arrays idx]
|
||||
(-> (get arrays idx) first second))
|
||||
|
||||
(defn get-edn-from-arrays
|
||||
[arrays idx]
|
||||
(-> (get-raw-from-arrays arrays idx)
|
||||
(get "__edn")
|
||||
(edn/read-string)))
|
||||
|
||||
;; HACK: sleep for an arbitrary period that is based off me throwing in a
|
||||
;; random "feels good" number in there... i think this says it all, really
|
||||
(defn wait-for-agent-send-offs
|
||||
|
|
|
@ -168,6 +168,25 @@
|
|||
(is (= (-> arrays ffirst second (get "__edn") (edn/read-string))
|
||||
{:foo "bar"})))))
|
||||
|
||||
(deftest backchannel-request-send-multiple-data-to-client-test
|
||||
(let [options (update-in default-options [:headers] dissoc "Content-Type")
|
||||
create-resp (app (->new-session-request) options)
|
||||
session-id (get-session-id create-resp)
|
||||
back-resp (app (->new-backchannel-request session-id))]
|
||||
(send-data session-id {:foo "bar"})
|
||||
(send-data session-id "hello, world")
|
||||
(wait-for-agent-send-offs)
|
||||
(let [async-resp @async-output
|
||||
arrays (get-response-arrays (:body async-resp))]
|
||||
(is (= 200 (:status back-resp)))
|
||||
(is (= 200 (:status async-resp)))
|
||||
(is (not (:closed? async-resp)))
|
||||
(is (contains-all-of? (:headers async-resp) (:headers options)))
|
||||
(is (= (get-edn-from-arrays arrays 0)
|
||||
{:foo "bar"}))
|
||||
(is (= (get-edn-from-arrays arrays 1)
|
||||
"hello, world")))))
|
||||
|
||||
(deftest backchannel-request-heartbeat-test
|
||||
(let [options (-> default-options
|
||||
(update-in [:headers] dissoc "Content-Type")
|
||||
|
@ -183,5 +202,5 @@
|
|||
(is (= 200 (:status async-resp)))
|
||||
(is (not (:closed? async-resp)))
|
||||
(is (contains-all-of? (:headers async-resp) (:headers options)))
|
||||
(is (= (-> arrays ffirst second)
|
||||
(is (= (get-raw-from-arrays arrays 0)
|
||||
["noop"])))))
|
||||
|
|
Reference in a new issue