blob: dde0603a284b5e55435cc91d309383d2d558bc4e (
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
;;; test-integration-calendar-sync-recurrence-exceptions.el --- Integration tests -*- lexical-binding: t; -*-
;;; Commentary:
;; Integration tests for RECURRENCE-ID exception handling workflow.
;; Tests the complete pipeline: ICS parsing → RRULE expansion → exception application.
;; Tests verify the final org output contains correct relative times.
;;; Code:
(require 'ert)
(add-to-list 'load-path (expand-file-name "." (file-name-directory load-file-name)))
(add-to-list 'load-path (expand-file-name "../modules" (file-name-directory load-file-name)))
(require 'testutil-calendar-sync)
(require 'calendar-sync)
;;; Test Data - Using local times (no Z suffix) to avoid timezone conversion
(defun test-integration-make-recurring-event-with-exception-local ()
"Create ICS content with local times (no Z suffix).
Weekly meeting with one instance rescheduled from 09:00 to 10:00."
(let* ((base-start (test-calendar-sync-time-days-from-now 0 9 0))
(base-end (test-calendar-sync-time-days-from-now 0 10 0))
;; Exception: week 2 moved from 9:00 to 10:00
(exception-start (test-calendar-sync-time-days-from-now 7 10 0))
(exception-end (test-calendar-sync-time-days-from-now 7 11 0))
(recurrence-id-date (test-calendar-sync-time-days-from-now 7 9 0)))
(concat "BEGIN:VCALENDAR\n"
"VERSION:2.0\n"
"PRODID:-//Test//Test//EN\n"
;; Base recurring event - use local time (no Z)
"BEGIN:VEVENT\n"
"UID:weekly-meeting@google.com\n"
"SUMMARY:Weekly Team Sync\n"
"DTSTART:" (test-calendar-sync-ics-datetime-local base-start) "\n"
"DTEND:" (test-calendar-sync-ics-datetime-local base-end) "\n"
"RRULE:FREQ=WEEKLY;COUNT=4\n"
"END:VEVENT\n"
;; Exception event - local time
"BEGIN:VEVENT\n"
"UID:weekly-meeting@google.com\n"
"RECURRENCE-ID:" (test-calendar-sync-ics-datetime-local recurrence-id-date) "\n"
"SUMMARY:Weekly Team Sync (Rescheduled)\n"
"DTSTART:" (test-calendar-sync-ics-datetime-local exception-start) "\n"
"DTEND:" (test-calendar-sync-ics-datetime-local exception-end) "\n"
"END:VEVENT\n"
"END:VCALENDAR")))
;;; Integration Tests
(ert-deftest test-integration-recurrence-exception-org-output ()
"Test that parse-ics returns valid org content with exception summary."
(let* ((ics-content (test-integration-make-recurring-event-with-exception-local))
(org-output (calendar-sync--parse-ics ics-content)))
;; Should return string with org content
(should (stringp org-output))
(should (string-match-p "Weekly Team Sync" org-output))
;; Should contain the rescheduled event with correct summary
(should (string-match-p "Rescheduled" org-output))))
(ert-deftest test-integration-recurrence-exception-times-in-output ()
"Test that rescheduled event shows different time than regular occurrences."
(let* ((ics-content (test-integration-make-recurring-event-with-exception-local))
(org-output (calendar-sync--parse-ics ics-content)))
;; The org output should contain both 09:00 (regular) and 10:00 (rescheduled)
(should (string-match-p "09:00" org-output))
(should (string-match-p "10:00" org-output))))
(ert-deftest test-integration-recurrence-no-exceptions-org-output ()
"Test recurring event without exceptions produces correct org output."
(let* ((base-start (test-calendar-sync-time-days-from-now 0 9 0))
(base-end (test-calendar-sync-time-days-from-now 0 10 0))
(ics-content (concat "BEGIN:VCALENDAR\n"
"VERSION:2.0\n"
"BEGIN:VEVENT\n"
"UID:simple-weekly@google.com\n"
"SUMMARY:Simple Weekly\n"
"DTSTART:" (test-calendar-sync-ics-datetime-local base-start) "\n"
"DTEND:" (test-calendar-sync-ics-datetime-local base-end) "\n"
"RRULE:FREQ=WEEKLY;COUNT=3\n"
"END:VEVENT\n"
"END:VCALENDAR"))
(org-output (calendar-sync--parse-ics ics-content)))
;; Should have org content
(should (stringp org-output))
;; Should have the event title
(should (string-match-p "Simple Weekly" org-output))
;; All occurrences should be at 09:00 (no exceptions)
(should (string-match-p "09:00-10:00" org-output))))
(ert-deftest test-integration-collect-exceptions-from-ics ()
"Test that collect-recurrence-exceptions correctly extracts exceptions."
(let* ((ics-content (test-integration-make-recurring-event-with-exception-local))
(exceptions (calendar-sync--collect-recurrence-exceptions ics-content)))
;; Should have collected one exception
(should (hash-table-p exceptions))
(should (gethash "weekly-meeting@google.com" exceptions))
;; The exception should exist
(let ((exc-list (gethash "weekly-meeting@google.com" exceptions)))
(should (= 1 (length exc-list)))
;; The exception should have the rescheduled time (10:00)
(let* ((exc (car exc-list))
(exc-start (plist-get exc :start)))
(should (= 10 (nth 3 exc-start)))))))
(ert-deftest test-integration-multiple-events-with-exceptions ()
"Test multiple recurring events each with their own exceptions."
(let* ((start-a (test-calendar-sync-time-days-from-now 0 9 0))
(end-a (test-calendar-sync-time-days-from-now 0 10 0))
(start-b (test-calendar-sync-time-days-from-now 0 14 0))
(end-b (test-calendar-sync-time-days-from-now 0 15 0))
;; Exceptions for week 2: A moves from 9:00→10:00, B moves from 14:00→15:00
(exc-a-start (test-calendar-sync-time-days-from-now 7 10 0))
(exc-a-end (test-calendar-sync-time-days-from-now 7 11 0))
(exc-b-start (test-calendar-sync-time-days-from-now 7 15 0))
(exc-b-end (test-calendar-sync-time-days-from-now 7 16 0))
(rec-id-a (test-calendar-sync-time-days-from-now 7 9 0))
(rec-id-b (test-calendar-sync-time-days-from-now 7 14 0))
(ics-content
(concat "BEGIN:VCALENDAR\n"
"VERSION:2.0\n"
;; Event A base
"BEGIN:VEVENT\n"
"UID:event-a@google.com\n"
"SUMMARY:Morning Standup\n"
"DTSTART:" (test-calendar-sync-ics-datetime-local start-a) "\n"
"DTEND:" (test-calendar-sync-ics-datetime-local end-a) "\n"
"RRULE:FREQ=WEEKLY;COUNT=2\n"
"END:VEVENT\n"
;; Event A exception
"BEGIN:VEVENT\n"
"UID:event-a@google.com\n"
"RECURRENCE-ID:" (test-calendar-sync-ics-datetime-local rec-id-a) "\n"
"SUMMARY:Morning Standup (Moved)\n"
"DTSTART:" (test-calendar-sync-ics-datetime-local exc-a-start) "\n"
"DTEND:" (test-calendar-sync-ics-datetime-local exc-a-end) "\n"
"END:VEVENT\n"
;; Event B base
"BEGIN:VEVENT\n"
"UID:event-b@google.com\n"
"SUMMARY:Afternoon Review\n"
"DTSTART:" (test-calendar-sync-ics-datetime-local start-b) "\n"
"DTEND:" (test-calendar-sync-ics-datetime-local end-b) "\n"
"RRULE:FREQ=WEEKLY;COUNT=2\n"
"END:VEVENT\n"
;; Event B exception
"BEGIN:VEVENT\n"
"UID:event-b@google.com\n"
"RECURRENCE-ID:" (test-calendar-sync-ics-datetime-local rec-id-b) "\n"
"SUMMARY:Afternoon Review (Moved)\n"
"DTSTART:" (test-calendar-sync-ics-datetime-local exc-b-start) "\n"
"DTEND:" (test-calendar-sync-ics-datetime-local exc-b-end) "\n"
"END:VEVENT\n"
"END:VCALENDAR"))
(org-output (calendar-sync--parse-ics ics-content)))
(should (stringp org-output))
;; Should have both events
(should (string-match-p "Morning Standup" org-output))
(should (string-match-p "Afternoon Review" org-output))
;; Should have the "(Moved)" versions
(should (string-match-p "Moved" org-output))
;; Should have rescheduled times (10:00 and 15:00)
(should (string-match-p "10:00" org-output))
(should (string-match-p "15:00" org-output))))
(ert-deftest test-integration-declined-single-occurrence-is-dropped ()
"A recurring event with one occurrence declined via a RECURRENCE-ID override
is filtered out end-to-end, while the other occurrences survive.
This is the singly-declined-occurrence case: declining one instance of a series
in Google Calendar emits a RECURRENCE-ID override carrying the user's
PARTSTAT=DECLINED. The override must carry its attendee block all the way from
`calendar-sync--parse-exception-event' through
`calendar-sync--apply-single-exception' (status re-derivation) to
`calendar-sync--filter-declined' for the drop to happen."
(let* ((calendar-sync-skip-declined t)
(calendar-sync-user-emails '("craig@example.com"))
(base-start (test-calendar-sync-time-days-from-now 0 9 0))
(base-end (test-calendar-sync-time-days-from-now 0 10 0))
(rec-id (test-calendar-sync-time-days-from-now 7 9 0))
(decl-start (test-calendar-sync-time-days-from-now 7 9 0))
(decl-end (test-calendar-sync-time-days-from-now 7 10 0))
(ics-content
(concat "BEGIN:VCALENDAR\n"
"VERSION:2.0\n"
"BEGIN:VEVENT\n"
"UID:1on1@google.com\n"
"SUMMARY:1on1 with Hayk\n"
"DTSTART:" (test-calendar-sync-ics-datetime-local base-start) "\n"
"DTEND:" (test-calendar-sync-ics-datetime-local base-end) "\n"
"RRULE:FREQ=WEEKLY;COUNT=4\n"
"END:VEVENT\n"
;; Week 2 declined: RECURRENCE-ID override with PARTSTAT=DECLINED
"BEGIN:VEVENT\n"
"UID:1on1@google.com\n"
"RECURRENCE-ID:" (test-calendar-sync-ics-datetime-local rec-id) "\n"
"SUMMARY:1on1 with Hayk DECLINEDWEEK\n"
"ATTENDEE;CN=Craig;PARTSTAT=DECLINED:mailto:craig@example.com\n"
"DTSTART:" (test-calendar-sync-ics-datetime-local decl-start) "\n"
"DTEND:" (test-calendar-sync-ics-datetime-local decl-end) "\n"
"END:VEVENT\n"
"END:VCALENDAR"))
(org-output (calendar-sync--parse-ics ics-content)))
(should (stringp org-output))
;; The non-declined occurrences survive.
(should (string-match-p "1on1 with Hayk" org-output))
;; The declined occurrence (unique marker) is dropped.
(should-not (string-match-p "DECLINEDWEEK" org-output))))
(provide 'test-integration-calendar-sync-recurrence-exceptions)
;;; test-integration-calendar-sync-recurrence-exceptions.el ends here
|