diff options
| author | fpi | 2024-09-16 11:33:39 +0200 | 
|---|---|---|
| committer | fpi | 2024-09-16 11:38:40 +0200 | 
| commit | 85cf32f793f7e364eda39c1b5c1738804028d89c (patch) | |
| tree | c02a49552f678ae76623cb44aaa1323fccb7f4cc | |
| parent | Update PRODID (diff) | |
Expand tests, Fix attende-list creation
| -rw-r--r-- | gnus-icalendar-request-tests.el | 69 | ||||
| -rw-r--r-- | gnus-icalendar-request.el | 16 | 
2 files changed, 80 insertions, 5 deletions
diff --git a/gnus-icalendar-request-tests.el b/gnus-icalendar-request-tests.el index 09d8198..d92ef2e 100644 --- a/gnus-icalendar-request-tests.el +++ b/gnus-icalendar-request-tests.el @@ -29,7 +29,7 @@  (require 'ert)  (require 'gnus-icalendar-request) -(ert-deftest gnus-icalendar-create-vcalendar () +(ert-deftest gnus-icalendar--create-vcalendar ()    ""    (let ((tz (getenv "TZ"))          (event "\ @@ -59,3 +59,70 @@ END:VEVENT"))        (should (string-match "^\\(BEGIN:VEVENT\\(\n\\|.\\)*\nEND:VEVENT\\)" vcalendar))        (should (string-match (match-string 1 vcalendar) event)))      (setenv "TZ" tz))) + +(ert-deftest gnus-icalendar--ical-from-event () +  "" +  (let* ((event-string "\ +BEGIN:VEVENT +DTSTAMP:20240915T120000Z +DTSTART:20240917T080000Z +DTEND:20240917T100000Z +SUMMARY:Party +DESCRIPTION:Lots of reasons to celebrate! +ATTENDEE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE:mailto:required@company.invalid +ATTENDEE;PARTSTAT=NEEDS-ACTION;ROLE=OPT-PARTICIPANT;RSVP=TRUE:mailto:optional@company.invalid +LOCATION:Party room +ORGANIZER:mailto:organizer@company.invalid +UID:ac44f43e-f5cd-4b0a-878e-add01aeb12dd +SEQUENCE:0 +END:VEVENT") +         (vcalendar-string (format "\ +BEGIN:VCALENDAR +PRODID:-//Google Inc//Google Calendar 70.9054//EN +VERSION:2.0 +CALSCALE:GREGORIAN +METHOD:REQUEST +%s +END:VCALENDAR" +                                   event-string)) +         (event (gnus-icalendar-tests--get-ical-event vcalendar-string)) +         (ical (gnus-icalendar-event--ical-from-event event))) +    (should (string-match "^BEGIN:VEVENT$" ical)) +    (should (string-match "^END:VEVENT$" ical)) +    (should (string-match "^DTSTAMP:" ical)) +    (should (string-match "^DTSTART:20240917T080000Z$" ical)) +    (should (string-match "^DTEND:20240917T100000Z$" ical)) +    (should (string-match "^SUMMARY:Party$" ical)) +    (should (string-match "^DESCRIPTION:Lots of reasons to celebrate!$" ical)) +    (should (string-match "^ATTENDEE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE:mailto:required@company.invalid$" ical)) +    (should (string-match "^ATTENDEE;PARTSTAT=NEEDS-ACTION;ROLE=OPT-PARTICIPANT;RSVP=TRUE:mailto:optional@company.invalid$" ical)) +    (should (string-match "^LOCATION:Party room$" ical)) +    (should (string-match "^ORGANIZER:mailto:organizer@company.invalid$" ical)) +    (should (string-match "^UID:ac44f43e-f5cd-4b0a-878e-add01aeb12dd$" ical)) +    (should (string-match "^SEQUENCE:0$" ical)))) + +(ert-deftest gnus-icalendar-event--create-attendee-list () +  "" +  (let* ((req-part '("Colleague1 <required@company.invalid>" +                    "Cool Colleague <required2@company.invalid>")) +        (opt-part '("My boss <required@company.invalid>")) +        (attendees (gnus-icalendar-event--create-attendee-list req-part opt-part)) +        (expected-attendee-entry "^ATTENDEE.*;ROLE=%s-PARTICIPANT.*;RSVP=TRUE:mailto:%s.*$")) +    (should (string-match (format expected-attendee-entry +                                  "REQ" (nth 0 req-part)) +                          attendees)) +    (should (string-match (format expected-attendee-entry +                                  "REQ" (nth 1 req-part)) +                          attendees)) +    (should (string-match (format expected-attendee-entry +                                  "OPT" (nth 0 opt-part)) +                          attendees)))) +(ert-deftest gnus-icalendar-event--create-empty-required-attendee-list () +  "" +  (let* ((req-part nil) +        (opt-part '("My boss <required@company.invalid>")) +        (attendees (gnus-icalendar-event--create-attendee-list req-part opt-part)) +        (expected-attendee-entry "^ATTENDEE.*;ROLE=%s-PARTICIPANT.*;RSVP=TRUE:mailto:%s.*$")) +    (should (string-match (format expected-attendee-entry +                                  "OPT" (nth 0 opt-part)) +                          attendees)))) diff --git a/gnus-icalendar-request.el b/gnus-icalendar-request.el index 61b5078..863c5aa 100644 --- a/gnus-icalendar-request.el +++ b/gnus-icalendar-request.el @@ -31,12 +31,20 @@    (when (member role '("req" "opt"))      (format "ATTENDEE;PARTSTAT=NEEDS-ACTION;ROLE=%s-PARTICIPANT;RSVP=TRUE:mailto:%s" (upcase role) attendee))) -(defun gnus-icalendar-event--create-attendee-list (req opt) +(defun gnus-icalendar-event--create-attendee-list (req &optional opt role) +  "Format a list of event attendees. + +REQ is a list of required attendees emails, OPT of optional +attendees and ROLE can be used to override the REQ attendees +role."    (concat -   (mapconcat (lambda (req) (gnus-icalendar-event--format-attendee req "req")) req "\n") +   (when req +     (mapconcat (lambda (req) (gnus-icalendar-event--format-attendee req (or role "req"))) req "\n"))     (when opt -     "\n" -     (mapconcat (lambda (opt) (gnus-icalendar-event--format-attendee opt "opt")) opt "\n")))) +     (concat "\n" +             (gnus-icalendar-event--create-attendee-list opt nil "opt")) +     ;; (mapconcat (lambda (opt) (gnus-icalendar-event--format-attendee opt "opt")) opt "\n") +     )))  (defun gnus-icalendar-event--ical-from-event (event)    (with-slots (summary description location organizer recur uid start-time end-time req-participants opt-participants) event  | 
