Commit d33dde1f authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch 'am-check-for-permit-data-categories-insubmit-service' into 'master'

Check PermitDataCategories.product_intelligence_enabled in submit service ping service [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!65998
parents 6d2f8e44 549a9afd
......@@ -19,12 +19,12 @@ module ServicePing
CATEGORIES
end
private
def product_intelligence_enabled?
pings_enabled? && !User.single_user&.requires_usage_stats_consent?
end
private
def pings_enabled?
::Gitlab::CurrentSettings.usage_ping_enabled?
end
......
......@@ -18,8 +18,7 @@ module ServicePing
SubmissionError = Class.new(StandardError)
def execute
return unless Gitlab::CurrentSettings.usage_ping_enabled?
return if User.single_user&.requires_usage_stats_consent?
return unless ServicePing::PermitDataCategoriesService.new.product_intelligence_enabled?
usage_data = Gitlab::UsageData.data(force_refresh: true)
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe ServicePing::PermitDataCategoriesService do
using RSpec::Parameterized::TableSyntax
describe '#execute' do
subject(:permitted_categories) { described_class.new.execute }
......@@ -96,4 +98,38 @@ 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(usage_ping_required_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
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe ServicePing::PermitDataCategoriesService do
using RSpec::Parameterized::TableSyntax
describe '#execute', :without_license do
subject(:permitted_categories) { described_class.new.execute }
......@@ -39,4 +41,27 @@ 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
......@@ -98,6 +98,34 @@ RSpec.describe ServicePing::SubmitService do
it_behaves_like 'does not run'
end
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
end
it_behaves_like 'does not run'
end
context 'when product_intelligence_enabled is true' 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
end
it 'generates service ping' do
stub_response(body: with_dev_ops_score_params)
expect(Gitlab::UsageData).to receive(:data).with(force_refresh: true).and_call_original
subject.execute
end
end
context 'when usage ping is enabled' do
before do
stub_usage_data_connections
......
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