discourse/spec/serializers/invite_serializer_spec.rb
Natalie Tay d2ef490e9a
FIX: Hide delete button to invite as user are unable to delete anyway (#21884)
Moderators are not allowed to delete invites that don't belong to them
2023-06-06 12:24:19 +08:00

38 lines
1.2 KiB
Ruby

# frozen_string_literal: true
RSpec.describe InviteSerializer do
describe "#can_delete_invite" do
fab!(:user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:invite_from_user) { Fabricate(:invite, invited_by: user) }
fab!(:invite_from_moderator) { Fabricate(:invite, invited_by: moderator) }
it "returns true for admin" do
serializer = InviteSerializer.new(invite_from_user, scope: Guardian.new(admin), root: false)
expect(serializer.as_json[:can_delete_invite]).to eq(true)
end
it "returns false for moderator" do
serializer =
InviteSerializer.new(invite_from_user, scope: Guardian.new(moderator), root: false)
expect(serializer.as_json[:can_delete_invite]).to eq(false)
end
it "returns true for inviter" do
serializer = InviteSerializer.new(invite_from_user, scope: Guardian.new(user), root: false)
expect(serializer.as_json[:can_delete_invite]).to eq(true)
end
it "returns false for plain user" do
serializer =
InviteSerializer.new(invite_from_moderator, scope: Guardian.new(user), root: false)
expect(serializer.as_json[:can_delete_invite]).to eq(false)
end
end
end