diff --git a/clj-browserchannel/test/net/thegeez/browserchannel/common.clj b/clj-browserchannel/test/net/thegeez/browserchannel/common.clj index 93be896..3ce9c5a 100644 --- a/clj-browserchannel/test/net/thegeez/browserchannel/common.clj +++ b/clj-browserchannel/test/net/thegeez/browserchannel/common.clj @@ -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 diff --git a/clj-browserchannel/test/net/thegeez/browserchannel/server/bind_channel_http_request_tests.clj b/clj-browserchannel/test/net/thegeez/browserchannel/server/bind_channel_http_request_tests.clj index a3a02ec..413d6d1 100644 --- a/clj-browserchannel/test/net/thegeez/browserchannel/server/bind_channel_http_request_tests.clj +++ b/clj-browserchannel/test/net/thegeez/browserchannel/server/bind_channel_http_request_tests.clj @@ -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"])))))