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
14 changes: 14 additions & 0 deletions src/main/kotlin/com/nylas/models/ListMessagesQueryParams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ data class ListMessagesQueryParams(
*/
@Json(name = "search_query_native")
val searchQueryNative: String? = null,
/**
* Pass in your metadata key and value pair to search for metadata.
*/
@Json(name = "metadata_pair")
val metadataPair: Map<String, String>? = null,
) : IQueryParams {
class Builder {
private var limit: Int? = null
Expand All @@ -113,6 +118,7 @@ data class ListMessagesQueryParams(
private var hasAttachment: Boolean? = null
private var fields: MessageFields? = null
private var searchQueryNative: String? = null
private var metadataPair: Map<String, String>? = null

/**
* Sets the maximum number of objects to return.
Expand Down Expand Up @@ -236,6 +242,13 @@ data class ListMessagesQueryParams(
*/
fun searchQueryNative(searchQueryNative: String?) = apply { this.searchQueryNative = searchQueryNative }

/**
* Set the metadata key and value pair to search for metadata.
* @param metadataPair The metadata key and value pair to search for metadata.
* @return The builder
*/
fun metadataPair(metadataPair: Map<String, String>?) = apply { this.metadataPair = metadataPair }

/**
* Builds the [ListMessagesQueryParams] object.
* @return The [ListMessagesQueryParams] object.
Expand All @@ -258,6 +271,7 @@ data class ListMessagesQueryParams(
hasAttachment = hasAttachment,
fields = fields,
searchQueryNative = searchQueryNative,
metadataPair = metadataPair,
)
}
}
25 changes: 25 additions & 0 deletions src/test/kotlin/com/nylas/resources/MessagesTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,31 @@ class MessagesTests {
assertEquals(queryParams, queryParamCaptor.firstValue)
}

@Test
fun `listing messages with metadata_pair calls requests with the correct params`() {
val queryParams =
ListMessagesQueryParams(
metadataPair = mapOf("campaign" to "welcome-email"),
)

messages.list(grantId, queryParams)

val pathCaptor = argumentCaptor<String>()
val typeCaptor = argumentCaptor<Type>()
val queryParamCaptor = argumentCaptor<IQueryParams>()
val overrideParamCaptor = argumentCaptor<RequestOverrides>()
verify(mockNylasClient).executeGet<ListResponse<Message>>(
pathCaptor.capture(),
typeCaptor.capture(),
queryParamCaptor.capture(),
overrideParamCaptor.capture(),
)

assertEquals("v3/grants/$grantId/messages", pathCaptor.firstValue)
assertEquals(Types.newParameterizedType(ListResponse::class.java, Message::class.java), typeCaptor.firstValue)
assertEquals(queryParams, queryParamCaptor.firstValue)
}

@Test
fun `listing messages without query params calls requests with the correct params`() {
messages.list(grantId)
Expand Down
Loading