UX: Improve invite error message when a user uses an email that has already redeemed (#25695)

Improve invite error message when a user uses an email that has already redeemed
This commit is contained in:
Natalie Tay 2024-02-27 18:24:20 +08:00 committed by GitHub
parent fe851a533a
commit a8a39d86b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -192,7 +192,7 @@ class InviteRedeemer
redeeming_user ||= User.where(admin: false, staged: false).find_by_email(email)
if redeeming_user.present? &&
InvitedUser.exists?(user_id: redeeming_user.id, invite_id: invite.id)
return false
raise Invite::UserExists.new(I18n.t("invite.existing_user_already_redemeed"))
end
true

View File

@ -587,13 +587,15 @@ RSpec.describe InviteRedeemer do
expect(invite_link.redemption_count).to eq(1)
end
it "should not redeem the invite if InvitedUser record already exists for email" do
it "raises an error if email has already been invited" do
invite_redeemer.redeem
invite_link.reload
another_invite_redeemer = InviteRedeemer.new(invite: invite_link, email: "foo@example.com")
another_user = another_invite_redeemer.redeem
expect(another_user).to eq(nil)
expect { another_invite_redeemer.redeem }.to raise_error(
Invite::UserExists,
I18n.t("invite.existing_user_already_redemeed"),
)
end
it "should redeem the invite if InvitedUser record does not exists for email" do