2022-08-09 05:54:33 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe FoundUserSerializer do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:user)
|
2022-08-09 05:54:33 -05:00
|
|
|
let(:serializer) { described_class.new(user, root: false) }
|
|
|
|
|
2023-04-25 09:25:57 -05:00
|
|
|
describe "#id" do
|
|
|
|
it "returns user id" do
|
|
|
|
json = serializer.as_json
|
|
|
|
expect(json.keys).to include :id
|
|
|
|
expect(json[:id]).to eq(user.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe "#name" do
|
2022-08-09 05:54:33 -05:00
|
|
|
it "returns name if enabled in site settings" do
|
|
|
|
SiteSetting.enable_names = true
|
|
|
|
json = serializer.as_json
|
|
|
|
expect(json.keys).to include :name
|
|
|
|
expect(json[:name]).to eq(user.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't return name if disabled in site settings" do
|
|
|
|
SiteSetting.enable_names = false
|
|
|
|
json = serializer.as_json
|
|
|
|
expect(json.keys).not_to include :name
|
|
|
|
end
|
|
|
|
end
|
2024-02-26 07:40:48 -06:00
|
|
|
|
|
|
|
describe "#status" do
|
2024-02-01 10:28:10 -06:00
|
|
|
fab!(:user_status)
|
2024-02-26 07:40:48 -06:00
|
|
|
|
|
|
|
before { user.user_status = user_status }
|
|
|
|
|
|
|
|
context "when status is enabled in site settings" do
|
|
|
|
before { SiteSetting.enable_user_status = true }
|
|
|
|
|
|
|
|
it "doesn't add user status by default" do
|
|
|
|
serializer = FoundUserSerializer.new(user, root: false)
|
|
|
|
json = serializer.as_json
|
|
|
|
expect(json.keys).not_to include :status
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when including user status" do
|
|
|
|
let(:serializer) { FoundUserSerializer.new(user, root: false, include_status: true) }
|
|
|
|
|
|
|
|
it "adds user status when enabled" do
|
|
|
|
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 expired user status" do
|
|
|
|
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
|
|
|
|
user.clear_status!
|
|
|
|
user.reload
|
|
|
|
json = serializer.as_json
|
|
|
|
|
|
|
|
expect(json.keys).not_to include :status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when status is disabled in site settings" do
|
|
|
|
before { SiteSetting.enable_user_status = false }
|
|
|
|
let(:serializer) { FoundUserSerializer.new(user, root: false, include_status: true) }
|
|
|
|
|
|
|
|
it "doesn't add user status" do
|
|
|
|
json = serializer.as_json
|
|
|
|
expect(json.keys).not_to include :status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-08-09 05:54:33 -05:00
|
|
|
end
|