test: IntegrationsLive test_connection across gaiia/sonar/splynx/visp branches

This commit is contained in:
Graham McIntire 2026-05-09 10:02:15 -05:00
parent a224775fd3
commit 84c839a218

View file

@ -227,6 +227,93 @@ defmodule ToweropsWeb.Org.IntegrationsLiveTest do
assert html =~ "Connection successful"
end
test "can test gaiia connection (drives test_provider_connection \"gaiia\" branch)",
%{conn: conn, user: user, organization: org} do
Req.Test.stub(Towerops.Gaiia.Client, fn c ->
Req.Test.json(c, %{"status" => "ok"})
end)
{:ok, view, _html} =
conn
|> log_in_user(user)
|> live(~p"/orgs/#{org.slug}/settings/integrations")
view |> element("#configure-gaiia") |> render_click()
view
|> form("#gaiia-form", %{integration: %{api_key: "k"}})
|> render_change()
_ = render_click(view, "test_connection", %{})
# Just exercises the gaiia branch — pass/fail is fine, the LV stays alive.
assert render(view) =~ "Test"
end
test "can test sonar connection (drives test_provider_connection \"sonar\" branch)",
%{conn: conn, user: user, organization: org} do
Req.Test.stub(Towerops.Sonar.Client, fn c ->
Req.Test.json(c, %{"data" => []})
end)
{:ok, view, _html} =
conn
|> log_in_user(user)
|> live(~p"/orgs/#{org.slug}/settings/integrations")
view |> element("#configure-sonar") |> render_click()
view
|> form("#sonar-form", %{integration: %{instance_url: "https://x.sonar.test", api_token: "k"}})
|> render_change()
_ = render_click(view, "test_connection", %{})
assert render(view) =~ "Test"
end
test "can test splynx connection (drives test_provider_connection \"splynx\" branch)",
%{conn: conn, user: user, organization: org} do
Req.Test.stub(Towerops.Splynx.Client, fn c ->
Req.Test.json(c, %{"access_token" => "tok"})
end)
{:ok, view, _html} =
conn
|> log_in_user(user)
|> live(~p"/orgs/#{org.slug}/settings/integrations")
view |> element("#configure-splynx") |> render_click()
view
|> form("#splynx-form", %{
integration: %{instance_url: "https://x.splynx.test", api_key: "k", api_secret: "s"}
})
|> render_change()
_ = render_click(view, "test_connection", %{})
assert render(view) =~ "Test"
end
test "can test visp connection (drives test_provider_connection \"visp\" branch)",
%{conn: conn, user: user, organization: org} do
Req.Test.stub(Towerops.Visp.Client, fn c ->
Req.Test.json(c, %{"data" => []})
end)
{:ok, view, _html} =
conn
|> log_in_user(user)
|> live(~p"/orgs/#{org.slug}/settings/integrations")
view |> element("#configure-visp") |> render_click()
view
|> form("#visp-form", %{integration: %{api_key: "k"}})
|> render_change()
_ = render_click(view, "test_connection", %{})
assert render(view) =~ "Test"
end
test "close_config clears the configuring panel", %{conn: conn, user: user, organization: org} do
{:ok, view, _html} =
conn