-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,16 +143,16 @@ defmodule PlausibleWeb.Live.RegisterFormTest do | |
inviter = new_user() | ||
site = new_site(owner: inviter) | ||
|
||
invitation = | ||
guest_invitation = | ||
invite_guest(site, "[email protected]", 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,16 +192,53 @@ 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, "[email protected]", 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") == "[email protected]" | ||
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, | ||
inviter: inviter | ||
} do | ||
mock_captcha_success() | ||
|
||
invitation = invite_transfer(site, "[email protected]", inviter: inviter) | ||
site_transfer = invite_transfer(site, "[email protected]", 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]", "[email protected]") | ||
|
@@ -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"| | ||
|
||
|