discourse/spec/serializers/site_serializer_spec.rb
Vinoth Kannan 8348a41124
FEATURE: add regular_categories field in site setting & user option. (#10477)
Like "default watching" and "default tracking" categories option now the "regular" categories support is added. It will be useful for sites that are muted by default. The user option will be displayed only if `mute_all_categories_by_default` site setting is enabled.
2020-08-20 00:35:04 +05:30

32 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe SiteSerializer do
let(:guardian) { Guardian.new }
let(:category) { Fabricate(:category) }
it "includes category custom fields only if its preloaded" do
category.custom_fields["enable_marketplace"] = true
category.save_custom_fields
data = MultiJson.dump(described_class.new(Site.new(guardian), scope: guardian, root: false))
expect(data).not_to include("enable_marketplace")
Site.preloaded_category_custom_fields << "enable_marketplace"
data = MultiJson.dump(described_class.new(Site.new(guardian), scope: guardian, root: false))
expect(data).to include("enable_marketplace")
end
it "returns correct notification level for categories" do
SiteSetting.mute_all_categories_by_default = true
SiteSetting.default_categories_regular = category.id.to_s
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
categories = serialized[:categories]
expect(categories[0][:notification_level]).to eq(0)
expect(categories[-1][:notification_level]).to eq(1)
end
end