2019-10-21 18:24:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe NotificationSerializer do
|
2019-10-21 18:24:41 -04:00
|
|
|
describe "#as_json" do
|
2023-11-09 17:47:59 -05:00
|
|
|
fab!(:user)
|
2019-10-21 18:24:41 -04:00
|
|
|
let(:notification) { Fabricate(:notification, user: user) }
|
|
|
|
let(:serializer) { NotificationSerializer.new(notification) }
|
|
|
|
let(:json) { serializer.as_json }
|
|
|
|
|
|
|
|
it "returns the user_id" do
|
|
|
|
expect(json[:notification][:user_id]).to eq(user.id)
|
|
|
|
end
|
|
|
|
|
2020-07-13 14:07:39 -04:00
|
|
|
it "does not include external_id when sso is disabled" do
|
|
|
|
expect(json[:notification].key?(:external_id)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#sso_enabled" do
|
|
|
|
let :user do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
SingleSignOnRecord.create!(user_id: user.id, external_id: "12345", last_payload: "")
|
|
|
|
user
|
|
|
|
end
|
|
|
|
let(:notification) { Fabricate(:notification, user: user) }
|
|
|
|
let(:serializer) { NotificationSerializer.new(notification) }
|
|
|
|
let(:json) { serializer.as_json }
|
|
|
|
|
|
|
|
it "should include the external_id" do
|
2021-02-08 05:04:33 -05:00
|
|
|
SiteSetting.discourse_connect_url = "http://example.com/discourse_sso"
|
|
|
|
SiteSetting.discourse_connect_secret = "12345678910"
|
|
|
|
SiteSetting.enable_discourse_connect = true
|
2020-07-13 14:07:39 -04:00
|
|
|
expect(json[:notification][:external_id]).to eq("12345")
|
|
|
|
end
|
2019-10-21 18:24:41 -04:00
|
|
|
end
|
|
|
|
end
|