aboutsummaryrefslogtreecommitdiff
path: root/tests/test-org-contacts-config-anniversaries.el
blob: 09e14d06f5221ea2beb79f3eac978b52a0a5a0aa (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;;; test-org-contacts-config-anniversaries.el --- Tests for org-contacts launch wiring -*- lexical-binding: t; -*-

;;; Commentary:
;; Covers two launch-time concerns that produced the
;; "[org-contacts] ERROR: Your custom variable `org-contacts-files' is
;; nil." message at startup:
;;
;;   1. `org-contacts-files' must be set to the configured contacts file
;;      as soon as the module is required -- not deferred behind the
;;      package load -- so the agenda-finalize anniversaries hook never
;;      sees it nil.
;;   2. `cj/org-contacts-anniversaries-safe' must not call
;;      `org-contacts-anniversaries' when `org-contacts-files' is nil
;;      (the function messages an error rather than signalling, so the
;;      wrapper's `ignore-errors' can't suppress it).
;;
;; `org-agenda' is required first so the `with-eval-after-load' that
;; defines the wrapper fires.

;;; Code:

(require 'ert)
(require 'cl-lib)

(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'user-constants)
(require 'org-agenda)
(require 'org-contacts-config)

(ert-deftest test-org-contacts-config-files-configured-on-load ()
  "Normal: requiring the module sets `org-contacts-files' to the contacts file."
  (should (equal org-contacts-files (list contacts-file))))

(ert-deftest test-org-contacts-anniversaries-safe-skips-when-files-nil ()
  "Error: wrapper does not call `org-contacts-anniversaries' when files are nil."
  (let ((called nil)
        (org-contacts-files nil))
    (cl-letf (((symbol-function 'org-contacts-anniversaries)
               (lambda (&rest _) (setq called t))))
      (cj/org-contacts-anniversaries-safe))
    (should-not called)))

(ert-deftest test-org-contacts-anniversaries-safe-runs-when-files-set ()
  "Normal: wrapper calls `org-contacts-anniversaries' when files are configured."
  (let ((called nil)
        (org-contacts-files (list contacts-file)))
    (cl-letf (((symbol-function 'org-contacts-anniversaries)
               (lambda (&rest _) (setq called t))))
      (cj/org-contacts-anniversaries-safe))
    (should called)))

(provide 'test-org-contacts-config-anniversaries)
;;; test-org-contacts-config-anniversaries.el ends here