@@ -292,6 +292,69 @@ defmodule PeekAppSDK.ClientTest do
292292 end
293293 end
294294
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+
307+ { :ok , % Tesla.Env { status: 200 , body: response_body } }
308+ end )
309+
310+ assert { :ok , ^ response_body } = Client . query_platform_raw ( install_id , :get , url , body_params )
311+ end
312+
313+ test "successfully returns raw response body for 201 status" do
314+ install_id = "test_install_id"
315+ url = "https://api.example.com/api/resource"
316+ body_params = % { "key" => "value" }
317+ response_body = % { created: true , id: 123 }
318+
319+ Tesla.Adapter.Finch
320+ |> Mimic . stub ( :call , fn env , _opts ->
321+ assert env . method == :post
322+ assert env . url == url
323+
324+ { :ok , % Tesla.Env { status: 201 , body: response_body } }
325+ end )
326+
327+ assert { :ok , ^ response_body } = Client . query_platform_raw ( install_id , :post , url , body_params )
328+ end
329+
330+ test "handles error response with status and body tuple" do
331+ install_id = "test_install_id"
332+ url = "https://api.example.com/api/resource"
333+ error_body = % { error: "Not found" }
334+
335+ Tesla.Adapter.Finch
336+ |> Mimic . stub ( :call , fn _env , _opts ->
337+ { :ok , % Tesla.Env { status: 404 , body: error_body } }
338+ end )
339+
340+ assert { :error , { 404 , ^ error_body } } = Client . query_platform_raw ( install_id , :get , url , % { } )
341+ end
342+
343+ test "bubbles up errors when status is 200 but errors key is present" do
344+ install_id = "test_install_id"
345+ url = "https://api.example.com/api/resource"
346+
347+ errors = [ % { message: "Validation failed" } ]
348+
349+ Tesla.Adapter.Finch
350+ |> Mimic . stub ( :call , fn _env , _opts ->
351+ { :ok , % Tesla.Env { status: 200 , body: % { errors: errors } } }
352+ end )
353+
354+ assert { :error , ^ errors } = Client . query_platform_raw ( install_id , :post , url , % { } )
355+ end
356+ end
357+
295358 describe "operation_name/1" do
296359 test "extracts operation name from query" do
297360 query = "query TestOperation { test }"
0 commit comments