discourse/spec/serializers/concerns/user_status_mixin_spec.rb
Andrei Prigorshnev b3a1199493
FEATURE: Hide user status when user is hiding public profile and presence (#24300)
Users can hide their public profile and presence information by checking 
“Hide my public profile and presence features” on the 
`u/{username}/preferences/interface` page. In that case, we also don't 
want to return user status from the server.

This work has been started in https://github.com/discourse/discourse/pull/23946. 
The current PR fixes all the remaining places in Core.

Note that the actual fix is quite simple – a5802f484d. 
But we had a fair amount of duplication in the code responsible for 
the user status serialization, so I had to dry that up first. The refactoring 
as well as adding some additional tests is the main part of this PR.
2024-02-26 17:40:48 +04:00

44 lines
1.3 KiB
Ruby

# frozen_string_literal: true
RSpec.describe UserStatusMixin do
fab!(:user_status) { Fabricate(:user_status) }
fab!(:user) { Fabricate(:user, user_status: user_status) }
class DummySerializer < ApplicationSerializer
include UserStatusMixin
end
context "when user status is disabled" do
before { SiteSetting.enable_user_status = false }
it "doesn't include status" do
serializer = DummySerializer.new(user, root: false, include_status: true)
json = serializer.as_json
expect(json[:status]).to be_nil
end
end
context "when user status is enabled" do
before { SiteSetting.enable_user_status = true }
it "doesn't include status by default" do
serializer = DummySerializer.new(user, root: false)
json = serializer.as_json
expect(json[:status]).to be_nil
end
it "includes status when include_status option is passed" do
serializer = DummySerializer.new(user, root: false, include_status: true)
json = serializer.as_json
expect(json[:status]).to be_present
end
it "doesn't include status if user hid profile and presence" do
user.user_option.hide_profile_and_presence = true
serializer = DummySerializer.new(user, root: false, include_status: true)
json = serializer.as_json
expect(json[:status]).to be_nil
end
end
end