test: cover Admin OrgLive override / pricing event paths

Adds tests for edit_overrides patch, validate_overrides re-render,
save_overrides invalid + valid, clear_overrides, and delete_org
unknown-id paths.
This commit is contained in:
Graham McIntire 2026-05-09 12:04:48 -05:00
parent fb288395aa
commit 3dc9f3cf46

View file

@ -244,4 +244,74 @@ defmodule ToweropsWeb.Admin.OrgLive.IndexTest do
assert_patched(view, ~p"/admin/organizations")
end
end
describe "edit_overrides + clear_overrides + delete_org events" do
setup %{conn: conn, organization: organization} do
{:ok, view, _html} = live(conn, ~p"/admin/organizations")
%{conn: conn, organization: organization, view: view}
end
test "edit_overrides patches to ?edit=org_id",
%{view: view, organization: org} do
_ = render_hook(view, "edit_overrides", %{"id" => org.id})
assert_patched(view, ~p"/admin/organizations?edit=#{org.id}")
end
test "validate_overrides updates the form with errors", %{conn: conn, organization: org} do
{:ok, view, _html} = live(conn, ~p"/admin/organizations?edit=#{org.id}")
_ =
render_hook(view, "validate_overrides", %{
"organization" => %{"custom_free_device_limit" => "garbage"}
})
# Form re-renders without crash
assert is_binary(render(view))
end
test "save_overrides with invalid params re-renders the form",
%{conn: conn, organization: org} do
{:ok, view, _html} = live(conn, ~p"/admin/organizations?edit=#{org.id}")
_ =
render_hook(view, "save_overrides", %{
"organization" => %{
"custom_free_device_limit" => "-5",
"custom_price_per_device" => "invalid"
}
})
# Re-renders without crashing
assert is_binary(render(view))
end
test "save_overrides with valid params persists and patches back",
%{conn: conn, organization: org} do
{:ok, view, _html} = live(conn, ~p"/admin/organizations?edit=#{org.id}")
html =
render_hook(view, "save_overrides", %{
"organization" => %{
"custom_free_device_limit" => "20",
"custom_price_per_device" => "5.00"
}
})
assert html =~ "Billing overrides updated"
end
test "clear_overrides resets the override fields",
%{conn: conn, organization: org} do
{:ok, view, _html} = live(conn, ~p"/admin/organizations?edit=#{org.id}")
html = render_hook(view, "clear_overrides", %{})
assert html =~ "cleared" or html =~ "Failed to clear"
end
test "delete_org with non-existent id flashes error",
%{view: view} do
html = render_hook(view, "delete_org", %{"id" => Ecto.UUID.generate()})
assert html =~ "Failed to delete"
end
end
end