Skip to content

Commit 620fbeb

Browse files
committed
chore: credo
1 parent 7198ce5 commit 620fbeb

7 files changed

Lines changed: 28 additions & 27 deletions

File tree

lib/ash_json_api/request.ex

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,13 +1024,14 @@ defmodule AshJsonApi.Request do
10241024
)
10251025
when is_map(attributes) do
10261026
Enum.reduce(attributes, request, fn {key, value}, request ->
1027-
if arg =
1028-
Enum.find(action.arguments, fn argument ->
1027+
case Enum.find(action.arguments, fn argument ->
10291028
to_string(argument.name) == key
10301029
end) do
1031-
%{request | arguments: Map.put(request.arguments || %{}, arg.name, value)}
1032-
else
1033-
request
1030+
nil ->
1031+
request
1032+
1033+
arg ->
1034+
%{request | arguments: Map.put(request.arguments || %{}, arg.name, value)}
10341035
end
10351036
end)
10361037
end

test/acceptance/error_validation_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ defmodule Test.Acceptance.ErrorValidationTest do
8787

8888
errors = response.resp_body["errors"]
8989
assert is_list(errors)
90-
assert length(errors) > 0
90+
assert errors != []
9191

9292
error = Enum.find(errors, &(&1["code"] == "invalid_filter"))
9393
assert error, "Expected to find an 'invalid_filter' error"
@@ -107,7 +107,7 @@ defmodule Test.Acceptance.ErrorValidationTest do
107107

108108
errors = response.resp_body["errors"]
109109
assert is_list(errors)
110-
assert length(errors) > 0
110+
assert errors != []
111111

112112
error = Enum.find(errors, &(&1["code"] == "invalid_sort"))
113113
assert error, "Expected to find an 'invalid_sort' error"
@@ -124,7 +124,7 @@ defmodule Test.Acceptance.ErrorValidationTest do
124124

125125
errors = response.resp_body["errors"]
126126
assert is_list(errors)
127-
assert length(errors) > 0
127+
assert errors != []
128128

129129
error = Enum.find(errors, &(&1["code"] == "invalid_sort"))
130130
assert error, "Expected to find an 'invalid_sort' error"

test/acceptance/forbidden_field_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ defmodule Test.Acceptance.ForbiddenFieldTest do
382382
result = AshJsonApi.Error.to_json_api_errors(Domain, Dashboard, forbidden_error, :read)
383383

384384
assert is_list(result)
385-
assert length(result) >= 1
385+
assert result != []
386386

387387
json_error = hd(result)
388388
assert json_error.status_code == 403

test/acceptance/generic_action_index_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ defmodule Test.Acceptance.GenericActionIndexTest do
134134

135135
assert %{"errors" => errors} = response.resp_body
136136
assert is_list(errors)
137-
assert length(errors) > 0
137+
assert errors != []
138138

139139
required_error =
140140
Enum.find(

test/acceptance/get_related_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ defmodule Test.Acceptance.GetRelatedTest do
186186
assert Map.has_key?(response.resp_body, "errors")
187187
errors = response.resp_body["errors"]
188188
assert is_list(errors)
189-
assert length(errors) > 0
189+
assert errors != []
190190

191191
# Verify the error has proper JSON:API structure
192192
error = hd(errors)
@@ -214,7 +214,7 @@ defmodule Test.Acceptance.GetRelatedTest do
214214
assert Map.has_key?(response.resp_body, "errors")
215215
errors = response.resp_body["errors"]
216216
assert is_list(errors)
217-
assert length(errors) > 0
217+
assert errors != []
218218

219219
error = hd(errors)
220220
assert error["status"] == "404"
@@ -237,7 +237,7 @@ defmodule Test.Acceptance.GetRelatedTest do
237237
assert Map.has_key?(response.resp_body, "errors")
238238
errors = response.resp_body["errors"]
239239
assert is_list(errors)
240-
assert length(errors) > 0
240+
assert errors != []
241241

242242
error = hd(errors)
243243
assert error["status"] == "404"

test/acceptance/paginated_relationships_test.exs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ defmodule Test.Acceptance.PaginatedRelationshipsTest do
297297

298298
# Should get an error because 'private_comments' is not public
299299
errors = response.resp_body["errors"]
300-
assert length(errors) > 0
300+
assert errors != []
301301
# Error should indicate the relationship is invalid/not included
302302
assert List.first(errors)["code"] in ["invalid_includes", "invalid_relationship"]
303303
end
@@ -324,14 +324,14 @@ defmodule Test.Acceptance.PaginatedRelationshipsTest do
324324

325325
# Multiple posts in the response
326326
assert is_list(response.resp_body["data"])
327-
assert length(response.resp_body["data"]) > 0
327+
assert response.resp_body["data"] != []
328328

329329
# Each post that has comments should have pagination metadata
330330
Enum.each(response.resp_body["data"], fn post_data ->
331331
comments_rel = post_data["relationships"]["comments"]
332332

333333
# If there are comments, check for pagination metadata
334-
if length(comments_rel["data"]) > 0 do
334+
if comments_rel["data"] != [] do
335335
assert comments_rel["meta"]["limit"] == 3
336336
end
337337
end)
@@ -411,7 +411,7 @@ defmodule Test.Acceptance.PaginatedRelationshipsTest do
411411
)
412412

413413
errors = response.resp_body["errors"]
414-
assert length(errors) > 0
414+
assert errors != []
415415
assert List.first(errors)["code"] == "invalid_pagination"
416416
assert List.first(errors)["detail"] =~ "limit must be an integer"
417417
end
@@ -425,7 +425,7 @@ defmodule Test.Acceptance.PaginatedRelationshipsTest do
425425
)
426426

427427
errors = response.resp_body["errors"]
428-
assert length(errors) > 0
428+
assert errors != []
429429
assert List.first(errors)["code"] == "invalid_pagination"
430430
assert List.first(errors)["detail"] =~ "limit must be a positive integer"
431431
end
@@ -439,7 +439,7 @@ defmodule Test.Acceptance.PaginatedRelationshipsTest do
439439
)
440440

441441
errors = response.resp_body["errors"]
442-
assert length(errors) > 0
442+
assert errors != []
443443
assert List.first(errors)["code"] == "invalid_pagination"
444444
assert List.first(errors)["detail"] =~ "limit must be a positive integer"
445445
end
@@ -453,7 +453,7 @@ defmodule Test.Acceptance.PaginatedRelationshipsTest do
453453
)
454454

455455
errors = response.resp_body["errors"]
456-
assert length(errors) > 0
456+
assert errors != []
457457
assert List.first(errors)["code"] == "invalid_pagination"
458458
assert List.first(errors)["detail"] =~ "offset must be an integer"
459459
end
@@ -467,7 +467,7 @@ defmodule Test.Acceptance.PaginatedRelationshipsTest do
467467
)
468468

469469
errors = response.resp_body["errors"]
470-
assert length(errors) > 0
470+
assert errors != []
471471
assert List.first(errors)["code"] == "invalid_pagination"
472472
assert List.first(errors)["detail"] =~ "offset must be a non-negative integer"
473473
end
@@ -481,7 +481,7 @@ defmodule Test.Acceptance.PaginatedRelationshipsTest do
481481
)
482482

483483
errors = response.resp_body["errors"]
484-
assert length(errors) > 0
484+
assert errors != []
485485
assert List.first(errors)["code"] == "invalid_pagination"
486486
assert List.first(errors)["detail"] =~ "count must be 'true' or 'false'"
487487
end
@@ -495,7 +495,7 @@ defmodule Test.Acceptance.PaginatedRelationshipsTest do
495495
)
496496

497497
errors = response.resp_body["errors"]
498-
assert length(errors) > 0
498+
assert errors != []
499499
assert List.first(errors)["code"] == "invalid_pagination"
500500
assert List.first(errors)["detail"] =~ "unknown pagination parameter"
501501
end
@@ -545,7 +545,7 @@ defmodule Test.Acceptance.PaginatedRelationshipsTest do
545545
)
546546

547547
errors = response.resp_body["errors"]
548-
assert length(errors) > 0
548+
assert errors != []
549549
assert List.first(errors)["code"] == "invalid_pagination"
550550
assert List.first(errors)["detail"] =~ "invalid JSON"
551551
end
@@ -562,7 +562,7 @@ defmodule Test.Acceptance.PaginatedRelationshipsTest do
562562
)
563563

564564
errors = response.resp_body["errors"]
565-
assert length(errors) > 0
565+
assert errors != []
566566
assert List.first(errors)["code"] == "invalid_pagination"
567567
assert List.first(errors)["detail"] =~ "must be a JSON object"
568568
end

test/acceptance/route_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ defmodule Test.Acceptance.RouteTest do
123123

124124
assert %{"errors" => errors} = response.resp_body
125125
assert is_list(errors)
126-
assert length(errors) > 0
126+
assert errors != []
127127

128128
# Find the "required" error for the missing "from" argument
129129
required_error = Enum.find(errors, &(&1["code"] == "required"))
@@ -146,7 +146,7 @@ defmodule Test.Acceptance.RouteTest do
146146

147147
assert %{"errors" => errors} = response.resp_body
148148
assert is_list(errors)
149-
assert length(errors) > 0
149+
assert errors != []
150150

151151
# Find the conflict error
152152
conflict_error = Enum.find(errors, &(&1["code"] == "invalid_query"))

0 commit comments

Comments
 (0)