feat(server): admin LiveView for host registration, rotate, delete

This commit is contained in:
Carsten 2026-04-21 22:55:29 +02:00
parent 94034eea9b
commit 667fd7160c
2 changed files with 178 additions and 0 deletions

View file

@ -0,0 +1,46 @@
defmodule ServerWeb.AdminHostsLiveTest do
use ServerWeb.ConnCase, async: false
import Phoenix.LiveViewTest
alias Server.Hosts
defp auth(conn), do: Plug.Test.init_test_session(conn, %{authenticated: true})
test "lists hosts", %{conn: conn} do
{:ok, {_, _}} = Hosts.create_host("pve-01")
{:ok, _view, html} = live(auth(conn), "/admin/hosts")
assert html =~ "pve-01"
end
test "creates a new host and reveals the token", %{conn: conn} do
{:ok, view, _html} = live(auth(conn), "/admin/hosts")
html =
view
|> form("form[phx-submit=create]", host: %{name: "pve-new"})
|> render_submit()
assert html =~ "pve-new"
assert html =~ ~r/[A-Za-z0-9_\-]{40,}/
end
test "revokes token", %{conn: conn} do
{:ok, {host, _}} = Hosts.create_host("pve-01")
original_hash = host.token_hash
{:ok, view, _html} = live(auth(conn), "/admin/hosts")
_html = render_click(view, "rotate", %{"id" => to_string(host.id)})
reloaded = Server.Repo.reload!(host)
refute reloaded.token_hash == original_hash
end
test "deletes a host", %{conn: conn} do
{:ok, {host, _}} = Hosts.create_host("pve-gone")
{:ok, view, _html} = live(auth(conn), "/admin/hosts")
html = render_click(view, "delete", %{"id" => to_string(host.id)})
refute html =~ "pve-gone"
end
end