2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-16 07:48:57 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe CategorySerializer do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:group) { Fabricate(:group) }
|
|
|
|
fab!(:category) { Fabricate(:category, reviewable_by_group_id: group.id) }
|
2019-04-17 17:12:32 -04:00
|
|
|
|
|
|
|
it "includes the reviewable by group name if enabled" do
|
2020-07-14 12:36:19 -04:00
|
|
|
SiteSetting.enable_category_group_moderation = true
|
2019-04-17 17:12:32 -04:00
|
|
|
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
|
|
|
expect(json[:reviewable_by_group_name]).to eq(group.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't include the reviewable by group name if disabled" do
|
2020-07-14 12:36:19 -04:00
|
|
|
SiteSetting.enable_category_group_moderation = false
|
2019-04-17 17:12:32 -04:00
|
|
|
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
|
|
|
expect(json[:reviewable_by_group_name]).to be_blank
|
|
|
|
end
|
2019-03-16 07:48:57 -04:00
|
|
|
|
|
|
|
it "includes custom fields" do
|
2019-03-24 22:29:56 -04:00
|
|
|
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
|
|
|
expect(json[:custom_fields]).to be_empty
|
|
|
|
|
2019-03-16 07:48:57 -04:00
|
|
|
category.custom_fields["enable_marketplace"] = true
|
|
|
|
category.save_custom_fields
|
|
|
|
|
|
|
|
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
|
|
|
expect(json[:custom_fields]).to be_present
|
|
|
|
end
|
2020-04-28 12:05:53 -04:00
|
|
|
|
2020-06-24 03:07:52 -04:00
|
|
|
it "does not include the default notification level when there is no user" do
|
2020-04-28 12:05:53 -04:00
|
|
|
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
2020-06-24 03:07:52 -04:00
|
|
|
expect(json.key?(:notification_level)).to eq(false)
|
2020-04-28 12:05:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "user notification level" do
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
it "includes the user's notification level" do
|
|
|
|
CategoryUser.set_notification_level_for_category(user, NotificationLevels.all[:watching], category.id)
|
|
|
|
json = described_class.new(category, scope: Guardian.new(user), root: false).as_json
|
|
|
|
expect(json[:notification_level]).to eq(NotificationLevels.all[:watching])
|
|
|
|
end
|
|
|
|
end
|
2021-06-02 13:18:45 -04:00
|
|
|
|
|
|
|
describe "available groups" do
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
it "not included for a regular user" do
|
|
|
|
json = described_class.new(category, scope: Guardian.new(user), root: false).as_json
|
|
|
|
expect(json[:available_groups]).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "included for an admin" do
|
|
|
|
json = described_class.new(category, scope: Guardian.new(admin), root: false).as_json
|
|
|
|
expect(json[:available_groups]).to eq(Group.order(:name).pluck(:name) - ['everyone'])
|
|
|
|
end
|
|
|
|
end
|
2019-03-16 07:48:57 -04:00
|
|
|
end
|