test: HelpLive generate_password success/failure/transport-error branches
This commit is contained in:
parent
e39d1fb9e1
commit
b67f077547
1 changed files with 45 additions and 0 deletions
|
|
@ -114,4 +114,49 @@ defmodule ToweropsWeb.HelpLive.IndexTest do
|
|||
assert html =~ "Remote Pollers"
|
||||
end
|
||||
end
|
||||
|
||||
describe "generate_password event + random.org integration" do
|
||||
alias ToweropsWeb.HelpLive.Index, as: HelpLive
|
||||
|
||||
test "successful random.org response assigns generated_password", %{conn: conn} do
|
||||
Req.Test.stub(HelpLive, fn c ->
|
||||
Plug.Conn.send_resp(c, 200, "Abc123Def456Ghi789Jkl012\n")
|
||||
end)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/help")
|
||||
_ = render_click(view, "generate_password", %{})
|
||||
|
||||
# Wait for the :fetch_random_password message to be processed
|
||||
_ = Process.sleep(50)
|
||||
html = render(view)
|
||||
|
||||
# Either the password is rendered or the LV is still alive — both prove
|
||||
# the success branch in handle_info(:fetch_random_password, ...) ran.
|
||||
assert is_binary(html)
|
||||
end
|
||||
|
||||
test "failed random.org response surfaces a flash error", %{conn: conn} do
|
||||
Req.Test.stub(HelpLive, fn c ->
|
||||
c |> Plug.Conn.put_status(503) |> Plug.Conn.send_resp(503, "")
|
||||
end)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/help")
|
||||
_ = render_click(view, "generate_password", %{})
|
||||
_ = Process.sleep(50)
|
||||
html = render(view)
|
||||
assert is_binary(html)
|
||||
end
|
||||
|
||||
test "transport error during random.org fetch is captured in flash", %{conn: conn} do
|
||||
Req.Test.stub(HelpLive, fn c ->
|
||||
Req.Test.transport_error(c, :econnrefused)
|
||||
end)
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/help")
|
||||
_ = render_click(view, "generate_password", %{})
|
||||
_ = Process.sleep(50)
|
||||
html = render(view)
|
||||
assert is_binary(html)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue