Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions spec/controllers/events_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ describe Events, tags: ["event"] do
body.includes?(%("recurring_master_id": "#{master_event_id}"))
end

it "#index should skip events with missing ical_uid and return the rest" do
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/users/dev%40acaprojects.com/calendar?")
.to_return(body: File.read("./spec/fixtures/calendars/o365/show.json"))
WebMock.stub(:post, "#{ENV["PLACE_URI"]}/auth/oauth/token")
.to_return(body: File.read("./spec/fixtures/tokens/placeos_token.json"))
WebMock.stub(:get, "#{ENV["PLACE_URI"]}/api/engine/v2/systems?limit=1000&offset=0&zone_id=zone-EzcsmWbvUG6")
.to_return(body: File.read("./spec/fixtures/placeos/systemJ.json"))
WebMock.stub(:post, "https://graph.microsoft.com/v1.0/%24batch")
.to_return(body: File.read("./spec/fixtures/events/o365/batch_index_missing_ical_uid.json"))

now = 1.minutes.from_now.to_unix
later = 80.minutes.from_now.to_unix

body = JSON.parse(client.get("#{EVENTS_BASE}/?period_start=#{now}&period_end=#{later}", headers: headers).body).as_a

# The event with ical_uid should be returned
body.size.should eq(1)
body.first["title"].as_s.should eq("Event with ical_uid")
end

it "#index should return a list of events with the most detailed metadata" do
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/users/dev%40acaprojects.onmicrosoft.com/calendars")
.to_return(body: File.read("./spec/fixtures/calendars/o365/show.json"))
Expand Down
163 changes: 163 additions & 0 deletions spec/fixtures/events/o365/batch_index_missing_ical_uid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"responses": [
{
"id": 0,
"status": 200,
"body": {
"value": [
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('dev%40acaprojects.com')/calendar/events/$entity",
"@odata.etag": "W/\"dPHcBLqEvkGEgQ87r+efLAAAfPJXoQ==\"",
"id": "AAMkADE3YmQxMGQ2LTRmZDgtNDljYy1hNDg1LWM0NzFmMGI0ZTQ3YgBGAAAAAADFYQb3DJ_xSJHh14kbXHWhBwB08dwEuoS_QYSBDzuv558sAAAAAAENAAB08dwEuoS_QYSBDzuv558sAACGVOwUAAA=",
"createdDateTime": "2020-08-31T04:20:56.2768516Z",
"lastModifiedDateTime": "2020-08-31T04:20:56.7915535Z",
"changeKey": "dPHcBLqEvkGEgQ87r+efLAAAfPJXoQ==",
"categories": [],
"originalStartTimeZone": "Australia/Sydney",
"originalEndTimeZone": "Australia/Sydney",
"iCalUId": "040000008200E00074C5B7101A82E008000000008CD0441F4E7FD60100000000000000001000000087A54520ECE5BD4AA552D826F3718E7F",
"reminderMinutesBeforeStart": 15,
"isReminderOn": true,
"hasAttachments": false,
"subject": "Event with ical_uid",
"bodyPreview": "This event has an ical_uid",
"importance": "normal",
"sensitivity": "normal",
"isAllDay": false,
"isCancelled": false,
"isOrganizer": true,
"responseRequested": true,
"seriesMasterId": null,
"showAs": "busy",
"type": "singleInstance",
"webLink": "https://outlook.office365.com/owa/",
"onlineMeetingUrl": null,
"isOnlineMeeting": false,
"onlineMeetingProvider": "unknown",
"allowNewTimeProposals": true,
"recurrence": null,
"onlineMeeting": null,
"responseStatus": {
"response": "organizer",
"time": "0001-01-01T00:00:00Z"
},
"body": {
"contentType": "text",
"content": "This event has an ical_uid"
},
"start": {
"dateTime": "2020-08-31T10:00:00.0000000",
"timeZone": "Australia/Sydney"
},
"end": {
"dateTime": "2020-08-31T10:30:00.0000000",
"timeZone": "Australia/Sydney"
},
"location": {
"displayName": "",
"locationType": "default",
"uniqueIdType": "unknown",
"address": {},
"coordinates": {}
},
"locations": [],
"attendees": [
{
"type": "required",
"status": {
"response": "none",
"time": "0001-01-01T00:00:00Z"
},
"emailAddress": {
"name": "Toby Carvan",
"address": "testing@redant.com.au"
}
}
],
"organizer": {
"emailAddress": {
"name": "Developer",
"address": "dev@acaprojects.onmicrosoft.com"
}
}
},
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('dev%40acaprojects.com')/calendar/events/$entity",
"@odata.etag": "W/\"abc123==\"",
"id": "AAMkADE3YmQxMGQ2LTRmZDgtNDljYy1hNDg1LWM0NzFmMGI0ZTQ3YgBGAAAAAADFYQb3DJ_xSJHh14kbXHWhBwB08dwEuoS_QYSBDzuv558sAAAAAAENAAB08dwEuoS_QYSBDzuv558sMISSINGICALUID=",
"createdDateTime": "2020-08-31T05:00:00.0000000Z",
"lastModifiedDateTime": "2020-08-31T05:00:00.0000000Z",
"changeKey": "abc123==",
"categories": [],
"originalStartTimeZone": "Australia/Sydney",
"originalEndTimeZone": "Australia/Sydney",
"reminderMinutesBeforeStart": 15,
"isReminderOn": true,
"hasAttachments": false,
"subject": "Event missing ical_uid",
"bodyPreview": "This event is missing ical_uid field",
"importance": "normal",
"sensitivity": "normal",
"isAllDay": false,
"isCancelled": false,
"isOrganizer": true,
"responseRequested": true,
"seriesMasterId": null,
"showAs": "busy",
"type": "singleInstance",
"webLink": "https://outlook.office365.com/owa/",
"onlineMeetingUrl": null,
"isOnlineMeeting": false,
"onlineMeetingProvider": "unknown",
"allowNewTimeProposals": true,
"recurrence": null,
"onlineMeeting": null,
"responseStatus": {
"response": "organizer",
"time": "0001-01-01T00:00:00Z"
},
"body": {
"contentType": "text",
"content": "This event is missing ical_uid field"
},
"start": {
"dateTime": "2020-08-31T11:00:00.0000000",
"timeZone": "Australia/Sydney"
},
"end": {
"dateTime": "2020-08-31T11:30:00.0000000",
"timeZone": "Australia/Sydney"
},
"location": {
"displayName": "",
"locationType": "default",
"uniqueIdType": "unknown",
"address": {},
"coordinates": {}
},
"locations": [],
"attendees": [
{
"type": "required",
"status": {
"response": "none",
"time": "0001-01-01T00:00:00Z"
},
"emailAddress": {
"name": "John Doe",
"address": "john@example.com"
}
}
],
"organizer": {
"emailAddress": {
"name": "Developer",
"address": "dev@acaprojects.onmicrosoft.com"
}
}
}
]
}
}
]
}
6 changes: 5 additions & 1 deletion src/controllers/events.cr
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ class Events < Application
# However they have a new `uid` field on the beta API which we can use when it's moved to production

raise Error::BadUpstreamResponse.new("id must be present on event") unless event_id = event.id
raise Error::BadUpstreamResponse.new("ical_uid must be present on event") unless event_ical_uid = event.ical_uid
unless event_ical_uid = event.ical_uid
Log.warn { "skipping event #{event_id} due to missing ical_uid" }
next
end

# Attempt to return metadata regardless of system id availability
event_ids << event_id
Expand Down Expand Up @@ -300,6 +303,7 @@ class Events < Application
# return array of standardised events
render response_code, json: results.compact_map { |(calendar_id, system, event)|
next if icaluid && event.ical_uid != icaluid
next unless event.ical_uid

parent_meta = false
event_id = client.client_id == :office365 ? event.ical_uid : event.id
Expand Down
Loading