Skip to content

Commit 24898d5

Browse files
committed
Try to fix another error that has been coming up.
1 parent 0a604f3 commit 24898d5

File tree

3 files changed

+151
-1
lines changed

3 files changed

+151
-1
lines changed

plugins/Calendar/src/Service/CalendarService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ public function syncEvents(CalendarSource $source): void
314314
// Check if the user has a sync token for this source.
315315
// If so use it to continue syncing.
316316
if ($source->sync_token) {
317-
$options['syncToken'] = $source->sync_token;
317+
$options = [
318+
'syncToken' => $source->sync_token,
319+
];
318320
}
319321

320322
try {

plugins/Calendar/tests/TestCase/Service/CalendarServiceTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,30 @@ public function testSyncUpdateExisting(): void
150150
);
151151
}
152152

153+
public function testSyncWithSyncToken(): void
154+
{
155+
// The response mock URLs are load bearing here.
156+
$this->loadResponseMocks('controller_calendarsources_sync_withsynctoken.yml');
157+
$provider = $this->makeCalendarProvider(1, '[email protected]');
158+
$source = $this->makeCalendarSource($provider->id, 'primary', [
159+
'provider_id' => 'calendar-1',
160+
'sync_token' => 'next-sync-token',
161+
]);
162+
$existing = $this->makeCalendarItem($source->id, [
163+
'provider_id' => 'calendar-event-1',
164+
'title' => 'old',
165+
'html_link' => 'old',
166+
'start_time' => '2019-01-01 12:13:14',
167+
'end_time' => '2019-01-01 13:13:14',
168+
]);
169+
$this->calendar->syncEvents($source);
170+
$updated = $this->fetchTable('Calendar.CalendarSources')->get($source->id);
171+
$this->assertNotNull($updated->last_sync);
172+
173+
$items = $this->getItems($source);
174+
$this->assertCount(3, $items);
175+
}
176+
153177
public function testSyncRemoveCancelled(): void
154178
{
155179
$this->loadResponseMocks('controller_calendarsources_sync.yml');
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
2+
-
3+
request:
4+
method: GET
5+
url: 'https://www.googleapis.com/calendar/v3/calendars/calendar-1/events?syncToken=next-sync-token'
6+
headers:
7+
content-type: application/json
8+
authorization: 'Bearer calendar-access-token'
9+
response:
10+
status:
11+
http_version: '1.1'
12+
code: '200'
13+
message: Ok
14+
headers:
15+
Content-Type: 'application/json; charset=UTF-8'
16+
body: >
17+
{
18+
"kind": "calendar#events",
19+
"etag": "etag-value",
20+
"summary": "primary",
21+
"description": "",
22+
"timeZone": "UTC",
23+
"nextPageToken": null,
24+
"nextSyncToken": "next-sync-token",
25+
"items": [
26+
{
27+
"kind": "calendar#event",
28+
"etag": "etag-value",
29+
"id": "calendar-event-1",
30+
"summary": "Dentist Appointment",
31+
"description": "",
32+
"htmlLink": "https://calendar.example.com/events/1",
33+
"start": {
34+
"date": null,
35+
"dateTime": "2021-07-22T12:13:14",
36+
"timeZone": "America/New_York"
37+
},
38+
"end": {
39+
"date": null,
40+
"dateTime": "2021-07-22T13:13:14",
41+
"timeZone": "America/New_York"
42+
},
43+
"status": "confirmed"
44+
},
45+
{
46+
"kind": "calendar#event",
47+
"etag": "etag-value",
48+
"id": "calendar-event-2",
49+
"summary": "Moving Day",
50+
"description": "",
51+
"htmlLink": "https://calendar.example.com/events/2",
52+
"start": {
53+
"date": "2021-07-28",
54+
"dateTime": null
55+
},
56+
"end": {
57+
"date": "2021-07-28",
58+
"dateTime": null
59+
},
60+
"status": "confirmed"
61+
},
62+
{
63+
"kind": "calendar#event",
64+
"etag": "etag-value",
65+
"id": "calendar-event-3",
66+
"summary": "Go camping",
67+
"description": "multi day event",
68+
"htmlLink": "https://calendar.example.com/events/3",
69+
"start": {
70+
"date": "2021-07-15",
71+
"dateTime": null
72+
},
73+
"end": {
74+
"date": "2021-07-17",
75+
"dateTime": null
76+
},
77+
"status": "confirmed"
78+
},
79+
{
80+
"kind": "calendar#event",
81+
"etag": "etag-value",
82+
"id": "calendar-event-4",
83+
"summary": "Cancelled",
84+
"description": "",
85+
"htmlLink": "https://calendar.example.com/events/4",
86+
"start": {
87+
"date": "2021-07-28",
88+
"dateTime": null
89+
},
90+
"end": {
91+
"date": "2021-07-28",
92+
"dateTime": null
93+
},
94+
"status": "cancelled"
95+
}
96+
]
97+
}
98+
-
99+
request:
100+
method: POST
101+
url: 'https://www.googleapis.com/calendar/v3/calendars/calendar-1/events/watch?eventTypes=default&eventTypes=focusTime&eventTypes=outOfOffice'
102+
headers:
103+
Host: www.googleapis.com
104+
content-type: application/json
105+
authorization: 'Bearer calendar-access-token'
106+
Accept: ''
107+
body: '{"address":"http:\/\/localhost\/google\/calendar\/notifications","id":"4c79e733-2976-43ec-a244-5d8827482e2e","token":"verifier=c4d6786b-77bc-4658-95c3-e98a1bb6cbda","type":"webhook"}'
108+
response:
109+
status:
110+
http_version: '1.1'
111+
code: '200'
112+
message: Ok
113+
headers:
114+
Content-Type: 'application/json; charset=UTF-8'
115+
Date: 'Sun, 25 Jul 2021 02:56:56 GMT'
116+
body: >
117+
{
118+
"id": "dd9935b9-41c9-45b1-988f-992d1a57d032",
119+
"kind": "api#channel",
120+
"resourceId": "calendar-1",
121+
"resourceUrl": "",
122+
"token": "verifier=581c0fb8-902d-4f67-9de3-08bb52557ca9",
123+
"expiration": 1426325213000
124+
}

0 commit comments

Comments
 (0)