@@ -32,21 +32,28 @@ def initialize(api_key, api_uri, timeout)
3232
3333 describe Nylas ::ApiOperations ::Get do
3434 describe "#get" do
35- it "returns a response" do
35+ it "returns response data, request_id and headers " do
3636 path = "#{ api_uri } /path"
3737 query_params = { foo : "bar" }
38+ mock_headers = { "X-Request-Id" => "123" , "Content-Type" => "application/json" }
39+ response_with_headers = mock_response . merge ( headers : mock_headers )
40+
3841 allow ( api_operations ) . to receive ( :execute ) . with (
3942 method : :get ,
4043 path : path ,
4144 query : query_params ,
4245 payload : nil ,
4346 api_key : api_key ,
4447 timeout : timeout
45- ) . and_return ( mock_response )
48+ ) . and_return ( response_with_headers )
4649
4750 response = api_operations . send ( :get , path : path , query_params : query_params )
4851
49- expect ( response ) . to eq ( [ mock_response [ :data ] , mock_response [ :request_id ] ] )
52+ expect ( response ) . to eq ( [
53+ mock_response [ :data ] ,
54+ mock_response [ :request_id ] ,
55+ mock_headers
56+ ] )
5057 end
5158
5259 it "returns a response with default query_params" do
@@ -62,7 +69,7 @@ def initialize(api_key, api_uri, timeout)
6269
6370 response = api_operations . send ( :get , path : path )
6471
65- expect ( response ) . to eq ( [ mock_response [ :data ] , mock_response [ :request_id ] ] )
72+ expect ( response ) . to eq ( [ mock_response [ :data ] , mock_response [ :request_id ] , nil ] )
6673 end
6774 end
6875
@@ -76,11 +83,15 @@ def initialize(api_key, api_uri, timeout)
7683 foo : "bar"
7784 }
7885 ] ,
79- next_cursor : "mock_cursor"
86+ next_cursor : "mock_cursor" ,
87+ headers : {
88+ "X-Request-Id" => "123" ,
89+ "Content-Type" => "application/json"
90+ }
8091 }
8192 end
8293
83- it "returns a list response" do
94+ it "returns list response with headers " do
8495 path = "#{ api_uri } /path"
8596 query_params = { foo : "bar" }
8697 allow ( api_operations ) . to receive ( :execute ) . with (
@@ -94,8 +105,12 @@ def initialize(api_key, api_uri, timeout)
94105
95106 response = api_operations . send ( :get_list , path : path , query_params : query_params )
96107
97- expect ( response ) . to eq ( [ list_response [ :data ] , list_response [ :request_id ] ,
98- list_response [ :next_cursor ] ] )
108+ expect ( response ) . to eq ( [
109+ list_response [ :data ] ,
110+ list_response [ :request_id ] ,
111+ list_response [ :next_cursor ] ,
112+ list_response [ :headers ]
113+ ] )
99114 end
100115
101116 it "returns a list response with default query_params" do
@@ -112,32 +127,35 @@ def initialize(api_key, api_uri, timeout)
112127 response = api_operations . send ( :get_list , path : path )
113128
114129 expect ( response ) . to eq ( [ list_response [ :data ] , list_response [ :request_id ] ,
115- list_response [ :next_cursor ] ] )
130+ list_response [ :next_cursor ] , list_response [ :headers ] ] )
116131 end
117132 end
118133 end
119134
120135 describe Nylas ::ApiOperations ::Post do
121136 describe "#post" do
122- it "returns a response" do
137+ it "returns response with headers " do
123138 path = "#{ api_uri } /path"
124- query_params = { foo : "bar " }
125- request_body = { foo : "bar" }
126- headers = { "Content-Type" => "application/json" }
139+ mock_headers = { "X-Request-Id" => "123" , "Content-Type" => "application/json " }
140+ response_with_headers = mock_response . merge ( headers : mock_headers )
141+
127142 allow ( api_operations ) . to receive ( :execute ) . with (
128143 method : :post ,
129144 path : path ,
130- query : query_params ,
131- payload : request_body ,
132- headers : headers ,
145+ query : { } ,
146+ payload : nil ,
147+ headers : { } ,
133148 api_key : api_key ,
134149 timeout : timeout
135- ) . and_return ( mock_response )
150+ ) . and_return ( response_with_headers )
136151
137- response = api_operations . send ( :post , path : path , query_params : query_params ,
138- request_body : request_body , headers : headers )
152+ response = api_operations . send ( :post , path : path )
139153
140- expect ( response ) . to eq ( [ mock_response [ :data ] , mock_response [ :request_id ] ] )
154+ expect ( response ) . to eq ( [
155+ mock_response [ :data ] ,
156+ mock_response [ :request_id ] ,
157+ mock_headers
158+ ] )
141159 end
142160
143161 it "returns a response with default query_params, request_body, and headers" do
@@ -154,7 +172,7 @@ def initialize(api_key, api_uri, timeout)
154172
155173 response = api_operations . send ( :post , path : path )
156174
157- expect ( response ) . to eq ( [ mock_response [ :data ] , mock_response [ :request_id ] ] )
175+ expect ( response ) . to eq ( [ mock_response [ :data ] , mock_response [ :request_id ] , nil ] )
158176 end
159177 end
160178 end
0 commit comments