discourse/spec/system/user_page/user_invites_spec.rb
Linca 826dda2d52
FIX: Show bulk removal of expired invites (#33716)
An existing codepath to bulk delete invites exists, but does not show
up. This commit fixes it and also fixes the old code's bug.

Specifically,
- `destroy_all_expired` endpoint only acts on the `current_user` which
is absolutely counter-intuitive, when a person visits another person’s
profile and is able to see the button, clicking it would delete their
own invites and not those of the profile they are visiting.
- In `UserInvitedShowController` the removedAll state is never set to
the original state, which results in the link being displayed in the
list when the new link expires, but the batch deletion cannot be
displayed unless the page is refreshed. It is replaced by a toast.
2025-07-21 17:13:06 +08:00

33 lines
1.1 KiB
Ruby

# frozen_string_literal: true
describe "User invites", type: :system do
fab!(:admin)
fab!(:user)
fab!(:invites_pending) { [1, 2, 3, 4].map { Fabricate(:invite, invited_by: user) } }
fab!(:invites_expired) do
[1, 2, 3].map { Fabricate(:invite, invited_by: user, expires_at: 2.days.ago) }
end
before do
SiteSetting.invite_expiry_days = 1
sign_in(admin)
end
describe "expired invites" do
let(:user_invite_expired_page) { PageObjects::Pages::UserInvitedExpired.new }
it "correctly shows expired invites" do
user_invite_expired_page.visit(user)
expect(user_invite_expired_page.invites_list.size).to eq(invites_expired.size)
end
it "can remove all expired invites" do
user_invite_expired_page.visit(user)
user_invite_expired_page.bulk_remove_expired_button.click
user_invite_expired_page.find(".btn-danger").click
user_invite_expired_page.wait_till_loaded
expect(user_invite_expired_page).to be_empty
invites_expired.each { |invite| expect(invite.reload.deleted_at).to be_present }
end
end
end