2022-12-14 17:18:09 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe GroupUserSerializer do
|
|
|
|
let(:serializer) { described_class.new(user, scope: Guardian.new(user), root: false) }
|
|
|
|
|
|
|
|
describe "#status" do
|
2023-11-10 06:47:59 +08:00
|
|
|
fab!(:user_status)
|
2022-12-14 17:18:09 +08:00
|
|
|
fab!(:user) { Fabricate(:user, user_status: user_status) }
|
|
|
|
|
|
|
|
it "adds user status when enabled in site settings" do
|
|
|
|
SiteSetting.enable_user_status = true
|
|
|
|
|
|
|
|
json = serializer.as_json
|
|
|
|
|
|
|
|
expect(json[:status]).to_not be_nil do |status|
|
|
|
|
expect(status.description).to eq(user_status.description)
|
|
|
|
expect(status.emoji).to eq(user_status.emoji)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't add user status when disabled in site settings" do
|
|
|
|
SiteSetting.enable_user_status = false
|
|
|
|
json = serializer.as_json
|
|
|
|
expect(json.keys).not_to include :status
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't add expired user status" do
|
|
|
|
SiteSetting.enable_user_status = true
|
|
|
|
|
|
|
|
user.user_status.ends_at = 1.minutes.ago
|
|
|
|
serializer = described_class.new(user, scope: Guardian.new(user), root: false)
|
|
|
|
json = serializer.as_json
|
|
|
|
|
|
|
|
expect(json.keys).not_to include :status
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't return status if user doesn't have it" do
|
|
|
|
SiteSetting.enable_user_status = true
|
|
|
|
|
|
|
|
user.clear_status!
|
|
|
|
user.reload
|
|
|
|
json = serializer.as_json
|
|
|
|
|
|
|
|
expect(json.keys).not_to include :status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|