summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/unit/test_bug1199942.js
blob: 7d78cb1244535c5c6b33b2eaf5dee40e3073a962 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
var { XPCOMUtils } = ChromeUtils.importESModule("resource://gre/modules/XPCOMUtils.sys.mjs");

XPCOMUtils.defineLazyModuleGetters(this, {
  CalAttendee: "resource:///modules/CalAttendee.jsm",
  CalEvent: "resource:///modules/CalEvent.jsm",
});

function run_test() {
  // Test the graceful handling of attendee ids for bug 1199942
  createAttendee_test();
  serializeEvent_test();
}

function createAttendee_test() {
  let data = [
    { input: "mailto:user1@example.net", expected: "mailto:user1@example.net" },
    { input: "MAILTO:user2@example.net", expected: "mailto:user2@example.net" },
    { input: "user3@example.net", expected: "mailto:user3@example.net" },
    { input: "urn:uuid:user4", expected: "urn:uuid:user4" },
  ];
  let event = new CalEvent();
  for (let test of data) {
    let attendee = new CalAttendee();
    attendee.id = test.input;
    event.addAttendee(attendee);
    let readAttendee = event.getAttendeeById(cal.email.prependMailTo(test.input));
    equal(readAttendee.id, test.expected);
  }
}

function serializeEvent_test() {
  let ics =
    "BEGIN:VCALENDAR\n" +
    "PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN\n" +
    "VERSION:2.0\n" +
    "BEGIN:VEVENT\n" +
    "CREATED:20150801T213509Z\n" +
    "LAST-MODIFIED:20150830T164104Z\n" +
    "DTSTAMP:20150830T164104Z\n" +
    "UID:a84c74d1-cfc6-4ddf-9d60-9e4afd8238cf\n" +
    "SUMMARY:New Event\n" +
    "ORGANIZER;RSVP=TRUE;CN=Tester1;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:user1@example.net\n" +
    "ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:MAILTO:user2@example.net\n" +
    "ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:mailto:user3@example.net\n" +
    "ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:user4@example.net\n" +
    "ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:urn:uuid:user5\n" +
    "DTSTART:20150729T103000Z\n" +
    "DTEND:20150729T113000Z\n" +
    "TRANSP:OPAQUE\n" +
    "END:VEVENT\n" +
    "END:VCALENDAR\n";

  let expectedIds = [
    "mailto:user2@example.net",
    "mailto:user3@example.net",
    "mailto:user4@example.net",
    "urn:uuid:user5",
  ];
  let event = createEventFromIcalString(ics);
  let attendees = event.getAttendees();

  // check whether all attendees get returned with expected id
  for (let attendee of attendees) {
    ok(expectedIds.includes(attendee.id));
  }

  // serialize the event again and check whether the attendees still are in shape
  let serializer = Cc["@mozilla.org/calendar/ics-serializer;1"].createInstance(
    Ci.calIIcsSerializer
  );
  serializer.addItems([event]);
  let serialized = ics_unfoldline(serializer.serializeToString());
  for (let id of expectedIds) {
    ok(serialized.search(id) != -1);
  }
}