analytics/test/workers/clean_invitations_test.exs
Adrian Gruntkowski 27ac3b6b5b
Address team syncing discrepancies (#4739)
* Clean site transfers after 48 hours

* Sync accepting site transfers and invitations within transaction

* Add dry run mode to teams backfill and make it a default

* Extend invitation clean worker tests
2024-10-28 10:11:47 +00:00

82 lines
2.0 KiB
Elixir

defmodule Plausible.Workers.CleanInvitationsTest do
use Plausible.DataCase
alias Plausible.Workers.CleanInvitations
test "cleans invitations and transfers that are more than 48h old" do
now = NaiveDateTime.utc_now(:second)
insert(:invitation,
inserted_at: NaiveDateTime.shift(now, hour: -49),
site: build(:site),
inviter: build(:user)
)
site = insert(:site, team: build(:team))
team_invitation =
insert(:team_invitation,
inserted_at: NaiveDateTime.shift(now, hour: -49),
team: site.team,
inviter: build(:user),
role: :guest
)
insert(:guest_invitation,
inserted_at: NaiveDateTime.shift(now, hour: -49),
team_invitation: team_invitation,
site: site,
role: :viewer
)
insert(:site_transfer,
inserted_at: NaiveDateTime.shift(now, hour: -49),
site: site,
initiator: build(:user)
)
CleanInvitations.perform(nil)
refute Repo.exists?(Plausible.Auth.Invitation)
refute Repo.exists?(Plausible.Teams.Invitation)
refute Repo.exists?(Plausible.Teams.GuestInvitation)
refute Repo.exists?(Plausible.Teams.SiteTransfer)
end
test "does not clean invitations and transfers that are less than 48h old" do
now = NaiveDateTime.utc_now(:second)
insert(:invitation,
inserted_at: NaiveDateTime.shift(now, hour: -47),
site: build(:site),
inviter: build(:user)
)
site = insert(:site, team: build(:team))
team_invitation =
insert(:team_invitation,
inserted_at: NaiveDateTime.shift(now, hour: -47),
team: site.team,
inviter: build(:user),
role: :guest
)
insert(:guest_invitation,
inserted_at: NaiveDateTime.shift(now, hour: -47),
team_invitation: team_invitation,
site: site,
role: :viewer
)
insert(:site_transfer,
inserted_at: NaiveDateTime.shift(now, hour: -47),
site: site,
initiator: build(:user)
)
CleanInvitations.perform(nil)
assert Repo.exists?(Plausible.Auth.Invitation)
end
end