Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix various tests
  • Loading branch information
ukutaht committed Nov 28, 2023
commit e76faa9b6cca982530e4bd23f23bf263b2df8ec0
10 changes: 5 additions & 5 deletions lib/plausible_web/controllers/auth_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,15 @@ defmodule PlausibleWeb.AuthController do
:error,
"We were unable to authenticate your Google Analytics account. Please check that you have granted us permission to 'See and download your Google Analytics data' and try again."
)
|> redirect(to: Routes.site_path(conn, :settings_general, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_general, site.domain))

message when message in ["server_error", "temporarily_unavailable"] ->
conn
|> put_flash(
:error,
"We are unable to authenticate your Google Analytics account because Google's authentication service is temporarily unavailable. Please try again in a few moments."
)
|> redirect(to: Routes.site_path(conn, :settings_general, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_general, site.domain))

_any ->
Sentry.capture_message("Google OAuth callback failed. Reason: #{inspect(params)}")
Expand All @@ -480,7 +480,7 @@ defmodule PlausibleWeb.AuthController do
:error,
"We were unable to authenticate your Google Analytics account. If the problem persists, please contact support for assistance."
)
|> redirect(to: Routes.site_path(conn, :settings_general, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_general, site.domain))
end
end

Expand All @@ -493,7 +493,7 @@ defmodule PlausibleWeb.AuthController do
case redirect_to do
"import" ->
redirect(conn,
to:
external:
Routes.site_path(conn, :import_from_google_view_id_form, site.domain,
access_token: res["access_token"],
refresh_token: res["refresh_token"],
Expand All @@ -518,7 +518,7 @@ defmodule PlausibleWeb.AuthController do

site = Repo.get(Plausible.Site, site_id)

redirect(conn, to: "/#{URI.encode_www_form(site.domain)}/settings/integrations")
redirect(conn, external: "/#{URI.encode_www_form(site.domain)}/settings/integrations")
end
end
end
6 changes: 3 additions & 3 deletions lib/plausible_web/controllers/invitation_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule PlausibleWeb.InvitationController do
{:ok, membership} ->
conn
|> put_flash(:success, "You now have access to #{membership.site.domain}")
|> redirect(to: "/#{URI.encode_www_form(membership.site.domain)}")
|> redirect(external: "/#{URI.encode_www_form(membership.site.domain)}")

{:error, :invitation_not_found} ->
conn
Expand Down Expand Up @@ -43,12 +43,12 @@ defmodule PlausibleWeb.InvitationController do
{:ok, invitation} ->
conn
|> put_flash(:success, "You have removed the invitation for #{invitation.email}")
|> redirect(to: Routes.site_path(conn, :settings_people, invitation.site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, invitation.site.domain))

{:error, :invitation_not_found} ->
conn
|> put_flash(:error, "Invitation missing or already removed")
|> redirect(to: Routes.site_path(conn, :settings_people, conn.assigns.site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, conn.assigns.site.domain))
end
end
end
20 changes: 10 additions & 10 deletions lib/plausible_web/controllers/site/membership_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule PlausibleWeb.Site.MembershipController do
:success,
"#{email} has been invited to #{site_domain} as #{PlausibleWeb.SiteView.with_indefinite_article("#{invitation.role}")}"
)
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))

{:error, :already_a_member} ->
render(conn, "invite_member_form.html",
Expand Down Expand Up @@ -86,7 +86,7 @@ defmodule PlausibleWeb.Site.MembershipController do

conn
|> put_flash(:error, error_msg)
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))
end
end

Expand All @@ -111,14 +111,14 @@ defmodule PlausibleWeb.Site.MembershipController do
{:ok, _invitation} ->
conn
|> put_flash(:success, "Site transfer request has been sent to #{email}")
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))

{:error, :transfer_to_self} ->
conn
|> put_flash(:ttl, :timer.seconds(5))
|> put_flash(:error_title, "Transfer error")
|> put_flash(:error, "Can't transfer ownership to existing owner")
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))

{:error, :upgrade_required} ->
conn
Expand All @@ -128,7 +128,7 @@ defmodule PlausibleWeb.Site.MembershipController do
:error,
"The site you're trying to transfer exceeds the invitee's subscription plan. To proceed, please contact us at hello@plausible.io for further assistance."
)
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))

{:error, changeset} ->
errors = Plausible.ChangesetHelpers.traverse_errors(changeset)
Expand All @@ -143,7 +143,7 @@ defmodule PlausibleWeb.Site.MembershipController do
|> put_flash(:ttl, :timer.seconds(5))
|> put_flash(:error_title, "Transfer error")
|> put_flash(:error, message)
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))
end
end

Expand Down Expand Up @@ -191,11 +191,11 @@ defmodule PlausibleWeb.Site.MembershipController do
:success,
"#{membership.user.name} is now #{PlausibleWeb.SiteView.with_indefinite_article(new_role_str)}"
)
|> redirect(to: redirect_target)
|> redirect(external: redirect_target)
else
conn
|> put_flash(:error, "You are not allowed to grant the #{new_role} role")
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))
end
end

Expand Down Expand Up @@ -241,14 +241,14 @@ defmodule PlausibleWeb.Site.MembershipController do
:success,
"#{membership.user.name} has been removed from #{site.domain}"
)
|> redirect(to: redirect_target)
|> redirect(external: redirect_target)
else
conn
|> put_flash(
:error,
"Failed to find membership to remove"
)
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))
end
end
end
8 changes: 4 additions & 4 deletions test/plausible_web/controllers/invitation_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
assert Phoenix.Flash.get(conn.assigns.flash, :success) ==
"You now have access to #{site.domain}"

assert redirected_to(conn) == "/#{site.domain}"
assert redirected_to(conn) == "/#{URI.encode_www_form(site.domain)}"

refute Repo.exists?(from(i in Plausible.Auth.Invitation, where: i.email == ^user.email))

Expand All @@ -42,7 +42,7 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
)

c1 = post(conn, "/sites/invitations/#{invitation.invitation_id}/accept")
assert redirected_to(c1) == "/#{site.domain}"
assert redirected_to(c1) == "/#{URI.encode_www_form(site.domain)}"

assert Phoenix.Flash.get(c1.assigns.flash, :success) ==
"You now have access to #{site.domain}"
Expand Down Expand Up @@ -126,7 +126,7 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
Routes.invitation_path(conn, :remove_invitation, site.domain, invitation.invitation_id)
)

assert redirected_to(conn, 302) == "/#{site.domain}/settings/people"
assert redirected_to(conn, 302) == "/#{URI.encode_www_form(site.domain)}/settings/people"

refute Repo.reload(invitation)
end
Expand Down Expand Up @@ -192,7 +192,7 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do

conn = delete(conn, remove_invitation_path)

assert redirected_to(conn, 302) == "/#{site.domain}/settings/people"
assert redirected_to(conn, 302) == "/#{URI.encode_www_form(site.domain)}/settings/people"

assert Phoenix.Flash.get(conn.assigns.flash, :error) ==
"Invitation missing or already removed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule PlausibleWeb.Site.MembershipControllerTest do
invitation = Repo.get_by(Plausible.Auth.Invitation, email: "john.doe@example.com")

assert invitation.role == :admin
assert redirected_to(conn) == "/#{site.domain}/settings/people"
assert redirected_to(conn) == "/#{URI.encode_www_form(site.domain)}/settings/people"
end

test "fails to create invitation when is over limit", %{conn: conn, user: user} do
Expand Down Expand Up @@ -214,7 +214,7 @@ defmodule PlausibleWeb.Site.MembershipControllerTest do
invitation = Repo.get_by(Plausible.Auth.Invitation, email: "john.doe@example.com")

assert invitation.role == :owner
assert redirected_to(conn) == "/#{site.domain}/settings/people"
assert redirected_to(conn) == "/#{URI.encode_www_form(site.domain)}/settings/people"
end

test "sends ownership transfer email for new user", %{conn: conn, user: user} do
Expand Down Expand Up @@ -316,7 +316,7 @@ defmodule PlausibleWeb.Site.MembershipControllerTest do
membership = Repo.reload!(membership)

assert membership.role == :viewer
assert redirected_to(conn) == "/#{site.domain}"
assert redirected_to(conn) == "/#{URI.encode_www_form(site.domain)}"
end

test "owner cannot make anyone else owner", %{
Expand Down Expand Up @@ -384,7 +384,7 @@ defmodule PlausibleWeb.Site.MembershipControllerTest do
viewer_membership = Repo.reload!(viewer_membership)

assert viewer_membership.role == :admin
assert redirected_to(conn) == "/#{site.domain}/settings/people"
assert redirected_to(conn) == "/#{URI.encode_www_form(site.domain)}/settings/people"
end

test "admin can't make themselves an owner", %{conn: conn, user: user} do
Expand Down
2 changes: 1 addition & 1 deletion test/plausible_web/live/goal_settings_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule PlausibleWeb.Live.GoalSettingsTest do
resp = html_response(conn, 200)
assert resp =~ "Define actions that you want your users to take"
assert resp =~ "compose Goals into Funnels"
assert resp =~ "/#{site.domain}/settings/funnels"
assert resp =~ "/#{URI.encode_www_form(site.domain)}/settings/funnels"
assert element_exists?(resp, ~s|a[href="https://plausible.io/docs/goal-conversions"]|)

assert resp =~ to_string(g1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ defmodule PlausibleWeb.Plugins.API.Controllers.SharedLinksTest do
|> assert_schema("SharedLink", spec())

assert resp.shared_link.href ==
"http://localhost:8000/share/#{site.domain}?auth=#{shared_link.slug}"
"http://localhost:8000/share/#{URI.encode_www_form(site.domain)}?auth=#{shared_link.slug}"

assert resp.shared_link.id == shared_link.id
assert resp.shared_link.password_protected == false
Expand Down Expand Up @@ -107,7 +107,9 @@ defmodule PlausibleWeb.Plugins.API.Controllers.SharedLinksTest do
|> assert_schema("SharedLink", spec())

assert resp.shared_link.name == "My Shared Link"
assert resp.shared_link.href =~ "http://localhost:8000/share/#{site.domain}?auth="

assert resp.shared_link.href =~
"http://localhost:8000/share/#{URI.encode_www_form(site.domain)}?auth="

[location] = get_resp_header(conn, "location")

Expand Down