Replace the thundering-herd cron job with a dispatcher that enqueues individual per-integration Oban jobs staggered across the 10-minute window using PollingOffset. Show last synced timestamp in user's local timezone via the <.timestamp> component.
85 lines
2.6 KiB
Elixir
85 lines
2.6 KiB
Elixir
defmodule ToweropsWeb.Org.IntegrationsLiveTest do
|
|
use ToweropsWeb.ConnCase
|
|
|
|
import Phoenix.LiveViewTest
|
|
import Towerops.AccountsFixtures
|
|
import Towerops.OrganizationsFixtures
|
|
|
|
alias Towerops.Preseem.Client, as: PreseemClient
|
|
|
|
setup do
|
|
user = user_fixture()
|
|
organization = organization_fixture(user.id)
|
|
%{user: user, organization: organization}
|
|
end
|
|
|
|
describe "index" do
|
|
test "renders integrations page", %{conn: conn, user: user, organization: org} do
|
|
{:ok, _view, html} =
|
|
conn
|
|
|> log_in_user(user)
|
|
|> live(~p"/orgs/#{org.slug}/settings/integrations")
|
|
|
|
assert html =~ "Integrations"
|
|
assert html =~ "Preseem"
|
|
end
|
|
|
|
test "shows preseem description", %{conn: conn, user: user, organization: org} do
|
|
{:ok, _view, html} =
|
|
conn
|
|
|> log_in_user(user)
|
|
|> live(~p"/orgs/#{org.slug}/settings/integrations")
|
|
|
|
assert html =~ "QoE monitoring"
|
|
end
|
|
|
|
test "can open preseem configuration", %{conn: conn, user: user, organization: org} do
|
|
{:ok, view, _html} =
|
|
conn
|
|
|> log_in_user(user)
|
|
|> live(~p"/orgs/#{org.slug}/settings/integrations")
|
|
|
|
html = view |> element("#configure-preseem") |> render_click()
|
|
assert html =~ "API Key"
|
|
end
|
|
|
|
test "can save preseem credentials", %{conn: conn, user: user, organization: org} do
|
|
{:ok, view, _html} =
|
|
conn
|
|
|> log_in_user(user)
|
|
|> live(~p"/orgs/#{org.slug}/settings/integrations")
|
|
|
|
view |> element("#configure-preseem") |> render_click()
|
|
|
|
view
|
|
|> form("#preseem-form", %{integration: %{api_key: "test-key-123"}})
|
|
|> render_submit()
|
|
|
|
assert {:ok, integration} = Towerops.Integrations.get_integration(org.id, "preseem")
|
|
assert integration.credentials["api_key"] == "test-key-123"
|
|
end
|
|
|
|
test "can test preseem connection successfully", %{conn: conn, user: user, organization: org} do
|
|
Req.Test.stub(PreseemClient, fn conn ->
|
|
Req.Test.json(conn, %{
|
|
"data" => [%{"id" => 1, "name" => "Test AP"}],
|
|
"paginator" => %{"page" => 1, "page_count" => 1, "limit" => 100, "total_count" => 1}
|
|
})
|
|
end)
|
|
|
|
{:ok, view, _html} =
|
|
conn
|
|
|> log_in_user(user)
|
|
|> live(~p"/orgs/#{org.slug}/settings/integrations")
|
|
|
|
view |> element("#configure-preseem") |> render_click()
|
|
|
|
view
|
|
|> form("#preseem-form", %{integration: %{api_key: "test-key"}})
|
|
|> render_change()
|
|
|
|
html = view |> element("#test-connection") |> render_click()
|
|
assert html =~ "Connection successful"
|
|
end
|
|
end
|
|
end
|