summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/unit/test_bug1204255.js
blob: 9277378ec43ee6f7ee6652661e121ae8d0b3f1c7 (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
/* 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 attendee duplicate handling for bug 1204255
  test_newAttendee();
  test_fromICS();
}

function test_newAttendee() {
  let data = [
    {
      input: [
        { id: "user2@example.net", partstat: "NEEDS-ACTION", cname: "NOT PREFIXED" },
        { id: "mailto:user2@example.net", partstat: "NEEDS-ACTION", cname: "PREFIXED" },
      ],
      expected: { id: "mailto:user2@example.net", partstat: "NEEDS-ACTION", cname: "PREFIXED" },
    },
    {
      input: [
        { id: "mailto:user3@example.net", partstat: "NEEDS-ACTION", cname: "PREFIXED" },
        { id: "user3@example.net", partstat: "NEEDS-ACTION", cname: "NOT PREFIXED" },
      ],
      expected: { id: "mailto:user3@example.net", partstat: "NEEDS-ACTION", cname: "NOT PREFIXED" },
    },
    {
      input: [
        { id: "mailto:user4@example.net", partstat: "ACCEPTED", cname: "PREFIXED" },
        { id: "user4@example.net", partstat: "TENTATIVE", cname: "NOT PREFIXED" },
      ],
      expected: { id: "mailto:user4@example.net", partstat: "ACCEPTED", cname: "PREFIXED" },
    },
    {
      input: [
        { id: "user5@example.net", partstat: "TENTATIVE", cname: "NOT PREFIXED" },
        { id: "mailto:user5@example.net", partstat: "ACCEPTED", cname: "PREFIXED" },
      ],
      expected: { id: "mailto:user5@example.net", partstat: "TENTATIVE", cname: "NOT PREFIXED" },
    },
    {
      input: [
        { id: "user6@example.net", partstat: "DECLINED", cname: "NOT PREFIXED" },
        { id: "mailto:user6@example.net", partstat: "TENTATIVE", cname: "PREFIXED" },
      ],
      expected: { id: "mailto:user6@example.net", partstat: "DECLINED", cname: "NOT PREFIXED" },
    },
    {
      input: [
        { id: "user7@example.net", partstat: "TENTATIVE", cname: "NOT PREFIXED" },
        { id: "mailto:user7@example.net", partstat: "DECLINED", cname: "PREFIXED" },
      ],
      expected: { id: "mailto:user7@example.net", partstat: "DECLINED", cname: "PREFIXED" },
    },
  ];

  let event = new CalEvent();
  for (let test of data) {
    for (let input of test.input) {
      let attendee = new CalAttendee();
      attendee.id = input.id;
      attendee.participationStatus = input.partstat;
      attendee.commonName = input.cname;
      event.addAttendee(attendee);
    }
    let readAttendee = event.getAttendeeById(cal.email.prependMailTo(test.expected.id));
    equal(readAttendee.id, test.expected.id);
    equal(
      readAttendee.participationStatus,
      test.expected.partstat,
      "partstat matches for " + test.expected.id
    );
    equal(
      readAttendee.commonName,
      test.expected.cname,
      "commonName matches for " + test.expected.id
    );
  }
}

function test_fromICS() {
  let ics = [
    "BEGIN:VCALENDAR",
    "PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN",
    "VERSION:2.0",
    "BEGIN:VEVENT",
    "UID:a84c74d1-cfc6-4ddf-9d60-9e4afd8238cf",
    "SUMMARY:New Event",
    "DTSTART:20150729T103000Z",
    "DTEND:20150729T113000Z",
    "ORGANIZER;RSVP=TRUE;CN=Tester1;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:user1@example.net",

    'ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;CN="NOT PREFIXED";ROLE=REQ-PARTICIPANT:user2@example.net',
    'ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;CN="PREFIXED";ROLE=REQ-PARTICIPANT:mailto:user2@example.net',

    'ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;CN="PREFIXED";ROLE=REQ-PARTICIPANT:mailto:user3@example.net',
    'ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;CN="NOT PREFIXED";ROLE=REQ-PARTICIPANT:user3@example.net',

    'ATTENDEE;RSVP=TRUE;PARTSTAT=ACCEPTED;CN="PREFIXED";ROLE=REQ-PARTICIPANT:mailto:user4@example.net',
    'ATTENDEE;RSVP=TRUE;PARTSTAT=TENTATIVE;CN="NOT PREFIXED";ROLE=REQ-PARTICIPANT:user4@example.net',

    'ATTENDEE;RSVP=TRUE;PARTSTAT=TENTATIVE;CN="NOT PREFIXED";ROLE=REQ-PARTICIPANT:user5@example.net',
    'ATTENDEE;RSVP=TRUE;PARTSTAT=ACCEPTED;CN="PREFIXED";ROLE=REQ-PARTICIPANT:mailto:user5@example.net',

    'ATTENDEE;RSVP=TRUE;PARTSTAT=DECLINED;CN="NOT PREFIXED";ROLE=REQ-PARTICIPANT:user6@example.net',
    'ATTENDEE;RSVP=TRUE;PARTSTAT=TENTATIVE;CN="PREFIXED";ROLE=REQ-PARTICIPANT:mailto:user6@example.net',

    'ATTENDEE;RSVP=TRUE;PARTSTAT=TENTATIVE;CN="NOT PREFIXED";ROLE=REQ-PARTICIPANT:user7@example.net',
    'ATTENDEE;RSVP=TRUE;PARTSTAT=DECLINED;CN="PREFIXED";ROLE=REQ-PARTICIPANT:mailto:user7@example.net',
    "END:VEVENT",
    "END:VCALENDAR",
  ].join("\n");

  let expected = [
    { id: "mailto:user2@example.net", partstat: "NEEDS-ACTION", cname: "PREFIXED" },
    { id: "mailto:user3@example.net", partstat: "NEEDS-ACTION", cname: "NOT PREFIXED" },
    { id: "mailto:user4@example.net", partstat: "ACCEPTED", cname: "PREFIXED" },
    { id: "mailto:user5@example.net", partstat: "TENTATIVE", cname: "NOT PREFIXED" },
    { id: "mailto:user6@example.net", partstat: "DECLINED", cname: "NOT PREFIXED" },
    { id: "mailto:user7@example.net", partstat: "DECLINED", cname: "PREFIXED" },
  ];
  let event = createEventFromIcalString(ics);
  let attendees = event.getAttendees();

  // check whether all attendees get returned as expected
  equal(attendees.length, expected.length);
  let count = 0;
  for (let attendee of attendees) {
    for (let exp of expected) {
      if (attendee.id == exp.id) {
        equal(attendee.participationStatus, exp.partstat, "partstat matches for " + exp.id);
        equal(attendee.commonName, exp.cname, "commonName matches for " + exp.id);
        count++;
      }
    }
  }
  equal(count, expected.length, "all attendees were processed");
}