Files
noise/test/noise-receive-poll-test.el
T
2026-06-10 12:43:24 -04:00

43 lines
1.7 KiB
EmacsLisp

;;; noise-receive-poll-test.el --- Tests for the receive poller -*- lexical-binding: t; -*-
(require 'ert)
(require 'noise-receive)
(ert-deftest noise-receive--poll-surfaces-error-once ()
"A failing poll messages the user once, not on every retry."
(let ((noise-receive--last-poll-error nil)
(messages nil))
(cl-letf (((symbol-function 'noise-receive)
(lambda ()
(signal 'noise-rpc-error
'("signal-cli error -32602: Method requires valid account parameter"))))
((symbol-function 'message)
(lambda (fmt &rest args)
(push (apply #'format fmt args) messages))))
(noise-receive--poll)
(noise-receive--poll))
(should (= 1 (length messages)))
(should (string-match-p "account parameter" (car messages)))
;; the hint points at the fix
(should (string-match-p "noise-select-account" (car messages)))))
(ert-deftest noise-receive--poll-recovers-and-resets ()
"After a successful poll, a recurring error is shown again."
(let ((noise-receive--last-poll-error nil)
(messages nil)
(fail t))
(cl-letf (((symbol-function 'noise-receive)
(lambda ()
(when fail
(signal 'noise-rpc-error '("connection refused")))
0))
((symbol-function 'message)
(lambda (fmt &rest args)
(push (apply #'format fmt args) messages))))
(noise-receive--poll) ; error -> message
(setq fail nil)
(noise-receive--poll) ; success -> resets
(setq fail t)
(noise-receive--poll)) ; error again -> message again
(should (= 2 (length messages)))))