Make sure ownership transfer sets trial_expiry_date

This commit is contained in:
Uku Taht 2021-10-12 10:28:32 +02:00
parent d1360dd681
commit 2e6f13ba67
2 changed files with 22 additions and 1 deletions

View File

@ -65,7 +65,7 @@ defmodule PlausibleWeb.InvitationController do
end
defp end_trial_of_new_owner(multi, new_owner) do
if Plausible.Billing.on_trial?(new_owner) do
if Plausible.Billing.on_trial?(new_owner) || is_nil(new_owner.trial_expiry_date) do
Ecto.Multi.update(multi, :user, Plausible.Auth.User.end_trial(new_owner))
else
multi

View File

@ -121,6 +121,27 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
assert Timex.before?(Repo.reload!(user).trial_expiry_date, Timex.today())
assert Repo.reload!(site).locked
end
test "ownership transfer - if new owner does not have a trial - will set trial_expiry_date to yesterday",
%{
conn: conn,
user: user
} do
Repo.update_all(from(u in Plausible.Auth.User, where: u.id == ^user.id),
set: [trial_expiry_date: nil]
)
inviter = insert(:user)
site = insert(:site, locked: false)
invitation =
insert(:invitation, site_id: site.id, inviter: inviter, email: user.email, role: :owner)
post(conn, "/sites/invitations/#{invitation.invitation_id}/accept")
assert Timex.before?(Repo.reload!(user).trial_expiry_date, Timex.today())
assert Repo.reload!(site).locked
end
end
describe "POST /sites/invitations/:invitation_id/reject" do