Skip to content

Commit

Permalink
Fixed issue where reminders were not being updated correctly when upd…
Browse files Browse the repository at this point in the history
…ating an event
  • Loading branch information
AaronDDM committed Jan 18, 2025
1 parent 1aba5c8 commit 30c5d60
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Unreleased
* Added pagination support for folders
* Fixed issue where reminders were not being updated correctly when updating an event

### [2.5.2] - Released 2024-12-02
* Added support for `skypeForConsumer` as conferencing provider
Expand Down
17 changes: 0 additions & 17 deletions src/main/kotlin/com/nylas/models/UpdateEventRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -495,23 +495,6 @@ data class UpdateEventRequest(
}
}

/**
* Class representing the reminders field of an event.
*/
data class Reminders(
/**
* Whether to use the default reminders for the calendar.
* When true, uses the default reminder settings for the calendar
*/
@Json(name = "use_default")
val useDefault: Boolean? = null,
/**
* A list of reminders for the event if useDefault is set to false.
*/
@Json(name = "override")
val override: List<ReminderOverride>? = null,
)

/**
* Builder for [UpdateEventRequest].
*/
Expand Down
70 changes: 70 additions & 0 deletions src/test/kotlin/com/nylas/resources/EventsTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,76 @@ class EventsTests {
assertEquals(adapter.toJson(updateEventRequest), requestBodyCaptor.firstValue)
}

@Test
fun `updating event reminders calls requests with the correct params`() {
val eventId = "event-123"
val updateEventRequest =
UpdateEventRequest(
reminders = Reminders(
useDefault = false,
overrides = listOf(
ReminderOverride(
reminderMinutes = 15,
reminderMethod = ReminderMethod.EMAIL,
),
ReminderOverride(
reminderMinutes = 30,
reminderMethod = ReminderMethod.POPUP,
),
),
),
)
val updateEventQueryParams =
UpdateEventQueryParams(
calendarId = "calendar-id",
notifyParticipants = true,
)

events.update(grantId, eventId, updateEventRequest, updateEventQueryParams)
val pathCaptor = argumentCaptor<String>()
val typeCaptor = argumentCaptor<Type>()
val requestBodyCaptor = argumentCaptor<String>()
val queryParamCaptor = argumentCaptor<UpdateEventQueryParams>()
val overrideParamCaptor = argumentCaptor<RequestOverrides>()
verify(mockNylasClient).executePut<ListResponse<Event>>(
pathCaptor.capture(),
typeCaptor.capture(),
requestBodyCaptor.capture(),
queryParamCaptor.capture(),
overrideParamCaptor.capture(),
)

assertEquals("v3/grants/$grantId/events/$eventId", pathCaptor.firstValue)
assertEquals(Types.newParameterizedType(Response::class.java, Event::class.java), typeCaptor.firstValue)

// Parse both expected and actual JSON into Maps to compare structure while preserving field names
val jsonAdapter = JsonHelper.moshi().adapter(Map::class.java)
val actualJson = jsonAdapter.fromJson(requestBodyCaptor.firstValue)!!

val expectedJson = mapOf(
"reminders" to mapOf(
"use_default" to false,
"overrides" to listOf(
mapOf(
"reminder_minutes" to 15.0,
"reminder_method" to "email",
),
mapOf(
"reminder_minutes" to 30.0,
"reminder_method" to "popup",
),
),
),
)

assertEquals(expectedJson, actualJson)

// Also verify that the request can be correctly deserialized
val adapter = JsonHelper.moshi().adapter(UpdateEventRequest::class.java)
val actualRequest = adapter.fromJson(requestBodyCaptor.firstValue)
assertEquals(updateEventRequest, actualRequest)
}

@Test
fun `destroying a event calls requests with the correct params`() {
val eventId = "event-123"
Expand Down

0 comments on commit 30c5d60

Please sign in to comment.