mirror of
https://github.com/plausible/analytics.git
synced 2024-11-23 03:04:43 +03:00
Make sure ownership transfer sets trial_expiry_date
This commit is contained in:
parent
d1360dd681
commit
2e6f13ba67
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user