Invite people to events on Federated Core calendars
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gcal-event-attendee.h"
|
||||
#include "gcal-event-organizer.h"
|
||||
@@ -454,6 +455,97 @@ event_get_attendees (void)
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
static void
|
||||
event_invite_attendees (void)
|
||||
{
|
||||
g_autoptr (GcalEvent) event = NULL;
|
||||
g_autoptr (GcalEvent) clone = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
g_autofree gchar *ical = NULL;
|
||||
GcalEventOrganizer *organizer;
|
||||
GListModel *attendees;
|
||||
|
||||
event = create_event_for_string (STUB_EVENT, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
attendees = gcal_event_get_attendees (event);
|
||||
g_assert_cmpuint (g_list_model_get_n_items (attendees), ==, 0);
|
||||
g_assert_null (gcal_event_get_organizer (event));
|
||||
|
||||
clone = gcal_event_new_from_event (event);
|
||||
g_assert_true (gcal_event_attendees_equal (event, clone));
|
||||
|
||||
gcal_event_set_organizer (clone, "me@example.com", "Me Myself");
|
||||
organizer = gcal_event_get_organizer (clone);
|
||||
g_assert_nonnull (organizer);
|
||||
g_assert_cmpstr (gcal_event_organizer_get_uri (organizer), ==, "mailto:me@example.com");
|
||||
g_assert_cmpstr (gcal_event_organizer_get_name (organizer), ==, "Me Myself");
|
||||
g_assert_false (gcal_event_attendees_equal (event, clone));
|
||||
|
||||
g_assert_true (gcal_event_add_attendee (clone, "ana@example.com", "Ana Lima"));
|
||||
g_assert_true (gcal_event_add_attendee (clone, "bo@example.com", NULL));
|
||||
g_assert_false (gcal_event_add_attendee (clone, "ANA@example.com", NULL));
|
||||
|
||||
attendees = gcal_event_get_attendees (clone);
|
||||
g_assert_cmpuint (g_list_model_get_n_items (attendees), ==, 2);
|
||||
g_assert_true (gcal_event_has_attendee (clone, "mailto:Ana@Example.com"));
|
||||
g_assert_false (gcal_event_has_attendee (clone, "carl@example.com"));
|
||||
|
||||
{
|
||||
g_autoptr (GcalEventAttendee) attendee = g_list_model_get_item (attendees, 0);
|
||||
|
||||
g_assert_cmpstr (gcal_event_attendee_get_uri (attendee), ==, "mailto:ana@example.com");
|
||||
g_assert_cmpstr (gcal_event_attendee_get_name (attendee), ==, "Ana Lima");
|
||||
g_assert_cmpint (gcal_event_attendee_get_attendee_type (attendee), ==, GCAL_EVENT_ATTENDEE_TYPE_INDIVIDUAL);
|
||||
g_assert_cmpint (gcal_event_attendee_get_role (attendee), ==, GCAL_EVENT_ATTENDEE_ROLE_REQUIRED);
|
||||
g_assert_cmpint (gcal_event_attendee_get_part_status (attendee), ==, GCAL_EVENT_ATTENDEE_PART_NEEDS_ACTION);
|
||||
g_assert_true (gcal_event_attendee_get_requires_rsvp (attendee));
|
||||
}
|
||||
|
||||
/* What the server sees */
|
||||
ical = e_cal_component_get_as_string (gcal_event_get_component (clone));
|
||||
g_assert_nonnull (strstr (ical, "ORGANIZER;CN=Me Myself:mailto:me@example.com"));
|
||||
g_assert_nonnull (strstr (ical, "mailto:ana@example.com"));
|
||||
g_assert_nonnull (strstr (ical, "mailto:bo@example.com"));
|
||||
|
||||
gcal_event_remove_attendee (clone, "mailto:ANA@example.com");
|
||||
g_assert_cmpuint (g_list_model_get_n_items (attendees), ==, 1);
|
||||
g_assert_false (gcal_event_has_attendee (clone, "ana@example.com"));
|
||||
|
||||
/* Removing someone who isn't invited does nothing */
|
||||
gcal_event_remove_attendee (clone, "carl@example.com");
|
||||
g_assert_cmpuint (g_list_model_get_n_items (attendees), ==, 1);
|
||||
|
||||
gcal_event_remove_attendee (clone, "bo@example.com");
|
||||
gcal_event_set_organizer (clone, NULL, NULL);
|
||||
g_assert_null (gcal_event_get_organizer (clone));
|
||||
g_assert_true (gcal_event_attendees_equal (event, clone));
|
||||
}
|
||||
|
||||
static void
|
||||
event_copy_attendees (void)
|
||||
{
|
||||
g_autoptr (GcalEvent) with_attendees = NULL;
|
||||
g_autoptr (GcalEvent) event = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
with_attendees = create_event_for_string (STUB_EVENT_WITH_ATTENDEES, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
event = create_event_for_string (STUB_EVENT, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
g_assert_false (gcal_event_attendees_equal (event, with_attendees));
|
||||
|
||||
gcal_event_copy_attendees (event, with_attendees);
|
||||
|
||||
g_assert_true (gcal_event_attendees_equal (event, with_attendees));
|
||||
g_assert_cmpuint (g_list_model_get_n_items (gcal_event_get_attendees (event)), ==, 2);
|
||||
g_assert_cmpstr (gcal_event_organizer_get_uri (gcal_event_get_organizer (event)), ==, "mailto:alice@example.com");
|
||||
}
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
static GDateTime *
|
||||
dt_add_second_random (GDateTime *dt)
|
||||
{
|
||||
@@ -595,6 +687,8 @@ main (gint argc,
|
||||
g_test_add_func ("/event/date/create-tzid", event_date_create_tzid);
|
||||
g_test_add_func ("/event/date/check-tz", event_date_check_tz);
|
||||
g_test_add_func ("/event/date/get-attendees", event_get_attendees);
|
||||
g_test_add_func ("/event/attendees/invite", event_invite_attendees);
|
||||
g_test_add_func ("/event/attendees/copy", event_copy_attendees);
|
||||
g_test_add_func ("/event/equal/schedule", event_schedule_equal);
|
||||
|
||||
return g_test_run ();
|
||||
|
||||
Reference in New Issue
Block a user