@@ -225,89 +225,26 @@ defmodule PeekAppSDK.ClientTest do
225225 end
226226
227227 describe "query_platform/4" do
228- test "successfully queries platform with GET method using full URL " do
228+ test "successfully returns raw response body for 200 status " do
229229 install_id = "test_install_id"
230230 url = "https://api.example.com/some/endpoint"
231231 body_params = % { }
232- response_data = % { result: "success" }
232+ response_body = % { result: "success" , other_field: "value "}
233233
234234 Tesla.Adapter.Finch
235235 |> Mimic . stub ( :call , fn env , _opts ->
236236 assert env . method == :get
237- assert env . url == "https://api.example.com/some/endpoint"
237+ assert env . url == url
238238 assert Jason . decode! ( env . body ) == body_params
239239
240240 assert Enum . any? ( env . headers , fn { k , v } ->
241241 k == "X-Peek-Auth" && String . starts_with? ( v , "Bearer " )
242242 end )
243243
244- { :ok , % Tesla.Env { status: 200 , body: % { data: response_data } } }
245- end )
246-
247- assert { :ok , ^ response_data } = PeekAppSDK . query_platform ( install_id , :get , url , body_params )
248- end
249-
250- test "successfully queries platform with POST method and body" do
251- install_id = "test_install_id"
252- url = "https://api.example.com/api/resource"
253- body_params = % { "key" => "value" }
254- response_data = % { created: true }
255-
256- Tesla.Adapter.Finch
257- |> Mimic . stub ( :call , fn env , _opts ->
258- assert env . method == :post
259- assert env . url == "https://api.example.com/api/resource"
260- assert Jason . decode! ( env . body ) == body_params
261-
262- { :ok , % Tesla.Env { status: 200 , body: % { data: response_data } } }
263- end )
264-
265- assert { :ok , ^ response_data } = Client . query_platform ( install_id , :post , url , body_params )
266- end
267-
268- test "handles error response" do
269- install_id = "test_install_id"
270- url = "https://api.example.com/api/resource"
271-
272- Tesla.Adapter.Finch
273- |> Mimic . stub ( :call , fn _env , _opts ->
274- { :ok , % Tesla.Env { status: 404 , body: % { error: "Not found" } } }
275- end )
276-
277- assert { :error , 404 } = Client . query_platform ( install_id , :get , url , % { } )
278- end
279-
280- test "bubbles up errors when status is 200 but errors key is present" do
281- install_id = "test_install_id"
282- url = "https://api.example.com/api/resource"
283-
284- errors = [ % { message: "Validation failed" } ]
285-
286- Tesla.Adapter.Finch
287- |> Mimic . stub ( :call , fn _env , _opts ->
288- { :ok , % Tesla.Env { status: 200 , body: % { errors: errors } } }
289- end )
290-
291- assert { :error , ^ errors } = Client . query_platform ( install_id , :post , url , % { } )
292- end
293- end
294-
295- describe "query_platform_raw/4" do
296- test "successfully returns raw response body for 200 status" do
297- install_id = "test_install_id"
298- url = "https://api.example.com/some/endpoint"
299- body_params = % { }
300- response_body = % { result: "success" , other_field: "value" }
301-
302- Tesla.Adapter.Finch
303- |> Mimic . stub ( :call , fn env , _opts ->
304- assert env . method == :get
305- assert env . url == url
306-
307244 { :ok , % Tesla.Env { status: 200 , body: response_body } }
308245 end )
309246
310- assert { :ok , ^ response_body } = Client . query_platform_raw ( install_id , :get , url , body_params )
247+ assert { :ok , ^ response_body } = PeekAppSDK . query_platform ( install_id , :get , url , body_params )
311248 end
312249
313250 test "successfully returns raw response body for 201 status" do
@@ -320,11 +257,12 @@ defmodule PeekAppSDK.ClientTest do
320257 |> Mimic . stub ( :call , fn env , _opts ->
321258 assert env . method == :post
322259 assert env . url == url
260+ assert Jason . decode! ( env . body ) == body_params
323261
324262 { :ok , % Tesla.Env { status: 201 , body: response_body } }
325263 end )
326264
327- assert { :ok , ^ response_body } = Client . query_platform_raw ( install_id , :post , url , body_params )
265+ assert { :ok , ^ response_body } = Client . query_platform ( install_id , :post , url , body_params )
328266 end
329267
330268 test "handles error response with status and body tuple" do
@@ -337,7 +275,7 @@ defmodule PeekAppSDK.ClientTest do
337275 { :ok , % Tesla.Env { status: 404 , body: error_body } }
338276 end )
339277
340- assert { :error , { 404 , ^ error_body } } = Client . query_platform_raw ( install_id , :get , url , % { } )
278+ assert { :error , { 404 , ^ error_body } } = Client . query_platform ( install_id , :get , url , % { } )
341279 end
342280
343281 test "bubbles up errors when status is 200 but errors key is present" do
@@ -351,7 +289,7 @@ defmodule PeekAppSDK.ClientTest do
351289 { :ok , % Tesla.Env { status: 200 , body: % { errors: errors } } }
352290 end )
353291
354- assert { :error , ^ errors } = Client . query_platform_raw ( install_id , :post , url , % { } )
292+ assert { :error , ^ errors } = Client . query_platform ( install_id , :post , url , % { } )
355293 end
356294 end
357295
0 commit comments