-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7918ec2
commit 644c559
Showing
2 changed files
with
165 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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) | ||
|
||
|
@@ -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) | ||
|
||
|
@@ -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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": [ | ||
|
@@ -90,8 +91,8 @@ class MessagesTests { | |
], | ||
"unread": true | ||
} | ||
""".trimIndent(), | ||
) | ||
""".trimIndent(), | ||
) | ||
|
||
val message = adapter.fromJson(jsonBuffer)!! | ||
assertIs<Message>(message) | ||
|
@@ -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) | ||
|
||
|
@@ -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) | ||
|
||
|
@@ -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) | ||
|
||
|