Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

CS: update tests + display user ID (#5405)

hq15495947c8d66
diff --git a/extra/lib/plausible/customer_support/resource/site.ex b/extra/lib/plausible/customer_support/resource/site.ex
index f7380fd28d..397f88ae56 100644
--- a/extra/lib/plausible/customer_support/resource/site.ex
+++ b/extra/lib/plausible/customer_support/resource/site.ex
@@ -40,7 +40,7 @@ defmodule Plausible.CustomerSupport.Resource.Site do
@impl true
def get(id) do
Plausible.Site
- |> Plausible.Repo.get(id)
+ |> Plausible.Repo.get!(id)
|> Plausible.Repo.preload(:team)
end
end
diff --git a/extra/lib/plausible/customer_support/resource/team.ex b/extra/lib/plausible/customer_support/resource/team.ex
index c81ef59a18..c984ff59a6 100644
--- a/extra/lib/plausible/customer_support/resource/team.ex
+++ b/extra/lib/plausible/customer_support/resource/team.ex
@@ -34,7 +34,7 @@ defmodule Plausible.CustomerSupport.Resource.Team do
@impl true
def get(id) do
Plausible.Teams.Team
- |> Repo.get(id)
+ |> Repo.get!(id)
|> Plausible.Teams.with_subscription()
|> Repo.preload(:owners)
end
diff --git a/extra/lib/plausible_web/live/customer_support/live/user.ex b/extra/lib/plausible_web/live/customer_support/live/user.ex
index 1782c414be..369f306a24 100644
--- a/extra/lib/plausible_web/live/customer_support/live/user.ex
+++ b/extra/lib/plausible_web/live/customer_support/live/user.ex
@@ -5,8 +5,16 @@ defmodule PlausibleWeb.CustomerSupport.Live.User do
def update(assigns, socket) do
user = socket.assigns[:user] || Resource.User.get(assigns.resource_id)
- form = user |> Plausible.Auth.User.changeset() |> to_form()
- {:ok, assign(socket, user: user, form: form)}
+
+ if is_nil(user) do
+ redirect(
+ socket,
+ to: Routes.customer_support_path(socket, :index)
+ )
+ else
+ form = user |> Plausible.Auth.User.changeset() |> to_form()
+ {:ok, assign(socket, user: user, form: form)}
+ end
end
def render(assigns) do
@@ -33,6 +41,15 @@ defmodule PlausibleWeb.CustomerSupport.Live.User do
</p>
</div>
</div>
+
+ <div class="mt-5 flex justify-center sm:mt-0">
+ <.input_with_clipboard
+ id="user-identifier"
+ name="user-identifier"
+ label="User Identifier"
+ value={@user.id}
+ />
+ </div>
</div>
<div class="mt-8">
diff --git a/test/plausible_web/live/customer_support/sites_test.exs b/test/plausible_web/live/customer_support/sites_test.exs
index f294bb7ea6..015a0da2fb 100644
--- a/test/plausible_web/live/customer_support/sites_test.exs
+++ b/test/plausible_web/live/customer_support/sites_test.exs
@@ -29,6 +29,12 @@ defmodule PlausibleWeb.Live.CustomerSupport.SitesTest do
{:ok, _lv, html} = live(conn, open_site(site.id))
assert text(html) =~ site.domain
end
+
+ test "404", %{conn: conn} do
+ assert_raise Ecto.NoResultsError, fn ->
+ {:ok, _lv, _html} = live(conn, open_site(9999))
+ end
+ end
end
end
end
diff --git a/test/plausible_web/live/customer_support/teams_test.exs b/test/plausible_web/live/customer_support/teams_test.exs
index b6dd2226b9..f1d03f17c0 100644
--- a/test/plausible_web/live/customer_support/teams_test.exs
+++ b/test/plausible_web/live/customer_support/teams_test.exs
@@ -30,6 +30,12 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do
{:ok, _lv, html} = live(conn, open_team(team.id))
assert text(html) =~ team.name
end
+
+ test "404", %{conn: conn} do
+ assert_raise Ecto.NoResultsError, fn ->
+ {:ok, _lv, _html} = live(conn, open_team(9999))
+ end
+ end
end
end
end
diff --git a/test/plausible_web/live/customer_support/users_test.exs b/test/plausible_web/live/customer_support/users_test.exs
index 16e62a0787..7516b43ffe 100644
--- a/test/plausible_web/live/customer_support/users_test.exs
+++ b/test/plausible_web/live/customer_support/users_test.exs
@@ -27,7 +27,21 @@ defmodule PlausibleWeb.Live.CustomerSupport.UsersTest do
test "renders", %{conn: conn, user: user} do
{:ok, _lv, html} = live(conn, open_user(user.id))
- assert text(html) =~ user.name
+ text = text(html)
+ assert text =~ user.name
+ assert text =~ user.email
+
+ assert [uid] = find(html, "#user-identifier")
+ assert text_of_attr(uid, "value") == "#{user.id}"
+
+ team = team_of(user)
+ assert [_] = find(html, ~s|a[href="/cs/teams/team/#{team.id}"]|)
+ end
+
+ test "404", %{conn: conn} do
+ assert_raise Ecto.NoResultsError, fn ->
+ {:ok, _lv, _html} = live(conn, open_user(9999))
+ end
end
end
end
diff --git a/test/plausible_web/live/sites_test.exs b/test/plausible_web/live/sites_test.exs
index 0acbcb6283..4b0f9b1f26 100644
--- a/test/plausible_web/live/sites_test.exs
+++ b/test/plausible_web/live/sites_test.exs
@@ -54,25 +54,29 @@ defmodule PlausibleWeb.Live.SitesTest do
assert text_of_element(html, "#invitation-#{invitation2.invitation_id}") =~
"G.I. Jane has invited you to join the \"My Personal Sites\" as editor member."
- assert find(
- html,
- "#invitation-#{invitation1.invitation_id} a[href=#{Routes.invitation_path(PlausibleWeb.Endpoint, :accept_invitation, invitation1.invitation_id)}]"
- )
-
- assert find(
- html,
- "#invitation-#{invitation1.invitation_id} a[href=#{Routes.invitation_path(PlausibleWeb.Endpoint, :reject_invitation, invitation1.invitation_id)}]"
- )
-
- assert find(
- html,
- "#invitation-#{invitation2.invitation_id} a[href=#{Routes.invitation_path(PlausibleWeb.Endpoint, :accept_invitation, invitation2.invitation_id)}]"
- )
-
- assert find(
- html,
- "#invitation-#{invitation2.invitation_id} a[href=#{Routes.invitation_path(PlausibleWeb.Endpoint, :reject_invitation, invitation2.invitation_id)}]"
- )
+ assert [_] =
+ find(
+ html,
+ ~s|#invitation-#{invitation1.invitation_id} a[href="#{Routes.invitation_path(PlausibleWeb.Endpoint, :accept_invitation, invitation1.invitation_id)}"]|
+ )
+
+ assert [_] =
+ find(
+ html,
+ ~s|#invitation-#{invitation1.invitation_id} a[href="#{Routes.invitation_path(PlausibleWeb.Endpoint, :reject_invitation, invitation1.invitation_id)}"]|
+ )
+
+ assert [_] =
+ find(
+ html,
+ ~s|#invitation-#{invitation2.invitation_id} a[href="#{Routes.invitation_path(PlausibleWeb.Endpoint, :accept_invitation, invitation2.invitation_id)}"]|
+ )
+
+ assert [_] =
+ find(
+ html,
+ ~s|#invitation-#{invitation2.invitation_id} a[href="#{Routes.invitation_path(PlausibleWeb.Endpoint, :reject_invitation, invitation2.invitation_id)}"]|
+ )
end
test "renders metadata for invitation", %{