2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe ReviewableUserSerializer do
|
2019-04-04 04:41:04 +08:00
|
|
|
let(:user) { Fabricate(:user) }
|
2019-01-04 01:03:01 +08:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
2024-05-31 01:30:06 +08:00
|
|
|
let(:moderator) { Fabricate(:moderator) }
|
|
|
|
let(:reviewable) { Reviewable.find_by(target: user) }
|
2019-01-04 01:03:01 +08:00
|
|
|
|
2024-05-31 01:30:06 +08:00
|
|
|
before do
|
2019-04-11 23:11:35 +08:00
|
|
|
SiteSetting.must_approve_users = true
|
2019-04-04 04:41:04 +08:00
|
|
|
Jobs::CreateUserReviewable.new.execute(user_id: user.id)
|
2024-05-31 01:30:06 +08:00
|
|
|
end
|
2019-04-04 04:41:04 +08:00
|
|
|
|
2024-05-31 01:30:06 +08:00
|
|
|
it "includes the user fields for review" do
|
2019-01-04 01:03:01 +08:00
|
|
|
json = ReviewableUserSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
|
|
|
expect(json[:user_id]).to eq(reviewable.target_id)
|
2019-04-04 04:41:04 +08:00
|
|
|
expect(json[:payload]["username"]).to eq(user.username)
|
|
|
|
expect(json[:payload]["email"]).to eq(user.email)
|
|
|
|
expect(json[:payload]["name"]).to eq(user.name)
|
2019-04-02 02:28:57 +08:00
|
|
|
expect(json[:topic_url]).to be_blank
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|
2024-05-31 01:30:06 +08:00
|
|
|
|
|
|
|
it "excludes the email user field for moderators" do
|
|
|
|
json =
|
|
|
|
ReviewableUserSerializer.new(reviewable, scope: Guardian.new(moderator), root: nil).as_json
|
|
|
|
expect(json[:user_id]).to eq(reviewable.target_id)
|
|
|
|
expect(json[:payload]["username"]).to eq(user.username)
|
|
|
|
expect(json[:payload]["email"]).to eq(nil)
|
|
|
|
expect(json[:payload]["name"]).to eq(user.name)
|
|
|
|
expect(json[:topic_url]).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes the email user field for moderators if enabled" do
|
|
|
|
SiteSetting.moderators_view_emails = true
|
|
|
|
|
|
|
|
json =
|
|
|
|
ReviewableUserSerializer.new(reviewable, scope: Guardian.new(moderator), root: nil).as_json
|
|
|
|
expect(json[:user_id]).to eq(reviewable.target_id)
|
|
|
|
expect(json[:payload]["username"]).to eq(user.username)
|
|
|
|
expect(json[:payload]["email"]).to eq(user.email)
|
|
|
|
expect(json[:payload]["name"]).to eq(user.name)
|
|
|
|
expect(json[:topic_url]).to be_blank
|
|
|
|
end
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|