Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue where reminders were not being updated correctly when updating an event #261

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Unreleased
* Made `NylasClient` and its methods open to enable mocking in tests
* 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
Loading