Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrashed-dev committed Jan 31, 2024
1 parent 7918ec2 commit 644c559
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 156 deletions.
194 changes: 99 additions & 95 deletions src/test/kotlin/com/nylas/resources/DraftsTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,57 +44,58 @@ class DraftsTests {
@Test
fun `Draft serializes properly`() {
val adapter = JsonHelper.moshi().adapter(Draft::class.java)
val jsonBuffer = Buffer().writeUtf8(
"""
{
"body": "Hello, I just sent a message using Nylas!",
"cc": [
{
"email": "[email protected]"
}
],
"attachments": [
{
"content_type": "text/calendar",
"id": "4kj2jrcoj9ve5j9yxqz5cuv98",
"size": 1708
}
],
"folders": [
"8l6c4d11y1p4dm4fxj52whyr9",
"d9zkcr2tljpu3m4qpj7l2hbr0"
],
"from": [
{
"name": "Daenerys Targaryen",
"email": "[email protected]"
}
],
"grant_id": "41009df5-bf11-4c97-aa18-b285b5f2e386",
"id": "5d3qmne77v32r8l4phyuksl2x",
"object": "draft",
"reply_to": [
{
"name": "Daenerys Targaryen",
"email": "[email protected]"
}
],
"snippet": "Hello, I just sent a message using Nylas!",
"starred": true,
"subject": "Hello from Nylas!",
"thread_id": "1t8tv3890q4vgmwq6pmdwm8qgsaer",
"to": [
{
"name": "Jon Snow",
"email": "[email protected]"
}
],
"date": 1705084742,
"created_at": 1705084926
val jsonBuffer =
Buffer().writeUtf8(
"""
{
"body": "Hello, I just sent a message using Nylas!",
"cc": [
{
"email": "[email protected]"
}
],
"attachments": [
{
"content_type": "text/calendar",
"id": "4kj2jrcoj9ve5j9yxqz5cuv98",
"size": 1708
}
],
"folders": [
"8l6c4d11y1p4dm4fxj52whyr9",
"d9zkcr2tljpu3m4qpj7l2hbr0"
],
"from": [
{
"name": "Daenerys Targaryen",
"email": "[email protected]"
}
],
"grant_id": "41009df5-bf11-4c97-aa18-b285b5f2e386",
"id": "5d3qmne77v32r8l4phyuksl2x",
"object": "draft",
"reply_to": [
{
"name": "Daenerys Targaryen",
"email": "[email protected]"
}
],
"snippet": "Hello, I just sent a message using Nylas!",
"starred": true,
"subject": "Hello from Nylas!",
"thread_id": "1t8tv3890q4vgmwq6pmdwm8qgsaer",
"to": [
{
"name": "Jon Snow",
"email": "[email protected]"
}
],
"date": 1705084742,
"created_at": 1705084926
}
}
}
""".trimIndent(),
)
""".trimIndent(),
)

val draft = adapter.fromJson(jsonBuffer)!!
assertIs<Draft>(draft)
Expand Down Expand Up @@ -144,17 +145,18 @@ class DraftsTests {

@Test
fun `listing drafts calls requests with the correct params`() {
val queryParams = ListDraftsQueryParams(
limit = 10,
threadId = "thread-123",
subject = "subject",
to = listOf("to"),
cc = listOf("cc"),
bcc = listOf("bcc"),
unread = true,
starred = true,
hasAttachment = true,
)
val queryParams =
ListDraftsQueryParams(
limit = 10,
threadId = "thread-123",
subject = "subject",
to = listOf("to"),
cc = listOf("cc"),
bcc = listOf("bcc"),
unread = true,
starred = true,
hasAttachment = true,
)

drafts.list(grantId, queryParams)

Expand Down Expand Up @@ -211,34 +213,35 @@ class DraftsTests {
@Test
fun `creating a draft calls requests with the correct params`() {
val adapter = JsonHelper.moshi().adapter(CreateDraftRequest::class.java)
val createDraftRequest = CreateDraftRequest(
body = "Hello, I just sent a message using Nylas!",
cc = listOf(
EmailName(
email = "[email protected]",
name = "Test",
),
),
bcc = listOf(
EmailName(
email = "[email protected]",
name = "BCC",
),
),
snippet = "Hello, I just sent a message using Nylas!",
threadId = "thread-123",
subject = "Hello from Nylas!",
unread = false,
starred = true,
sendAt = 1620000000,
replyToMessageId = "reply-to-message-id",
trackingOptions = TrackingOptions(
label = "label",
links = true,
opens = true,
threadReplies = true,
),
)
val createDraftRequest =
CreateDraftRequest(
body = "Hello, I just sent a message using Nylas!",
cc =
listOf(
EmailName(
email = "[email protected]",
name = "Test",
),
),
bcc =
listOf(
EmailName(
email = "[email protected]",
name = "BCC",
),
),
subject = "Hello from Nylas!",
starred = true,
sendAt = 1620000000,
replyToMessageId = "reply-to-message-id",
trackingOptions =
TrackingOptions(
label = "label",
links = true,
opens = true,
threadReplies = true,
),
)

drafts.create(grantId, createDraftRequest)

Expand Down Expand Up @@ -270,12 +273,13 @@ class DraftsTests {
fun `updating a draft calls requests with the correct params`() {
val draftId = "draft-123"
val adapter = JsonHelper.moshi().adapter(UpdateDraftRequest::class.java)
val updateDraftRequest = UpdateDraftRequest(
body = "Hello, I just sent a message using Nylas!",
subject = "Hello from Nylas!",
unread = false,
starred = true,
)
val updateDraftRequest =
UpdateDraftRequest(
body = "Hello, I just sent a message using Nylas!",
subject = "Hello from Nylas!",
unread = false,
starred = true,
)

drafts.update(grantId, draftId, updateDraftRequest)

Expand Down
127 changes: 66 additions & 61 deletions src/test/kotlin/com/nylas/resources/MessagesTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class MessagesTests {
@Test
fun `Message serializes properly`() {
val adapter = JsonHelper.moshi().adapter(Message::class.java)
val jsonBuffer = Buffer().writeUtf8(
"""
val jsonBuffer =
Buffer().writeUtf8(
"""
{
"body": "Hello, I just sent a message using Nylas!",
"cc": [
Expand Down Expand Up @@ -90,8 +91,8 @@ class MessagesTests {
],
"unread": true
}
""".trimIndent(),
)
""".trimIndent(),
)

val message = adapter.fromJson(jsonBuffer)!!
assertIs<Message>(message)
Expand Down Expand Up @@ -142,24 +143,25 @@ class MessagesTests {

@Test
fun `listing messages calls requests with the correct params`() {
val queryParams = ListMessagesQueryParams(
limit = 10,
pageToken = "abc-123",
subject = "Hello from Nylas!",
anyEmail = listOf("[email protected]"),
to = listOf("[email protected]"),
cc = listOf("[email protected]"),
bcc = listOf("[email protected]"),
from = listOf("[email protected]"),
inFolder = listOf("inbox"),
unread = true,
starred = true,
hasAttachment = true,
searchQueryNative = "1634832749",
receivedBefore = 1634832749,
receivedAfter = 1634832749,
fields = MessageFields.INCLUDE_HEADERS,
)
val queryParams =
ListMessagesQueryParams(
limit = 10,
pageToken = "abc-123",
subject = "Hello from Nylas!",
anyEmail = listOf("[email protected]"),
to = listOf("[email protected]"),
cc = listOf("[email protected]"),
bcc = listOf("[email protected]"),
from = listOf("[email protected]"),
inFolder = listOf("inbox"),
unread = true,
starred = true,
hasAttachment = true,
searchQueryNative = "1634832749",
receivedBefore = 1634832749,
receivedAfter = 1634832749,
fields = MessageFields.INCLUDE_HEADERS,
)

messages.list(grantId, queryParams)

Expand Down Expand Up @@ -219,11 +221,12 @@ class MessagesTests {
fun `updating a message calls requests with the correct params`() {
val messageId = "message-123"
val adapter = JsonHelper.moshi().adapter(UpdateMessageRequest::class.java)
val updateMessageRequest = UpdateMessageRequest(
starred = true,
unread = true,
folders = listOf("folder-1", "folder-2"),
)
val updateMessageRequest =
UpdateMessageRequest(
starred = true,
unread = true,
folders = listOf("folder-1", "folder-2"),
)

messages.update(grantId, messageId, updateMessageRequest)

Expand Down Expand Up @@ -353,40 +356,42 @@ class MessagesTests {
@Test
fun `sending a message calls requests with the correct params`() {
val adapter = JsonHelper.moshi().adapter(SendMessageRequest::class.java)
val sendMessageRequest = SendMessageRequest(
to = listOf(
EmailName(
email = "[email protected]",
name = "Test",
),
),
body = "Hello, I just sent a message using Nylas!",
cc = listOf(
EmailName(
email = "[email protected]",
name = "Test",
),
),
bcc = listOf(
EmailName(
email = "[email protected]",
name = "BCC",
),
),
snippet = "Hello, I just sent a message using Nylas!",
threadId = "thread-123",
subject = "Hello from Nylas!",
unread = false,
starred = true,
sendAt = 1620000000,
replyToMessageId = "reply-to-message-id",
trackingOptions = TrackingOptions(
label = "label",
links = true,
opens = true,
threadReplies = true,
),
)
val sendMessageRequest =
SendMessageRequest(
to =
listOf(
EmailName(
email = "[email protected]",
name = "Test",
),
),
body = "Hello, I just sent a message using Nylas!",
cc =
listOf(
EmailName(
email = "[email protected]",
name = "Test",
),
),
bcc =
listOf(
EmailName(
email = "[email protected]",
name = "BCC",
),
),
subject = "Hello from Nylas!",
starred = true,
sendAt = 1620000000,
replyToMessageId = "reply-to-message-id",
trackingOptions =
TrackingOptions(
label = "label",
links = true,
opens = true,
threadReplies = true,
),
)

messages.send(grantId, sendMessageRequest)

Expand Down

0 comments on commit 644c559

Please sign in to comment.