aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-pearl-accounts.el34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test-pearl-accounts.el b/tests/test-pearl-accounts.el
index c0514a8..f8bc06b 100644
--- a/tests/test-pearl-accounts.el
+++ b/tests/test-pearl-accounts.el
@@ -477,5 +477,39 @@ account first\" — the refresh the guard tells the user to run must resolve."
(pearl--update-source-header 1 nil)
(should (null (pearl--read-buffer-account))))))
+;;; pearl-check-setup is account-aware
+
+(ert-deftest test-pearl-check-setup-accounts-mode-resolves-and-tests ()
+ "Under accounts, check-setup reports the active account and runs the test even
+when the legacy `pearl-api-key' global is unset — the account resolves the key."
+ (let ((pearl-accounts '(("work" :api-key-source (:literal "kw") :org-file "/tmp/w.org")))
+ (pearl-active-account "work") (pearl-default-account "work")
+ (pearl-api-key nil)
+ (tested nil))
+ (cl-letf (((symbol-function 'pearl-test-connection) (lambda () (setq tested t))))
+ (pearl-check-setup)
+ (should tested))))
+
+(ert-deftest test-pearl-check-setup-accounts-mode-unresolvable-skips-test ()
+ "Under accounts with no usable active account, check-setup reports and does not
+fire the connection test (and does not signal)."
+ (let ((pearl-accounts '(("work" :api-key-source (:literal "kw") :org-file "/tmp/w.org")))
+ (pearl-active-account nil) (pearl-default-account nil)
+ (tested nil))
+ (cl-letf (((symbol-function 'pearl-test-connection) (lambda () (setq tested t))))
+ (pearl-check-setup)
+ (should-not tested))))
+
+(ert-deftest test-pearl-check-setup-legacy-mode-unchanged ()
+ "In legacy mode the gate still reads the global key: set -> test, unset -> message."
+ (let ((pearl-accounts nil) (pearl-active-account nil) (pearl-default-account nil)
+ (tested nil))
+ (cl-letf (((symbol-function 'pearl-test-connection) (lambda () (setq tested t))))
+ (let ((pearl-api-key "lin_legacy")) (pearl-check-setup))
+ (should tested)
+ (setq tested nil)
+ (let ((pearl-api-key nil)) (pearl-check-setup))
+ (should-not tested))))
+
(provide 'test-pearl-accounts)
;;; test-pearl-accounts.el ends here