forked from plausible/analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a regression in accepting site transfers with pending invitations (…
- Loading branch information
Showing
2 changed files
with
17 additions
and
126 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
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 |
---|---|---|
|
@@ -36,6 +36,18 @@ defmodule Plausible.Site.Memberships.AcceptInvitationTest do | |
assert_no_emails_delivered() | ||
end | ||
|
||
test "transfers ownership with pending invites" do | ||
existing_owner = new_user() | ||
site = new_site(owner: existing_owner) | ||
|
||
invite_guest(site, "[email protected]", role: :viewer, inviter: existing_owner) | ||
|
||
new_owner = new_user() |> subscribe_to_growth_plan() | ||
|
||
assert {:ok, _new_membership} = | ||
AcceptInvitation.transfer_ownership(site, new_owner) | ||
end | ||
|
||
@tag :teams | ||
test "syncs ownership transfers provided memberships exist already" do | ||
site = insert(:site, memberships: []) | ||
|
@@ -310,52 +322,6 @@ defmodule Plausible.Site.Memberships.AcceptInvitationTest do | |
assert_guest_membership(team, site, invitee, :editor) | ||
end | ||
|
||
@tag :teams | ||
test "converts an invitation into a membership (TEAMS)" do | ||
inviter = insert(:user) | ||
invitee = insert(:user) | ||
team = insert(:team) | ||
site = insert(:site, team: team, members: [inviter]) | ||
insert(:team_membership, team: team, user: inviter, role: :owner) | ||
|
||
_invitation = | ||
insert(:invitation, | ||
site_id: site.id, | ||
inviter: inviter, | ||
email: invitee.email, | ||
role: :admin | ||
) | ||
|
||
team_invitation = | ||
insert(:team_invitation, | ||
team: team, | ||
inviter: inviter, | ||
email: invitee.email, | ||
role: :guest | ||
) | ||
|
||
insert(:guest_invitation, team_invitation: team_invitation, site: site, role: :editor) | ||
|
||
assert {:ok, team_membership} = | ||
Plausible.Teams.Invitations.accept(team_invitation.invitation_id, invitee) | ||
|
||
assert [guest_membership] = | ||
Repo.preload(team_membership, :guest_memberships).guest_memberships | ||
|
||
assert guest_membership.site_id == site.id | ||
assert team_membership.user_id == invitee.id | ||
assert guest_membership.role == :editor | ||
assert team_membership.role == :guest | ||
assert team_membership.team_id == team.id | ||
|
||
refute Repo.reload(team_invitation) | ||
|
||
assert_email_delivered_with( | ||
to: [nil: inviter.email], | ||
subject: @subject_prefix <> "#{invitee.email} accepted your invitation to #{site.domain}" | ||
) | ||
end | ||
|
||
test "does not degrade role when trying to invite self as an owner" do | ||
user = insert(:user) | ||
|
||
|