From 6c7d3636344fb97dbd9bab7ab123d7f79a893160 Mon Sep 17 00:00:00 2001 From: Subash Pradhan Date: Mon, 4 Nov 2024 15:29:48 +0100 Subject: [PATCH] Add select field to threads find --- lib/nylas/resources/threads.rb | 6 ++-- spec/nylas/resources/folders_spec.rb | 44 +++++++++++++--------------- spec/nylas/resources/threads_spec.rb | 15 +++++++++- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/lib/nylas/resources/threads.rb b/lib/nylas/resources/threads.rb index 7172f9ae..f251251d 100644 --- a/lib/nylas/resources/threads.rb +++ b/lib/nylas/resources/threads.rb @@ -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 diff --git a/spec/nylas/resources/folders_spec.rb b/spec/nylas/resources/folders_spec.rb index bd1f9f76..63551aae 100644 --- a/spec/nylas/resources/folders_spec.rb +++ b/spec/nylas/resources/folders_spec.rb @@ -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" @@ -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 @@ -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 diff --git a/spec/nylas/resources/threads_spec.rb b/spec/nylas/resources/threads_spec.rb index e95960d3..a03700dc 100644 --- a/spec/nylas/resources/threads_spec.rb +++ b/spec/nylas/resources/threads_spec.rb @@ -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