-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved message sending and draft create/update performance (#470)
This PR improves message send/draft create/update performance by always defaulting to application/json instead of multipart. Multipart will only be used for when a request contains a total attachments size of 3mb or higher.
- Loading branch information
1 parent
fe73d9c
commit 0639d65
Showing
6 changed files
with
121 additions
and
10 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
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
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
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
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 |
---|---|---|
|
@@ -97,7 +97,33 @@ | |
expect(draft_response).to eq(response) | ||
end | ||
|
||
it "calls the post method with the correct parameters and attachments" do | ||
it "calls the post method with the correct parameters for small attachments" do | ||
identifier = "abc-123-grant-id" | ||
mock_file = instance_double("file") | ||
request_body = { | ||
subject: "Hello from Nylas!", | ||
to: [{ name: "Jon Snow", email: "[email protected]" }], | ||
cc: [{ name: "Arya Stark", email: "[email protected]" }], | ||
body: "This is the body of my draft message.", | ||
attachments: [{ | ||
filename: "file.txt", | ||
content_type: "text/plain", | ||
size: 100, | ||
content: mock_file | ||
}] | ||
} | ||
path = "#{api_uri}/v3/grants/#{identifier}/drafts" | ||
|
||
allow(drafts).to receive(:post) | ||
.with(path: path, request_body: request_body) | ||
.and_return(response) | ||
|
||
draft_response = drafts.create(identifier: identifier, request_body: request_body) | ||
|
||
expect(draft_response).to eq(response) | ||
end | ||
|
||
it "calls the post method with the correct parameters for large attachments" do | ||
identifier = "abc-123-grant-id" | ||
mock_file = instance_double("file") | ||
request_body = { | ||
|
@@ -109,7 +135,7 @@ | |
attachment = { | ||
filename: "file.txt", | ||
content_type: "text/plain", | ||
size: 100, | ||
size: 3 * 1024 * 1024, | ||
content: mock_file | ||
} | ||
expected_compiled_request = { | ||
|
@@ -154,6 +180,33 @@ | |
end | ||
|
||
it "calls the put method with the correct parameters and attachments" do | ||
identifier = "abc-123-grant-id" | ||
draft_id = "5d3qmne77v32r8l4phyuksl2x" | ||
mock_file = instance_double("file") | ||
request_body = { | ||
subject: "Hello from Nylas!", | ||
to: [{ name: "Jon Snow", email: "[email protected]" }], | ||
cc: [{ name: "Arya Stark", email: "[email protected]" }], | ||
body: "This is the body of my draft message.", | ||
attachments: [{ | ||
filename: "file.txt", | ||
content_type: "text/plain", | ||
size: 100, | ||
content: mock_file | ||
}] | ||
} | ||
path = "#{api_uri}/v3/grants/#{identifier}/drafts/#{draft_id}" | ||
allow(drafts).to receive(:put) | ||
.with(path: path, request_body: request_body) | ||
.and_return(response) | ||
|
||
draft_response = drafts.update(identifier: identifier, draft_id: draft_id, | ||
request_body: request_body) | ||
|
||
expect(draft_response).to eq(response) | ||
end | ||
|
||
it "calls the put method with the correct parameters for large attachments" do | ||
identifier = "abc-123-grant-id" | ||
draft_id = "5d3qmne77v32r8l4phyuksl2x" | ||
mock_file = instance_double("file") | ||
|
@@ -166,7 +219,7 @@ | |
attachment = { | ||
filename: "file.txt", | ||
content_type: "text/plain", | ||
size: 100, | ||
size: 3 * 1024 * 1024, | ||
content: mock_file | ||
} | ||
expected_compiled_request = { | ||
|
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 |
---|---|---|
|
@@ -135,6 +135,32 @@ | |
end | ||
|
||
it "calls the post method with the correct parameters and attachments" do | ||
identifier = "abc-123-grant-id" | ||
mock_file = instance_double("file") | ||
request_body = { | ||
subject: "Hello from Nylas!", | ||
to: [{ name: "Jon Snow", email: "[email protected]" }], | ||
cc: [{ name: "Arya Stark", email: "[email protected]" }], | ||
body: "This is the body of my message message.", | ||
attachments: [{ | ||
filename: "file.txt", | ||
content_type: "text/plain", | ||
size: 100, | ||
content: mock_file | ||
}] | ||
} | ||
path = "#{api_uri}/v3/grants/#{identifier}/messages/send" | ||
|
||
allow(messages).to receive(:post) | ||
.with(path: path, request_body: request_body) | ||
.and_return(response) | ||
|
||
message_response = messages.send(identifier: identifier, request_body: request_body) | ||
|
||
expect(message_response).to eq(response) | ||
end | ||
|
||
it "calls the post method with the correct parameters and large attachments" do | ||
identifier = "abc-123-grant-id" | ||
mock_file = instance_double("file") | ||
request_body = { | ||
|
@@ -146,7 +172,7 @@ | |
attachment = { | ||
filename: "file.txt", | ||
content_type: "text/plain", | ||
size: 100, | ||
size: 3 * 1024 * 1024, | ||
content: mock_file | ||
} | ||
expected_compiled_request = { | ||
|