blob: 96ce49d5810373224ff11efa20ed25f88735e4cf (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
;;; test-calendar-sync--event-to-org.el --- Tests for updated event-to-org formatter -*- lexical-binding: t; -*-
;;; Commentary:
;; Unit tests for calendar-sync--event-to-org function (updated version).
;; Tests the new property drawer format with LOCATION, ORGANIZER, STATUS, URL.
;; Covers Normal, Boundary, and Error cases.
;;; Code:
(require 'ert)
(require 'testutil-calendar-sync)
(require 'calendar-sync)
;;; Normal Cases
(ert-deftest test-calendar-sync--event-to-org-normal-all-fields ()
"Test event with all fields produces property drawer + description."
(let* ((start (test-calendar-sync-time-days-from-now 5 14 0))
(end (test-calendar-sync-time-days-from-now 5 15 0))
(event (list :summary "Team Standup"
:start start
:end end
:description "Daily sync meeting"
:location "Conference Room A"
:organizer (list :cn "John Smith" :email "john@example.com")
:status "accepted"
:url "https://meet.google.com/abc-defg-hij")))
(let ((result (calendar-sync--event-to-org event)))
;; Verify heading comes before timestamp
(should (string-match "\\* Team Standup" result))
(let ((heading-pos (match-beginning 0)))
(should (string-match "<[0-9]" result))
(should (< heading-pos (match-beginning 0))))
(should (string-match-p ":PROPERTIES:" result))
(should (string-match-p ":LOCATION: Conference Room A" result))
(should (string-match-p ":ORGANIZER: John Smith" result))
(should (string-match-p ":STATUS: accepted" result))
(should (string-match-p ":URL: https://meet.google.com/abc-defg-hij" result))
(should (string-match-p ":END:" result))
(should (string-match-p "Daily sync meeting" result)))))
(ert-deftest test-calendar-sync--event-to-org-normal-summary-and-time-only ()
"Test event with only summary and time (no drawer)."
(let* ((start (test-calendar-sync-time-days-from-now 5 14 0))
(end (test-calendar-sync-time-days-from-now 5 15 0))
(event (list :summary "Quick Chat"
:start start
:end end)))
(let ((result (calendar-sync--event-to-org event)))
(should (string-match-p "\\* Quick Chat" result))
(should-not (string-match-p ":PROPERTIES:" result)))))
;;; Boundary Cases
(ert-deftest test-calendar-sync--event-to-org-boundary-no-description ()
"Test event with location but no description."
(let* ((start (test-calendar-sync-time-days-from-now 5 14 0))
(end (test-calendar-sync-time-days-from-now 5 15 0))
(event (list :summary "Meeting"
:start start
:end end
:location "Room B")))
(let ((result (calendar-sync--event-to-org event)))
(should (string-match-p ":LOCATION: Room B" result))
;; After :END: there should be no body text
(should-not (string-match-p ":END:\n." result)))))
(ert-deftest test-calendar-sync--event-to-org-boundary-no-location-no-attendees ()
"Test event without location or attendees produces no drawer."
(let* ((start (test-calendar-sync-time-days-from-now 5 14 0))
(end (test-calendar-sync-time-days-from-now 5 15 0))
(event (list :summary "Simple Event"
:start start
:end end
:description "Just a note")))
(let ((result (calendar-sync--event-to-org event)))
(should (string-match-p "\\* Simple Event" result))
;; Description goes after timestamp, no drawer needed
(should (string-match-p "Just a note" result)))))
(ert-deftest test-calendar-sync--event-to-org-boundary-only-status ()
"Test event with only status produces drawer."
(let* ((start (test-calendar-sync-time-days-from-now 5 14 0))
(end (test-calendar-sync-time-days-from-now 5 15 0))
(event (list :summary "Status Only"
:start start
:end end
:status "tentative")))
(let ((result (calendar-sync--event-to-org event)))
(should (string-match-p ":PROPERTIES:" result))
(should (string-match-p ":STATUS: tentative" result))
(should (string-match-p ":END:" result)))))
(ert-deftest test-calendar-sync--event-to-org-boundary-description-with-asterisks ()
"Test event description containing org-special asterisks."
(let* ((start (test-calendar-sync-time-days-from-now 5 14 0))
(end (test-calendar-sync-time-days-from-now 5 15 0))
(event (list :summary "Meeting"
:start start
:end end
:description "* agenda item 1\n** sub-item")))
(let ((result (calendar-sync--event-to-org event)))
;; Description should be present
(should (string-match-p "agenda item" result)))))
(ert-deftest test-calendar-sync--event-to-org-boundary-organizer-email-only ()
"Test organizer without CN shows email."
(let* ((start (test-calendar-sync-time-days-from-now 5 14 0))
(end (test-calendar-sync-time-days-from-now 5 15 0))
(event (list :summary "Meeting"
:start start
:end end
:organizer (list :cn nil :email "org@example.com"))))
(let ((result (calendar-sync--event-to-org event)))
(should (string-match-p ":ORGANIZER: org@example.com" result)))))
;;; Error Cases
(ert-deftest test-calendar-sync--event-to-org-error-missing-summary ()
"Test event with nil summary still produces output."
(let* ((start (test-calendar-sync-time-days-from-now 5 14 0))
(end (test-calendar-sync-time-days-from-now 5 15 0))
(event (list :summary nil
:start start
:end end)))
;; Should not error - produce some output
(should (stringp (calendar-sync--event-to-org event)))))
(provide 'test-calendar-sync--event-to-org)
;;; test-calendar-sync--event-to-org.el ends here
|