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

Fix when type for date #235

Merged
merged 1 commit into from
Jun 26, 2024
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
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nylas/models/When.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ sealed class When {
val date: String,
) : When() {
@Json(name = "object")
override val obj: WhenType = WhenType.DATESPAN
override val obj: WhenType = WhenType.DATE
}

/**
Expand Down
50 changes: 50 additions & 0 deletions src/test/kotlin/com/nylas/resources/EventsTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,56 @@ class EventsTests {
assertEquals("America/New_York", whenTimespan.startTimezone)
assertEquals("America/New_York", whenTimespan.endTimezone)
}

@Test
fun `Event serializes when with date type properly`() {
val adapter = JsonHelper.moshi().adapter(Event::class.java)
val jsonBuffer =
Buffer().writeUtf8(
"""
{
"busy": true,
"calendar_id": "7d93zl2palhxqdy6e5qinsakt",
"created_at": 1661874192,
"description": "Description of my new calendar",
"hide_participants": false,
"grant_id": "41009df5-bf11-4c97-aa18-b285b5f2e386",
"html_link": "https://www.google.com/calendar/event?eid=bTMzcGJrNW4yYjk4bjk3OWE4Ef3feD2VuM29fMjAyMjA2MjdUMjIwMDAwWiBoYWxsYUBueWxhcy5jb20",
"id": "5d3qmne77v32r8l4phyuksl2x",
"location": "Roller Rink",
"object": "event",
"organizer": {
"email": "[email protected]",
"name": ""
},
"read_only": false,
"reminders": {
"use_default": false,
"overrides": [
{
"reminder_minutes": 10,
"reminder_method": "email"
}
]
},
"status": "confirmed",
"title": "Birthday Party",
"updated_at": 1661874192,
"visibility": "private",
"when": {
"date": "2024-06-18",
"object": "date"
}
}
""".trimIndent(),
)

val event = adapter.fromJson(jsonBuffer)!!
assertIs<Event>(event)
assertIs<When.Date>(event.getWhen())
val whenDate = event.getWhen() as When.Date
assertEquals("2024-06-18", whenDate.date)
}
}

@Nested
Expand Down
Loading