Skip to content

Commit e1cd9e4

Browse files
committed
refactor tests and remove helper function
1 parent acffae7 commit e1cd9e4

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

test/hex/registry/error_message_test.exs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,25 @@ defmodule Hex.Registry.ErrorMessageTest do
2323
describe "404 errors (package not found)" do
2424
test "displays helpful message for non-existent package" do
2525
result = {:ok, {404, [], %{}}}
26-
send_error_message(result, "hexpm", "nonexistent_package", false)
2726

28-
assert_received {:mix_shell, :error, [msg]}
29-
assert msg =~ "Failed to fetch record for nonexistent_package from registry"
27+
Hex.Registry.Server.print_missing_package_diagnostics(
28+
"hexpm",
29+
"nonexistent_package",
30+
result
31+
)
3032

3133
assert_received {:mix_shell, :error, [msg]}
3234
assert msg =~ "The package nonexistent_package does not exist"
3335
assert msg =~ "Please verify the package name is spelled correctly"
3436
end
3537

36-
test "displays helpful message for non-existent package with cache" do
37-
package_name = "typo_package"
38-
38+
test "displays helpful message with different package name" do
3939
result = {:ok, {404, [], %{}}}
40-
send_error_message(result, "hexpm", package_name, true)
4140

42-
assert_received {:mix_shell, :error, [msg]}
43-
44-
assert msg =~
45-
"Failed to fetch record for #{package_name} from registry (using cache instead)"
41+
Hex.Registry.Server.print_missing_package_diagnostics("hexpm", "typo_package", result)
4642

47-
# Still shows detailed diagnostics to help user understand the issue
4843
assert_received {:mix_shell, :error, [msg]}
49-
assert msg =~ "The package #{package_name} does not exist"
44+
assert msg =~ "The package typo_package does not exist"
5045
assert msg =~ "Please verify the package name is spelled correctly"
5146
end
5247
end
@@ -107,12 +102,4 @@ defmodule Hex.Registry.ErrorMessageTest do
107102
assert msg =~ "https://hex.pm/dashboard"
108103
end
109104
end
110-
111-
defp send_error_message(result, repo, package, cached?) do
112-
package_name = Hex.Utils.package_name(repo, package)
113-
cached_message = if cached?, do: " (using cache instead)", else: ""
114-
115-
Hex.Shell.error("Failed to fetch record for #{package_name} from registry#{cached_message}")
116-
Hex.Registry.Server.print_missing_package_diagnostics(repo, package, result)
117-
end
118105
end

0 commit comments

Comments
 (0)