@@ -8,45 +8,39 @@ sub test_calendarevent_defaultalerts_calalarmd
8
8
9
9
my $jmap = $self -> {jmap };
10
10
my $caldav = $self -> {caldav };
11
+ my $now = DateTime-> now();
12
+ $now -> set_time_zone(' Australia/Sydney' );
11
13
12
- my $calendarId = $caldav -> NewCalendar({name => ' foo' });
13
- $self -> assert_not_null($calendarId );
14
-
14
+ xlog $self , " Create calendar without default alarms" ;
15
15
my $res = $jmap -> CallMethods([
16
16
[' Calendar/set' , {
17
17
create => {
18
18
1 => {
19
19
name => ' test' ,
20
- defaultAlertsWithTime => {
21
- alert1 => {
22
- ' @type' => ' Alert' ,
23
- trigger => {
24
- ' @type' => ' OffsetTrigger' ,
25
- relativeTo => ' start' ,
26
- offset => ' PT0S' ,
27
- },
28
- action => ' display' ,
29
- },
30
- }
31
20
},
32
21
}
33
22
}, ' R1' ],
34
23
]);
35
24
my $calendarId = $res -> [0][1]{created }{1 }{id };
36
25
$self -> assert_not_null($calendarId );
37
26
38
- my $now = DateTime-> now();
39
- $now -> set_time_zone(' Australia/Sydney' );
27
+ xlog $self , " Remove any default alarms" ;
28
+ $res = $jmap -> CallMethods([
29
+ [' Calendar/set' , {
30
+ update => {
31
+ $calendarId => {
32
+ defaultAlertsWithTime => undef ,
33
+ },
34
+ },
35
+ }, ' R1' ],
36
+ ]);
37
+ $self -> assert(exists $res -> [0][1]{updated }{$calendarId });
40
38
41
- # define the event to start in a few seconds
39
+ xlog $self , " Create event that starts in an hour, ocurring daily " ;
42
40
my $startdt = $now -> clone();
43
- $startdt -> add(DateTime::Duration-> new(seconds => 2 ));
41
+ $startdt -> add(DateTime::Duration-> new(hours => 1 ));
44
42
my $start = $startdt -> strftime(' %Y%m%dT%H%M%S' );
45
43
46
- my $enddt = $startdt -> clone();
47
- $enddt -> add(DateTime::Duration-> new(seconds => 15));
48
- my $end = $enddt -> strftime(' %Y%m%dT%H%M%S' );
49
-
50
44
my $uuid = " 574E2CD0-2D2A-4554-8B63-C7504481D3A9" ;
51
45
my $href = " $calendarId /$uuid .ics" ;
52
46
my $card = <<EOF ;
@@ -72,35 +66,95 @@ END:VTIMEZONE
72
66
BEGIN:VEVENT
73
67
CREATED:20150806T234327Z
74
68
UID:574E2CD0-2D2A-4554-8B63-C7504481D3A9
75
- DTEND;TZID=Australia/Sydney:$end
76
69
TRANSP:OPAQUE
77
70
SUMMARY:Simple
78
71
DTSTART;TZID=Australia/Sydney:$start
72
+ DURATION:PT15S
73
+ RRULE:FREQ=DAILY
79
74
DTSTAMP:20150806T234327Z
80
75
SEQUENCE:0
81
76
X-JMAP-USEDEFAULTALERTS;VALUE=BOOLEAN:TRUE
77
+ BEGIN:VALARM
78
+ UID:e01ddb42-f2f1-4e39-9d94-17fcc5aa320c
79
+ TRIGGER:-PT30M
80
+ ACTION:DISPLAY
81
+ SUMMARY:Hello
82
+ END:VALARM
82
83
END:VEVENT
83
84
END:VCALENDAR
84
85
EOF
85
86
86
87
$caldav -> Request(' PUT' , $href , $card , ' Content-Type' => ' text/calendar' );
87
88
89
+ xlog $self , " Assert that useDefaultAlerts got rewritten to false" ;
90
+ $res = $jmap -> CallMethods([
91
+ [' CalendarEvent/get' , {
92
+ properties => [' useDefaultAlerts' ],
93
+ }, ' R1' ],
94
+ ]);
95
+ $self -> assert_equals(JSON::false, $res -> [0][1]{list }[0]{useDefaultAlerts });
96
+ my $eventId = $res -> [0][1]{list }[0]{id };
97
+
88
98
# clean notification cache
89
99
$self -> {instance }-> getnotify();
90
100
91
- xlog " No alarm triggered before the event" ;
92
- $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $now -> epoch() - 60 );
93
- $self -> assert_alarms();
94
-
95
- xlog " Alarm triggered in the first minute after the event" ;
96
- $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $now -> epoch() + 60 );
101
+ xlog " Custom alarm triggers half an hour before event" ;
102
+ $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $startdt -> epoch - 1800);
97
103
$self -> assert_alarms({summary => ' Simple' , start => $start });
98
104
99
- xlog " No further alarm triggered for the event" ;
100
- $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $now -> epoch() + 120 );
105
+ xlog $self , " Set default alarms to trigger at start of event" ;
106
+ $res = $jmap -> CallMethods([
107
+ [' Calendar/set' , {
108
+ update => {
109
+ $calendarId => {
110
+ defaultAlertsWithTime => {
111
+ alert1 => {
112
+ ' @type' => ' Alert' ,
113
+ trigger => {
114
+ ' @type' => ' OffsetTrigger' ,
115
+ relativeTo => ' start' ,
116
+ offset => ' PT0S' ,
117
+ },
118
+ action => ' display' ,
119
+ },
120
+ }
121
+ },
122
+ }
123
+ }, ' R1' ],
124
+ ]);
125
+ $self -> assert(exists $res -> [0][1]{updated }{$calendarId });
126
+
127
+ xlog $self , " Set useDefaultAlerts=true for event" ;
128
+ $res = $jmap -> CallMethods([
129
+ [' CalendarEvent/set' , {
130
+ update => {
131
+ $eventId => {
132
+ useDefaultAlerts => JSON::true,
133
+ }
134
+ },
135
+ }, ' R1' ],
136
+ ]);
137
+ $self -> assert(exists $res -> [0][1]{updated }{$eventId });
138
+
139
+ xlog $self , " Forward clock by one day" ;
140
+ $now -> add(DateTime::Duration-> new(days => 1));
141
+ $startdt -> add(DateTime::Duration-> new(days => 1));
142
+ $start = $startdt -> strftime(' %Y%m%dT%H%M%S' );
143
+ $start = $startdt -> strftime(' %Y%m%dT%H%M%S' );
144
+
145
+ # clean notification cache
146
+ $self -> {instance }-> getnotify();
147
+
148
+ xlog " Custom alarm does not trigger half an hour before event" ;
149
+ $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $startdt -> epoch - 1800);
101
150
$self -> assert_alarms();
102
151
103
- my $res = $jmap -> CallMethods([
152
+ xlog " Default alarm triggers at start of event" ;
153
+ $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $startdt -> epoch);
154
+ $self -> assert_alarms({summary => ' Simple' , start => $start });
155
+
156
+ xlog $self , " Update default alarms to trigger half an hour after event" ;
157
+ $res = $jmap -> CallMethods([
104
158
[' Calendar/set' , {
105
159
update => {
106
160
$calendarId => {
110
164
trigger => {
111
165
' @type' => ' OffsetTrigger' ,
112
166
relativeTo => ' start' ,
113
- offset => ' PT1M ' ,
167
+ offset => ' PT30M ' ,
114
168
},
115
169
action => ' display' ,
116
170
},
@@ -121,11 +175,52 @@ EOF
121
175
]);
122
176
$self -> assert(exists $res -> [0][1]{updated }{$calendarId });
123
177
124
- xlog " Assert alarm gets triggered two minutes after the event" ;
125
- $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $now -> epoch() + 120 );
178
+ xlog $self , " Forward clock by one day" ;
179
+ $now -> add(DateTime::Duration-> new(days => 1));
180
+ $startdt -> add(DateTime::Duration-> new(days => 1));
181
+ $start = $startdt -> strftime(' %Y%m%dT%H%M%S' );
182
+
183
+ xlog " Custom alarm does not trigger half an hour before event" ;
184
+ $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $startdt -> epoch - 1800);
185
+ $self -> assert_alarms();
186
+
187
+ xlog " Former default alarm does not trigger at start of event" ;
188
+ $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $startdt -> epoch);
189
+ $self -> assert_alarms();
190
+
191
+ xlog " Current default alarm gets triggered half an hour after the event" ;
192
+ $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $startdt -> epoch + 1800 );
126
193
$self -> assert_alarms({summary => ' Simple' , start => $start });
127
- }
128
194
195
+ xlog $self , " Forward clock by one day" ;
196
+ $now -> add(DateTime::Duration-> new(days => 1));
197
+ $startdt -> add(DateTime::Duration-> new(days => 1));
198
+ $start = $startdt -> strftime(' %Y%m%dT%H%M%S' );
199
+
200
+ xlog $self , " Remove default alarms again" ;
201
+ $res = $jmap -> CallMethods([
202
+ [' Calendar/set' , {
203
+ update => {
204
+ $calendarId => {
205
+ defaultAlertsWithTime => undef ,
206
+ },
207
+ },
208
+ }, ' R1' ],
209
+ ]);
210
+ $self -> assert(exists $res -> [0][1]{updated }{$calendarId });
211
+
212
+ xlog " Custom alarm does not trigger half an hour before event" ;
213
+ $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $startdt -> epoch - 1800);
214
+ $self -> assert_alarms();
215
+
216
+ xlog " Former default alarm does not trigger at start of event" ;
217
+ $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $startdt -> epoch);
218
+ $self -> assert_alarms();
219
+
220
+ xlog " Former default alarm does not trigger half an hour after the event" ;
221
+ $self -> {instance }-> run_command({ cyrus => 1 }, ' calalarmd' , ' -t' => $startdt -> epoch + 1800 );
222
+ $self -> assert_alarms();
223
+ }
129
224
130
225
sub _can_match {
131
226
my $event = shift ;
0 commit comments