diff --git a/test/plausible_web/live/register_form_test.exs b/test/plausible_web/live/register_form_test.exs index b4b05037ba79..d500e89305e4 100644 --- a/test/plausible_web/live/register_form_test.exs +++ b/test/plausible_web/live/register_form_test.exs @@ -143,16 +143,16 @@ defmodule PlausibleWeb.Live.RegisterFormTest do inviter = new_user() site = new_site(owner: inviter) - invitation = + guest_invitation = invite_guest(site, "user@email.co", role: :editor, inviter: inviter) - {:ok, %{site: site, invitation: invitation, inviter: inviter}} + {:ok, %{site: site, guest_invitation: guest_invitation, inviter: inviter}} end - test "registers user from invitation", %{conn: conn, invitation: invitation} do + test "registers user from guest invitation", %{conn: conn, guest_invitation: guest_invitation} do mock_captcha_success() - lv = get_liveview(conn, "/register/invitation/#{invitation.invitation_id}") + lv = get_liveview(conn, "/register/invitation/#{guest_invitation.invitation_id}") type_into_input(lv, "user[name]", "Mary Sue") type_into_input(lv, "user[password]", "very-long-and-very-secret-123") @@ -192,6 +192,43 @@ defmodule PlausibleWeb.Live.RegisterFormTest do assert String.length(password_hash) > 0 end + test "registers user from team invitation", %{conn: conn, inviter: inviter} do + mock_captcha_success() + + team = team_of(inviter) + + team_invitation = + invite_member(team, "team-user@email.co", role: :editor, inviter: inviter) + + lv = get_liveview(conn, "/register/invitation/#{team_invitation.invitation_id}") + + type_into_input(lv, "user[name]", "Mary Sue") + type_into_input(lv, "user[password]", "very-long-and-very-secret-123") + type_into_input(lv, "user[password_confirmation]", "very-long-and-very-secret-123") + + html = lv |> element("form") |> render_submit() + + on_ee do + assert_push_event(lv, "send-metrics", %{event_name: "Signup via invitation"}) + end + + assert [ + csrf_input, + action_input, + email_input, + name_input, + password_input, + password_confirmation_input | _ + ] = find(html, "input") + + assert String.length(text_of_attr(csrf_input, "value")) > 0 + assert text_of_attr(action_input, "value") == "register_from_invitation_form" + assert text_of_attr(name_input, "value") == "Mary Sue" + assert text_of_attr(email_input, "value") == "team-user@email.co" + assert text_of_attr(password_input, "value") == "very-long-and-very-secret-123" + assert text_of_attr(password_confirmation_input, "value") == "very-long-and-very-secret-123" + end + test "preserves trial_expiry_date when invitation role is :owner", %{ conn: conn, site: site, @@ -199,9 +236,9 @@ defmodule PlausibleWeb.Live.RegisterFormTest do } do mock_captcha_success() - invitation = invite_transfer(site, "owner_user@email.co", inviter: inviter) + site_transfer = invite_transfer(site, "owner_user@email.co", inviter: inviter) - lv = get_liveview(conn, "/register/invitation/#{invitation.transfer_id}") + lv = get_liveview(conn, "/register/invitation/#{site_transfer.transfer_id}") type_into_input(lv, "user[name]", "Mary Sue") type_into_input(lv, "user[password]", "very-long-and-very-secret-123") @@ -214,10 +251,13 @@ defmodule PlausibleWeb.Live.RegisterFormTest do assert team_of(user).trial_expiry_date != nil end - test "always uses original email from the invitation", %{conn: conn, invitation: invitation} do + test "always uses original email from the invitation", %{ + conn: conn, + guest_invitation: guest_invitation + } do mock_captcha_success() - lv = get_liveview(conn, "/register/invitation/#{invitation.invitation_id}") + lv = get_liveview(conn, "/register/invitation/#{guest_invitation.invitation_id}") type_into_input(lv, "user[name]", "Mary Sue") type_into_input(lv, "user[email]", "mary.sue@plausible.test") @@ -247,10 +287,10 @@ defmodule PlausibleWeb.Live.RegisterFormTest do assert html =~ "Your invitation has expired or been revoked" end - test "renders error on failed captcha", %{conn: conn, invitation: invitation} do + test "renders error on failed captcha", %{conn: conn, guest_invitation: guest_invitation} do mock_captcha_failure() - lv = get_liveview(conn, "/register/invitation/#{invitation.invitation_id}") + lv = get_liveview(conn, "/register/invitation/#{guest_invitation.invitation_id}") type_into_input(lv, "user[name]", "Mary Sue") type_into_input(lv, "user[password]", "very-long-and-very-secret-123") @@ -265,9 +305,9 @@ defmodule PlausibleWeb.Live.RegisterFormTest do test "pushing send-metrics-after event submits the form", %{ conn: conn, - invitation: invitation + guest_invitation: guest_invitation } do - lv = get_liveview(conn, "/register/invitation/#{invitation.invitation_id}") + lv = get_liveview(conn, "/register/invitation/#{guest_invitation.invitation_id}") refute render(lv) =~ ~s|phx-trigger-action="phx-trigger-action"|