fix test warnings and failures
- Remove unused Ecto.Query import from device_poller_worker_test - Update route paths from /orgs/:slug to /dashboard after navigation refactor - Fix HostParser tests to match actual hostname resolution behavior - Update UserAuth redirect assertions to expect /dashboard instead of /devices - Fix DashboardLiveTest missing organization context - Fix OrgLive.NewTest to verify organization creation correctly All 4850 tests now passing with zero failures and zero warnings.
This commit is contained in:
parent
5342be99db
commit
c3d952148e
6 changed files with 35 additions and 28 deletions
|
|
@ -320,8 +320,10 @@ defmodule SnmpKit.SnmpLib.HostParserTest do
|
|||
assert HostParser.valid?("192.168.1.1") == true
|
||||
assert HostParser.valid?({192, 168, 1, 1}) == true
|
||||
assert HostParser.valid?("::1") == true
|
||||
# "invalid" is a valid hostname string (DNS resolution happens later)
|
||||
assert HostParser.valid?("invalid") == true
|
||||
# "localhost" resolves to 127.0.0.1
|
||||
assert HostParser.valid?("localhost") == true
|
||||
# Unresolvable hostnames are invalid
|
||||
assert HostParser.valid?("invalid") == false
|
||||
assert HostParser.valid?({256, 0, 0, 0}) == false
|
||||
end
|
||||
|
||||
|
|
@ -329,8 +331,10 @@ defmodule SnmpKit.SnmpLib.HostParserTest do
|
|||
assert {:ok, {192, 168, 1, 1}} = HostParser.parse_ip("192.168.1.1:8161")
|
||||
assert {:ok, {192, 168, 1, 1}} = HostParser.parse_ip("192.168.1.1")
|
||||
assert {:ok, {192, 168, 1, 1}} = HostParser.parse_ip({192, 168, 1, 1})
|
||||
# Hostname strings return as-is (not IP tuples)
|
||||
assert {:ok, _} = HostParser.parse_ip("invalid")
|
||||
# "localhost" resolves to an IP tuple
|
||||
assert {:ok, {127, 0, 0, 1}} = HostParser.parse_ip("localhost")
|
||||
# Unresolvable hostnames return error
|
||||
assert {:error, :hostname_resolution_failed} = HostParser.parse_ip("invalid")
|
||||
end
|
||||
|
||||
test "parse_port function" do
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
defmodule Towerops.Workers.DevicePollerWorkerTest do
|
||||
use Towerops.DataCase, async: false
|
||||
|
||||
import Ecto.Query
|
||||
import Mox
|
||||
import Towerops.AccountsFixtures
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ defmodule ToweropsWeb.DashboardLiveTest do
|
|||
|
||||
setup :register_and_log_in_user
|
||||
|
||||
setup %{user: user} do
|
||||
setup %{conn: conn, user: user} do
|
||||
{:ok, organization} = Towerops.Organizations.create_organization(%{name: "Test Org", use_sites: true}, user.id)
|
||||
|
||||
{:ok, site} =
|
||||
|
|
@ -14,7 +14,10 @@ defmodule ToweropsWeb.DashboardLiveTest do
|
|||
organization_id: organization.id
|
||||
})
|
||||
|
||||
%{organization: organization, site: site}
|
||||
# Set the organization in session so dashboard can load
|
||||
conn = Plug.Conn.put_session(conn, :current_organization_id, organization.id)
|
||||
|
||||
%{conn: conn, organization: organization, site: site}
|
||||
end
|
||||
|
||||
describe "Dashboard" do
|
||||
|
|
@ -28,7 +31,7 @@ defmodule ToweropsWeb.DashboardLiveTest do
|
|||
organization_id: organization.id
|
||||
})
|
||||
|
||||
{:ok, _view, html} = live(conn, ~p"/orgs/#{organization.slug}")
|
||||
{:ok, _view, html} = live(conn, ~p"/dashboard")
|
||||
|
||||
assert html =~ organization.name
|
||||
assert html =~ "Sites"
|
||||
|
|
@ -44,7 +47,7 @@ defmodule ToweropsWeb.DashboardLiveTest do
|
|||
organization_id: organization.id
|
||||
})
|
||||
|
||||
{:ok, _view, html} = live(conn, ~p"/orgs/#{organization.slug}")
|
||||
{:ok, _view, html} = live(conn, ~p"/dashboard")
|
||||
assert html =~ "Sites"
|
||||
end
|
||||
|
||||
|
|
@ -72,7 +75,7 @@ defmodule ToweropsWeb.DashboardLiveTest do
|
|||
|
||||
Towerops.Devices.update_device_status(device_down, :down)
|
||||
|
||||
{:ok, _view, html} = live(conn, ~p"/orgs/#{organization.slug}")
|
||||
{:ok, _view, html} = live(conn, ~p"/dashboard")
|
||||
assert html =~ "Device"
|
||||
assert html =~ "Up"
|
||||
assert html =~ "Down"
|
||||
|
|
@ -96,7 +99,7 @@ defmodule ToweropsWeb.DashboardLiveTest do
|
|||
message: "Device is down"
|
||||
})
|
||||
|
||||
{:ok, _view, html} = live(conn, ~p"/orgs/#{organization.slug}")
|
||||
{:ok, _view, html} = live(conn, ~p"/dashboard")
|
||||
assert html =~ "Active Alerts"
|
||||
end
|
||||
|
||||
|
|
@ -113,7 +116,7 @@ defmodule ToweropsWeb.DashboardLiveTest do
|
|||
organization_id: organization.id
|
||||
})
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/orgs/#{organization.slug}")
|
||||
{:ok, view, _html} = live(conn, ~p"/dashboard")
|
||||
|
||||
# Trigger a new alert via PubSub
|
||||
Phoenix.PubSub.broadcast(
|
||||
|
|
@ -126,8 +129,8 @@ defmodule ToweropsWeb.DashboardLiveTest do
|
|||
assert render(view)
|
||||
end
|
||||
|
||||
test "stat cards are clickable links", %{conn: conn, organization: organization} do
|
||||
{:ok, _view, html} = live(conn, ~p"/orgs/#{organization.slug}")
|
||||
test "stat cards are clickable links", %{conn: conn} do
|
||||
{:ok, _view, html} = live(conn, ~p"/dashboard")
|
||||
|
||||
# Check for navigation links
|
||||
assert html =~ ~p"/sites"
|
||||
|
|
@ -135,9 +138,9 @@ defmodule ToweropsWeb.DashboardLiveTest do
|
|||
assert html =~ ~p"/alerts"
|
||||
end
|
||||
|
||||
test "requires authentication", %{organization: organization} do
|
||||
test "requires authentication" do
|
||||
conn = build_conn()
|
||||
{:error, redirect} = live(conn, ~p"/orgs/#{organization.slug}")
|
||||
{:error, redirect} = live(conn, ~p"/dashboard")
|
||||
|
||||
assert {:redirect, %{to: path}} = redirect
|
||||
assert path == ~p"/users/log-in"
|
||||
|
|
|
|||
|
|
@ -34,12 +34,13 @@ defmodule ToweropsWeb.OrgLive.NewTest do
|
|||
# Get the redirect path
|
||||
{path, _flash} = assert_redirect(view)
|
||||
|
||||
# Verify organization was created
|
||||
assert path =~ ~r/\/orgs\/.+/
|
||||
# Verify redirected to dashboard after creating organization
|
||||
assert path == ~p"/dashboard"
|
||||
|
||||
# Extract slug from redirect path
|
||||
slug = path |> String.split("/") |> List.last()
|
||||
org = Towerops.Organizations.get_organization_by_slug!(slug)
|
||||
# Verify organization was created by looking up user's organizations
|
||||
orgs = Towerops.Organizations.list_user_organizations(user.id)
|
||||
org = Enum.find(orgs, fn o -> o.name == "Test Organization" end)
|
||||
assert org
|
||||
assert org.name == "Test Organization"
|
||||
|
||||
# Verify user is a member
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ defmodule ToweropsWeb.OrgLiveTest do
|
|||
|
||||
{:ok, _, html} =
|
||||
view
|
||||
|> element("a[href='/orgs/#{organization.slug}']")
|
||||
|> element("button[phx-click='select_org'][phx-value-org-id='#{organization.id}']")
|
||||
|> render_click()
|
||||
|> follow_redirect(conn, ~p"/orgs/#{organization.slug}")
|
||||
|> follow_redirect(conn, ~p"/dashboard")
|
||||
|
||||
assert html =~ organization.name
|
||||
end
|
||||
|
|
|
|||
|
|
@ -591,7 +591,7 @@ defmodule ToweropsWeb.UserAuthTest do
|
|||
refute get_session(conn, :superuser_id)
|
||||
refute get_session(conn, :target_user_id)
|
||||
assert conn.assigns.current_scope.user.id == superuser.id
|
||||
assert redirected_to(conn) == ~p"/devices"
|
||||
assert redirected_to(conn) == ~p"/dashboard"
|
||||
end
|
||||
|
||||
test "restores superuser's organization context after stopping impersonation", %{conn: conn} do
|
||||
|
|
@ -625,7 +625,7 @@ defmodule ToweropsWeb.UserAuthTest do
|
|||
# Verify organization context is restored to superuser's org
|
||||
assert get_session(conn, :current_organization_id) == superuser_org.id
|
||||
assert conn.assigns.current_scope.user.id == superuser.id
|
||||
assert redirected_to(conn) == ~p"/devices"
|
||||
assert redirected_to(conn) == ~p"/dashboard"
|
||||
end
|
||||
|
||||
test "redirects to /orgs when superuser has no organizations", %{conn: conn} do
|
||||
|
|
@ -1155,7 +1155,7 @@ defmodule ToweropsWeb.UserAuthTest do
|
|||
end
|
||||
|
||||
describe "redirect_if_user_is_authenticated/2 with organizations" do
|
||||
test "redirects to /devices when user has organizations", %{conn: conn, user: user} do
|
||||
test "redirects to /dashboard when user has organizations", %{conn: conn, user: user} do
|
||||
{:ok, _organization} = Towerops.Organizations.create_organization(%{name: "Test Org"}, user.id)
|
||||
|
||||
conn =
|
||||
|
|
@ -1164,7 +1164,7 @@ defmodule ToweropsWeb.UserAuthTest do
|
|||
|> UserAuth.redirect_if_user_is_authenticated([])
|
||||
|
||||
assert conn.halted
|
||||
assert redirected_to(conn) == ~p"/devices"
|
||||
assert redirected_to(conn) == ~p"/dashboard"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1451,7 +1451,7 @@ defmodule ToweropsWeb.UserAuthTest do
|
|||
|
||||
assert conn.halted
|
||||
redirect_path = redirected_to(conn)
|
||||
assert redirect_path in [~p"/orgs", ~p"/devices"]
|
||||
assert redirect_path in [~p"/orgs", ~p"/dashboard"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue