Commit a3246c17 authored by Rajendra Kadam's avatar Rajendra Kadam

Fix specs and remove prepend

parent 41a46db7
......@@ -7,6 +7,8 @@ module ServicePing
pings_enabled? && !User.single_user&.requires_usage_stats_consent?
end
private
def pings_enabled?
::Gitlab::CurrentSettings.usage_ping_enabled?
end
......
......@@ -18,7 +18,7 @@ module ServicePing
SubmissionError = Class.new(StandardError)
def execute
return unless ServicePing::PermitDataCategoriesService.new.product_intelligence_enabled?
return unless ServicePing::ServicePingSettings.product_intelligence_enabled?
begin
usage_data = BuildPayloadService.new.execute
......
......@@ -13,7 +13,7 @@ module EE
override :execute
def execute
return super unless ::License.current.present?
return [] unless product_intelligence_enabled?
return [] unless ServicePing::ServicePingSettings.product_intelligence_enabled?
optional_enabled = ::Gitlab::CurrentSettings.usage_ping_enabled?
customer_service_enabled = ::License.current.customer_service_enabled?
......@@ -23,13 +23,6 @@ module EE
categories << OPERATIONAL_CATEGORY if customer_service_enabled
end.to_set
end
private
override :pings_enabled?
def pings_enabled?
::License.current&.customer_service_enabled? || super
end
end
end
end
# frozen_string_literal: true
module EE
module ServicePing
module ServicePingSettings
class << self
def product_intelligence_enabled?
pings_enabled? && !::User.single_user&.requires_usage_stats_consent?
end
private
def pings_enabled?
::License.current&.customer_service_enabled? || ::Gitlab::CurrentSettings.usage_ping_enabled?
end
end
end
end
end
......@@ -78,6 +78,7 @@ RSpec.describe ServicePing::PermitDataCategoriesService do
before do
# License.current.usage_ping? == true
create_current_license(operational_metrics_enabled: true)
allow(ServicePing::ServicePingSettings).to receive(:product_intelligence_enabled?).and_return(true)
end
it 'returns all categories' do
......@@ -98,38 +99,4 @@ RSpec.describe ServicePing::PermitDataCategoriesService do
end
end
end
describe '#product_intelligence_enabled?' do
where(:usage_ping_enabled, :customer_service_enabled, :requires_usage_stats_consent, :expected_product_intelligence_enabled) do
# Customer service enabled
true | true | false | true
false | true | true | false
false | true | false | true
true | true | true | false
# Customer service disabled
true | false | false | true
true | false | true | false
false | false | false | false
false | false | true | false
# When there is no license it should have same behaviour as ce
true | nil | false | true
false | nil | false | false
false | nil | true | false
true | nil | true | false
end
with_them do
before do
allow(User).to receive(:single_user).and_return(double(:user, requires_usage_stats_consent?: requires_usage_stats_consent))
stub_config_setting(usage_ping_enabled: usage_ping_enabled)
create_current_license(operational_metrics_enabled: customer_service_enabled)
end
it 'has the correct product_intelligence_enabled?' do
expect(described_class.new.product_intelligence_enabled?).to eq(expected_product_intelligence_enabled)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe EE::ServicePing::ServicePingSettings do
using RSpec::Parameterized::TableSyntax
describe '#product_intelligence_enabled?' do
where(:usage_ping_enabled, :customer_service_enabled, :requires_usage_stats_consent, :expected_product_intelligence_enabled) do
# Customer service enabled
true | true | false | true
false | true | true | false
false | true | false | true
true | true | true | false
# Customer service disabled
true | false | false | true
true | false | true | false
false | false | false | false
false | false | true | false
# When there is no license it should have same behaviour as ce
true | nil | false | true
false | nil | false | false
false | nil | true | false
true | nil | true | false
end
with_them do
before do
allow(User).to receive(:single_user).and_return(double(:user, requires_usage_stats_consent?: requires_usage_stats_consent))
stub_config_setting(usage_ping_enabled: usage_ping_enabled)
create_current_license(operational_metrics_enabled: customer_service_enabled)
end
it 'has the correct product_intelligence_enabled?' do
expect(described_class.product_intelligence_enabled?).to eq(expected_product_intelligence_enabled)
end
end
end
end
......@@ -41,27 +41,4 @@ RSpec.describe ServicePing::PermitDataCategoriesService do
end
end
end
# describe '#product_intelligence_enabled?' do
# where(:usage_ping_enabled, :requires_usage_stats_consent, :expected_product_intelligence_enabled) do
# # Usage ping enabled
# true | false | true
# true | true | false
# # Usage ping disabled
# false | false | false
# false | true | false
# end
# with_them do
# before do
# allow(User).to receive(:single_user).and_return(double(:user, requires_usage_stats_consent?: requires_usage_stats_consent))
# stub_config_setting(usage_ping_enabled: usage_ping_enabled)
# end
# it 'has the correct product_intelligence_enabled?' do
# expect(described_class.new.product_intelligence_enabled?).to eq(expected_product_intelligence_enabled)
# end
# end
# end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ServicePing::ServicePingSettings do
using RSpec::Parameterized::TableSyntax
describe '#product_intelligence_enabled?' do
where(:usage_ping_enabled, :requires_usage_stats_consent, :expected_product_intelligence_enabled) do
# Usage ping enabled
true | false | true
true | true | false
# Usage ping disabled
false | false | false
false | true | false
end
with_them do
before do
allow(User).to receive(:single_user).and_return(double(:user, requires_usage_stats_consent?: requires_usage_stats_consent))
stub_config_setting(usage_ping_enabled: usage_ping_enabled)
end
it 'has the correct product_intelligence_enabled?' do
expect(described_class.product_intelligence_enabled?).to eq(expected_product_intelligence_enabled)
end
end
end
end
......@@ -100,9 +100,7 @@ RSpec.describe ServicePing::SubmitService do
context 'when product_intelligence_enabled is false' do
before do
allow_next_instance_of(ServicePing::PermitDataCategoriesService) do |service|
allow(service).to receive(:product_intelligence_enabled?).and_return(false)
end
allow(ServicePing::ServicePingSettings).to receive(:product_intelligence_enabled?).and_return(false)
end
it_behaves_like 'does not run'
......@@ -112,9 +110,7 @@ RSpec.describe ServicePing::SubmitService do
before do
stub_usage_data_connections
allow_next_instance_of(ServicePing::PermitDataCategoriesService) do |service|
allow(service).to receive(:product_intelligence_enabled?).and_return(true)
end
allow(ServicePing::ServicePingSettings).to receive(:product_intelligence_enabled?).and_return(true)
end
it 'generates service ping' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment