diff options
Diffstat (limited to 'spec/services/service_ping/submit_service_ping_service_spec.rb')
-rw-r--r-- | spec/services/service_ping/submit_service_ping_service_spec.rb | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/spec/services/service_ping/submit_service_ping_service_spec.rb b/spec/services/service_ping/submit_service_ping_service_spec.rb index 2971c9a9309..73be8f000a9 100644 --- a/spec/services/service_ping/submit_service_ping_service_spec.rb +++ b/spec/services/service_ping/submit_service_ping_service_spec.rb @@ -55,7 +55,7 @@ RSpec.describe ServicePing::SubmitService do shared_examples 'does not run' do it do expect(Gitlab::HTTP).not_to receive(:post) - expect(Gitlab::UsageData).not_to receive(:data) + expect(Gitlab::Usage::ServicePingReport).not_to receive(:for) subject.execute end @@ -63,7 +63,7 @@ RSpec.describe ServicePing::SubmitService do shared_examples 'does not send a blank usage ping payload' do it do - expect(Gitlab::HTTP).not_to receive(:post) + expect(Gitlab::HTTP).not_to receive(:post).with(subject.url, any_args) expect { subject.execute }.to raise_error(described_class::SubmissionError) do |error| expect(error.message).to include('Usage data is blank') @@ -118,7 +118,7 @@ RSpec.describe ServicePing::SubmitService do 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 + expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_call_original subject.execute end @@ -129,6 +129,7 @@ RSpec.describe ServicePing::SubmitService do stub_usage_data_connections stub_database_flavor_check stub_application_setting(usage_ping_enabled: true) + stub_response(body: nil, url: subject.error_url, status: 201) end context 'and user requires usage stats consent' do @@ -150,7 +151,7 @@ RSpec.describe ServicePing::SubmitService do it 'forces a refresh of usage data statistics before submitting' do stub_response(body: with_dev_ops_score_params) - expect(Gitlab::UsageData).to receive(:data).with(force_refresh: true).and_call_original + expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_call_original subject.execute end @@ -166,7 +167,7 @@ RSpec.describe ServicePing::SubmitService do recorded_at = Time.current usage_data = { uuid: 'uuid', recorded_at: recorded_at } - expect(Gitlab::UsageData).to receive(:data).with(force_refresh: true).and_return(usage_data) + expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_return(usage_data) subject.execute @@ -189,7 +190,7 @@ RSpec.describe ServicePing::SubmitService do recorded_at = Time.current usage_data = { uuid: 'uuid', recorded_at: recorded_at } - expect(Gitlab::UsageData).to receive(:data).with(force_refresh: true).and_return(usage_data) + expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_return(usage_data) subject.execute @@ -234,7 +235,7 @@ RSpec.describe ServicePing::SubmitService do recorded_at = Time.current usage_data = { uuid: 'uuid', recorded_at: recorded_at } - expect(Gitlab::UsageData).to receive(:data).with(force_refresh: true).and_return(usage_data) + expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_return(usage_data) subject.execute @@ -259,7 +260,7 @@ RSpec.describe ServicePing::SubmitService do context 'and usage data is empty string' do before do - allow(Gitlab::UsageData).to receive(:data).and_return({}) + allow(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_return({}) end it_behaves_like 'does not send a blank usage ping payload' @@ -268,7 +269,7 @@ RSpec.describe ServicePing::SubmitService do context 'and usage data is nil' do before do allow(ServicePing::BuildPayloadService).to receive(:execute).and_return(nil) - allow(Gitlab::UsageData).to receive(:data).and_return(nil) + allow(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_return(nil) end it_behaves_like 'does not send a blank usage ping payload' @@ -277,13 +278,23 @@ RSpec.describe ServicePing::SubmitService do context 'if payload service fails' do before do stub_response(body: with_dev_ops_score_params) - allow(ServicePing::BuildPayloadService).to receive(:execute).and_raise(described_class::SubmissionError, 'SubmissionError') + allow(ServicePing::BuildPayloadService).to receive_message_chain(:new, :execute) + .and_raise(described_class::SubmissionError, 'SubmissionError') end - it 'calls UsageData .data method' do + it 'calls Gitlab::Usage::ServicePingReport .for method' do usage_data = build_usage_data - expect(Gitlab::UsageData).to receive(:data).and_return(usage_data) + expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_return(usage_data) + + subject.execute + end + + it 'submits error' do + expect(Gitlab::HTTP).to receive(:post).with(subject.url, any_args) + .and_call_original + expect(Gitlab::HTTP).to receive(:post).with(subject.error_url, any_args) + .and_call_original subject.execute end @@ -315,10 +326,10 @@ RSpec.describe ServicePing::SubmitService do end end - it 'calls UsageData .data method' do + it 'calls Gitlab::Usage::ServicePingReport .for method' do usage_data = build_usage_data - expect(Gitlab::UsageData).to receive(:data).and_return(usage_data) + expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_return(usage_data) # SubmissionError is raised as a result of 404 in response from HTTP Request expect { subject.execute }.to raise_error(described_class::SubmissionError) |