summaryrefslogtreecommitdiff
path: root/spec/xmpp.scm
diff options
context:
space:
mode:
Diffstat (limited to 'spec/xmpp.scm')
-rw-r--r--spec/xmpp.scm36
1 files changed, 34 insertions, 2 deletions
diff --git a/spec/xmpp.scm b/spec/xmpp.scm
index 0b9a74b..9282e03 100644
--- a/spec/xmpp.scm
+++ b/spec/xmpp.scm
@@ -38,8 +38,40 @@
(setup 'presence2 (presence "body" #:id "1234"))
(setup 'presence3 (presence "body" #:id "1234" #:from "romeo@capulet.it"))))
-;; TODO
-(suite "register-temp-stanza-handler-for-id" (tests))
+(suite "register-temp-stanza-handler-for-id"
+ (tests
+ (test "handler is not executed if stanza with non-matching id is received" e
+ (assert-false (error?
+ (begin
+ (register-temp-stanza-handler-for-id
+ "1234a"
+ (lambda _ (throw 'error)))
+ ((@@ (gnubba xmpp) handle-stanza) (e 'stanza))))))
+ (test "handler remains if stanza with non-matching id is received" e
+ (assert-equal 1
+ (begin
+ (register-temp-stanza-handler-for-id
+ "1234b"
+ (lambda _ (throw 'error)))
+ ((@@ (gnubba xmpp) handle-stanza) (e 'stanza))
+ (hash-count (const #t)
+ (@@ (gnubba xmpp) *stanza-id-handlers*)))))
+ (test "handler is removed after execution" e
+ (assert-equal 0
+ (begin
+ (register-temp-stanza-handler-for-id
+ "999"
+ (lambda _ 'handler))
+ ((@@ (gnubba xmpp) handle-stanza) (e 'stanza))
+ (hash-count (const #t)
+ (@@ (gnubba xmpp) *stanza-id-handlers*))))))
+ (options)
+ (setups
+ (setup 'stanza (iq "payload" #:to "romeo@capulet.it" #:id "999")))
+ (teardowns
+ ;; always reset the internal state after each test
+ (teardown e (set! (@@ (gnubba xmpp) *stanza-id-handlers*)
+ (make-hash-table)))))
(suite "register-stanza-handler"
(tests