summaryrefslogtreecommitdiff
path: root/tests/test-calendar-sync--get-recurrence-id.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-02-03 07:39:50 -0600
committerCraig Jennings <c@cjennings.net>2026-02-03 07:39:50 -0600
commit84a02097bf842e96f7f4dd4e4ac39e78faf64989 (patch)
treea3a87b6b3d75ae4179924a62c318b05fa0bd0751 /tests/test-calendar-sync--get-recurrence-id.el
parent089a4313660cb8af1eca3829ffbdbae70f72333a (diff)
feat(calendar-sync): add RECURRENCE-ID exception handling for recurring events
Handle rescheduled instances of recurring calendar events by processing RECURRENCE-ID properties from ICS files. When someone reschedules a single instance of a recurring meeting in Google Calendar, the calendar-sync module now shows the rescheduled time instead of the original RRULE time. New functions: - calendar-sync--get-recurrence-id: Extract RECURRENCE-ID from event - calendar-sync--get-recurrence-id-line: Get full line with TZID params - calendar-sync--parse-recurrence-id: Parse into (year month day hour minute) - calendar-sync--collect-recurrence-exceptions: Collect all exceptions by UID - calendar-sync--occurrence-matches-exception-p: Match occurrences to exceptions - calendar-sync--apply-single-exception: Apply exception data to occurrence - calendar-sync--apply-recurrence-exceptions: Apply all exceptions to occurrences Also adds DeepSat calendar configuration (dcal-file) to user-constants, init.el, and org-agenda-config. 48 unit and integration tests added covering normal, boundary, and error cases.
Diffstat (limited to 'tests/test-calendar-sync--get-recurrence-id.el')
-rw-r--r--tests/test-calendar-sync--get-recurrence-id.el111
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/test-calendar-sync--get-recurrence-id.el b/tests/test-calendar-sync--get-recurrence-id.el
new file mode 100644
index 00000000..4ff09e34
--- /dev/null
+++ b/tests/test-calendar-sync--get-recurrence-id.el
@@ -0,0 +1,111 @@
+;;; test-calendar-sync--get-recurrence-id.el --- Tests for RECURRENCE-ID extraction -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Unit tests for calendar-sync--get-recurrence-id function.
+;; Tests extraction of RECURRENCE-ID property from VEVENT strings.
+;; Following quality-engineer.org guidelines: one function per file.
+
+;;; 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)
+
+;;; Normal Cases
+
+(ert-deftest test-calendar-sync--get-recurrence-id-normal-simple-returns-value ()
+ "Test extracting simple RECURRENCE-ID without TZID."
+ (let ((event "BEGIN:VEVENT
+DTSTART:20260210T090000
+RECURRENCE-ID:20260203T090000
+SUMMARY:Rescheduled Meeting
+END:VEVENT"))
+ (should (string= "20260203T090000"
+ (calendar-sync--get-recurrence-id event)))))
+
+(ert-deftest test-calendar-sync--get-recurrence-id-normal-with-z-suffix-returns-value ()
+ "Test extracting RECURRENCE-ID with UTC Z suffix."
+ (let ((event "BEGIN:VEVENT
+DTSTART:20260210T170000Z
+RECURRENCE-ID:20260203T170000Z
+SUMMARY:UTC Event
+END:VEVENT"))
+ (should (string= "20260203T170000Z"
+ (calendar-sync--get-recurrence-id event)))))
+
+(ert-deftest test-calendar-sync--get-recurrence-id-normal-with-tzid-returns-value ()
+ "Test extracting RECURRENCE-ID with TZID parameter.
+The TZID parameter should be ignored, only value returned."
+ (let ((event "BEGIN:VEVENT
+DTSTART;TZID=Europe/Tallinn:20260210T170000
+RECURRENCE-ID;TZID=Europe/Tallinn:20260203T170000
+SUMMARY:Tallinn Meeting
+END:VEVENT"))
+ (should (string= "20260203T170000"
+ (calendar-sync--get-recurrence-id event)))))
+
+(ert-deftest test-calendar-sync--get-recurrence-id-normal-date-only-returns-value ()
+ "Test extracting date-only RECURRENCE-ID for all-day event exceptions."
+ (let ((event "BEGIN:VEVENT
+DTSTART:20260210
+RECURRENCE-ID:20260203
+SUMMARY:All Day Exception
+END:VEVENT"))
+ (should (string= "20260203"
+ (calendar-sync--get-recurrence-id event)))))
+
+;;; Boundary Cases
+
+(ert-deftest test-calendar-sync--get-recurrence-id-boundary-no-recurrence-id-returns-nil ()
+ "Test that event without RECURRENCE-ID returns nil."
+ (let ((event "BEGIN:VEVENT
+DTSTART:20260203T090000
+SUMMARY:Regular Event
+END:VEVENT"))
+ (should (null (calendar-sync--get-recurrence-id event)))))
+
+(ert-deftest test-calendar-sync--get-recurrence-id-boundary-recurrence-id-multiline-returns-partial ()
+ "Test RECURRENCE-ID with continuation line (RFC 5545 folding).
+Note: Current implementation returns partial value for folded lines.
+Full continuation line support is a future enhancement."
+ (let ((event "BEGIN:VEVENT
+DTSTART:20260210T090000
+RECURRENCE-ID;TZID=America/Los_Angeles;VALUE=DATE-TIME:2026
+ 0203T090000
+SUMMARY:Folded Line
+END:VEVENT"))
+ ;; Current implementation returns partial value before continuation
+ ;; This is acceptable as folded RECURRENCE-ID lines are rare in practice
+ (let ((result (calendar-sync--get-recurrence-id event)))
+ (should result)
+ ;; At minimum, should capture the year portion
+ (should (string-match-p "2026" result)))))
+
+(ert-deftest test-calendar-sync--get-recurrence-id-boundary-multiple-params-returns-value ()
+ "Test RECURRENCE-ID with multiple parameters."
+ (let ((event "BEGIN:VEVENT
+DTSTART:20260210T090000
+RECURRENCE-ID;TZID=America/Chicago;VALUE=DATE-TIME:20260203T090000
+SUMMARY:Multi-param
+END:VEVENT"))
+ (should (string= "20260203T090000"
+ (calendar-sync--get-recurrence-id event)))))
+
+;;; Error Cases
+
+(ert-deftest test-calendar-sync--get-recurrence-id-error-empty-string-returns-nil ()
+ "Test that empty event string returns nil."
+ (should (null (calendar-sync--get-recurrence-id ""))))
+
+(ert-deftest test-calendar-sync--get-recurrence-id-error-nil-input-returns-nil ()
+ "Test that nil input returns nil."
+ (should (null (calendar-sync--get-recurrence-id nil))))
+
+(ert-deftest test-calendar-sync--get-recurrence-id-error-malformed-returns-nil ()
+ "Test that malformed event without proper structure returns nil."
+ (should (null (calendar-sync--get-recurrence-id "not a vevent"))))
+
+(provide 'test-calendar-sync--get-recurrence-id)
+;;; test-calendar-sync--get-recurrence-id.el ends here