-
Notifications
You must be signed in to change notification settings - Fork 33
/
websocket_relay_spec.clj
37 lines (33 loc) · 1.33 KB
/
websocket_relay_spec.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(ns more-speech.websocket-relay-spec
(:require [speclj.core :refer :all]
[clojure.core.async :as async]
[more-speech
[relay :as relay]
[websocket-relay :as ws-relay]]))
(describe "websocket-relay"
(it "can be made"
(should= {::relay/type ::ws-relay/websocket
::ws-relay/url "url"
::ws-relay/callbacks :some-callbacks
::ws-relay/socket nil}
(ws-relay/make "url" :some-callbacks)))
(it "can open and close"
(pending "be nice to relay.damus.io")
(let [relay (ws-relay/make "wss://relay.damus.io" :some-f)
relay-open (relay/open relay)
relay-closed (relay/close relay-open)]
(should (::ws-relay/open? relay-open))
(should-not (::ws-relay/open? relay-closed))))
(it "can send and receive"
(pending "be nice to relay.damus.io")
(let [chan (async/chan)
recv-f (fn [relay msg] (async/>!! chan [relay msg]))
relay (ws-relay/make "wss://relay.damus.io" recv-f)
relay-open (relay/open relay)
_ (relay/send relay-open ["test"])
f-reply (future (async/<!! chan))
[relay-r reply] (deref f-reply 1000 :timeout)
_ (relay/close relay-open)]
(should= relay relay-r )
(should= ["NOTICE" "could not parse command"] reply)))
)