discourse/spec/serializers/notification_serializer_spec.rb
Daniel Waterworth 6e161d3e75
DEV: Allow fab! without block (#24314)
The most common thing that we do with fab! is:

    fab!(:thing) { Fabricate(:thing) }

This commit adds a shorthand for this which is just simply:

    fab!(:thing)

i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
2023-11-09 16:47:59 -06:00

37 lines
1.2 KiB
Ruby

# frozen_string_literal: true
RSpec.describe NotificationSerializer do
describe "#as_json" do
fab!(:user)
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
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
SiteSetting.discourse_connect_url = "http://example.com/discourse_sso"
SiteSetting.discourse_connect_secret = "12345678910"
SiteSetting.enable_discourse_connect = true
expect(json[:notification][:external_id]).to eq("12345")
end
end
end