Skip to content

Commit

Permalink
Add select field to threads find
Browse files Browse the repository at this point in the history
  • Loading branch information
Subash Pradhan committed Nov 4, 2024
1 parent 9cf9b35 commit 6c7d363
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
6 changes: 4 additions & 2 deletions lib/nylas/resources/threads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ def list(identifier:, query_params: nil)
#
# @param identifier [String] Grant ID or email account to query.
# @param thread_id [String] The id of the thread to return.
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Hash, String)] The thread and API request ID.
def find(identifier:, thread_id:)
def find(identifier:, thread_id:, query_params: nil)
get(
path: "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}"
path: "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}",
query_params: query_params
)
end

Expand Down
44 changes: 21 additions & 23 deletions spec/nylas/resources/folders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
end

describe "#find" do
let(:select_response) do
[{
id: "5d3qmne77v32r8l4phyuksl2x",
grant_id: "abc-123-grant-id"
}, "mock_request_id"]
end

it "calls the get method with the correct parameters" do
identifier = "abc-123-grant-id"
folder_id = "5d3qmne77v32r8l4phyuksl2x"
Expand All @@ -49,6 +56,20 @@

expect(folder_response).to eq(response)
end

it "calls the get method with the correct query parameters" do
identifier = "abc-123-grant-id"
folder_id = "5d3qmne77v32r8l4phyuksl2x"
query_params = { select: "id,grant_id" }
path = "#{api_uri}/v3/grants/#{identifier}/folders/#{folder_id}"
allow(folders).to receive(:get)
.with(path: path, query_params: query_params)
.and_return(select_response)

folder_response = folders.find(identifier: identifier, folder_id: folder_id, query_params: query_params)

expect(folder_response).to eq(select_response)
end
end

describe "#create" do
Expand Down Expand Up @@ -106,27 +127,4 @@
expect(folder_response).to eq([true, response[1]])
end
end

describe "#find_select" do
let(:select_response) do
[{
id: "5d3qmne77v32r8l4phyuksl2x",
grant_id: "abc-123-grant-id"
}, "mock_request_id"]
end

it "calls the get method with the correct query parameters" do
identifier = "abc-123-grant-id"
folder_id = "5d3qmne77v32r8l4phyuksl2x"
query_params = { select: "id,grant_id" }
path = "#{api_uri}/v3/grants/#{identifier}/folders/#{folder_id}"
allow(folders).to receive(:get)
.with(path: path, query_params: query_params)
.and_return(select_response)

folder_response = folders.find(identifier: identifier, folder_id: folder_id, query_params: query_params)

expect(folder_response).to eq(select_response)
end
end
end
15 changes: 14 additions & 1 deletion spec/nylas/resources/threads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,26 @@
thread_id = "5d3qmne77v32r8l4phyuksl2x"
path = "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}"
allow(threads).to receive(:get)
.with(path: path)
.with(path: path, query_params: nil)
.and_return(response)

thread_response = threads.find(identifier: identifier, thread_id: thread_id)

expect(thread_response).to eq(response)
end

it "calls the get method with the correct query parameters" do
identifier = "abc-123-grant-id"
thread_id = "5d3qmne77v32r8l4phyuksl2x"
query_params = { foo: "bar" }
path = "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}"
allow(threads).to receive(:get)
.with(path: path, query_params: query_params)
.and_return(response)

thread_response = threads.find(identifier: identifier, thread_id: thread_id, query_params: query_params)
expect(thread_response).to eq(response)
end
end

describe "#update" do
Expand Down

0 comments on commit 6c7d363

Please sign in to comment.