Skip to content

Commit cf9cb8f

Browse files
committed
fix: Resolve CI failures - Credo naming and Dialyzer type specs
- Add Credo inline directive for arrayBuffer camelCase (Browser API requirement) - Fix alias ordering in test file (alphabetical) - Change read_all spec from String.t() to binary() for correct type - Fix text/1 function to pass full response struct to read_all - All CI checks now passing: Credo, Dialyzer, Format, Compile
1 parent 5dca805 commit cf9cb8f

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/http/response.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ defmodule HTTP.Response do
217217
@spec text(t()) :: String.t()
218218
def text(%__MODULE__{body: body, stream: nil}), do: body
219219

220-
def text(%__MODULE__{body: body, stream: stream}) do
220+
def text(%__MODULE__{body: body, stream: stream} = response) do
221221
if is_nil(body) and is_pid(stream) do
222-
read_all(%__MODULE__{body: body, stream: stream})
222+
read_all(response)
223223
else
224224
body || ""
225225
end
@@ -236,7 +236,7 @@ defmodule HTTP.Response do
236236
iex> HTTP.Response.read_all(response)
237237
"Hello World"
238238
"""
239-
@spec read_all(t()) :: String.t()
239+
@spec read_all(t()) :: binary()
240240
def read_all(%__MODULE__{body: body, stream: nil}), do: body || ""
241241

242242
def read_all(%__MODULE__{body: _body, stream: stream}) do
@@ -410,6 +410,7 @@ defmodule HTTP.Response do
410410
<<1, 2, 3, 4>>
411411
"""
412412
@spec arrayBuffer(t()) :: binary()
413+
# credo:disable-for-next-line Credo.Check.Readability.FunctionNames
413414
def arrayBuffer(%__MODULE__{} = response) do
414415
# arrayBuffer is essentially the same as read_all for binary data
415416
read_all(response)

test/http/response_browser_api_test.exs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
defmodule HTTP.ResponseBrowserAPITest do
22
use ExUnit.Case, async: true
33

4-
alias HTTP.Response
5-
alias HTTP.Headers
64
alias HTTP.Blob
5+
alias HTTP.Headers
6+
alias HTTP.Response
77

88
describe "Browser Fetch API properties" do
99
test "ok is true for 200-299 status codes" do
@@ -41,6 +41,7 @@ defmodule HTTP.ResponseBrowserAPITest do
4141

4242
for {status, expected_text} <- test_cases do
4343
response = Response.new(status: status)
44+
4445
assert response.status_text == expected_text,
4546
"Status #{status} should have status_text='#{expected_text}', got '#{response.status_text}'"
4647
end
@@ -92,7 +93,8 @@ defmodule HTTP.ResponseBrowserAPITest do
9293

9394
# Multiple reads work because response is immutable
9495
assert Response.text(response) == "Hello"
95-
assert Response.text(response) == "Hello" # Works in Elixir
96+
# Works in Elixir
97+
assert Response.text(response) == "Hello"
9698
end
9799

98100
test "body_used flag can be manually checked" do
@@ -253,7 +255,8 @@ defmodule HTTP.ResponseBrowserAPITest do
253255
describe "Response.blob/1" do
254256
test "returns blob with correct data and type" do
255257
headers = Headers.new([{"content-type", "image/png"}])
256-
data = <<137, 80, 78, 71>> # PNG magic bytes
258+
# PNG magic bytes
259+
data = <<137, 80, 78, 71>>
257260
response = Response.new(status: 200, body: data, headers: headers)
258261

259262
blob = Response.blob(response)

0 commit comments

Comments
 (0)