2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-03 23:54:20 +08:00
discourse/spec/serializers/auth_provider_serializer_spec.rb
Chris Alberti 1f227a5eb4
DEV: Add capability to pass an icon setting into auth provider registration (#34584)
Add capability to pass an icon setting into auth provider registration to override the default icon with a site setting.

Matches the pattern we use for the auth provider title and pretty name. 

With this, the SAML plugin can be updated to have a site setting to override the default "user" icon.
2025-08-28 09:14:36 -05:00

69 lines
1.8 KiB
Ruby

# frozen_string_literal: true
RSpec.describe AuthProviderSerializer do
fab!(:user)
before do
allow(SiteSetting).to receive(:get).and_call_original
allow(SiteSetting).to receive(:get).with(:test_icon).and_return("bullseye")
allow(SiteSetting).to receive(:get).with(:test_pretty_name).and_return("new pretty name")
allow(SiteSetting).to receive(:get).with(:test_title).and_return("new_title")
end
let(:authenticator) do
Class
.new(Auth::ManagedAuthenticator) do
def name
"test_auth"
end
def enabled?
true
end
end
.new
end
let(:serializer) do
AuthProviderSerializer.new(auth_provider, scope: Guardian.new(user), root: false)
end
context "without overridden attributes" do
let(:auth_provider) do
Auth::AuthProvider.new(
authenticator:,
icon: "flash",
pretty_name: "old pretty name",
title: "old_title",
)
end
it "returns the original values" do
json = serializer.as_json
expect(json[:pretty_name_override]).to eq("old pretty name")
expect(json[:title_override]).to eq("old_title")
expect(json[:icon_override]).to eq("flash")
end
end
context "with overridden attributes" do
let(:auth_provider) do
Auth::AuthProvider.new(
authenticator:,
icon: "flash",
icon_setting: :test_icon,
pretty_name: "old pretty name",
pretty_name_setting: :test_pretty_name,
title: "old_title",
title_setting: :test_title,
)
end
it "returns the overridden values" do
json = serializer.as_json
expect(json[:pretty_name_override]).to eq("new pretty name")
expect(json[:title_override]).to eq("new_title")
expect(json[:icon_override]).to eq("bullseye")
end
end
end