summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-22 12:08:40 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-22 12:08:40 +0000
commitbe3e24ea3c9f497efde85900df298ce9bc42fce8 (patch)
treefd0de9443253a1b21ca9a2741dc34ba3aef795be /spec/services
parent001243986195143c395a9811d8254bbf1b9ebfa1 (diff)
downloadgitlab-ce-be3e24ea3c9f497efde85900df298ce9bc42fce8.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/submit_usage_ping_service_spec.rb122
1 files changed, 68 insertions, 54 deletions
diff --git a/spec/services/submit_usage_ping_service_spec.rb b/spec/services/submit_usage_ping_service_spec.rb
index 719b374553c..e2f1ef089bf 100644
--- a/spec/services/submit_usage_ping_service_spec.rb
+++ b/spec/services/submit_usage_ping_service_spec.rb
@@ -5,6 +5,49 @@ require 'spec_helper'
describe SubmitUsagePingService do
include StubRequests
+ let(:score_params) do
+ {
+ score: {
+ leader_issues: 10.2,
+ instance_issues: 3.2,
+ percentage_issues: 31.37,
+
+ leader_notes: 25.3,
+ instance_notes: 23.2,
+
+ leader_milestones: 16.2,
+ instance_milestones: 5.5,
+
+ leader_boards: 5.2,
+ instance_boards: 3.2,
+
+ leader_merge_requests: 5.2,
+ instance_merge_requests: 3.2,
+
+ leader_ci_pipelines: 25.1,
+ instance_ci_pipelines: 21.3,
+
+ leader_environments: 3.3,
+ instance_environments: 2.2,
+
+ leader_deployments: 41.3,
+ instance_deployments: 15.2,
+
+ leader_projects_prometheus_active: 0.31,
+ instance_projects_prometheus_active: 0.30,
+
+ leader_service_desk_issues: 15.8,
+ instance_service_desk_issues: 15.1,
+
+ non_existing_column: 'value'
+ }
+ }
+ end
+
+ let(:with_dev_ops_score_params) { { dev_ops_score: score_params[:score] } }
+ let(:with_conv_index_params) { { conv_index: score_params[:score] } }
+ let(:without_dev_ops_score_params) { { dev_ops_score: {} } }
+
context 'when usage ping is disabled' do
before do
stub_application_setting(usage_ping_enabled: false)
@@ -19,13 +62,25 @@ describe SubmitUsagePingService do
end
end
+ shared_examples 'saves DevOps score data from the response' do
+ it do
+ expect { subject.execute }
+ .to change { DevOpsScore::Metric.count }
+ .by(1)
+
+ expect(DevOpsScore::Metric.last.leader_issues).to eq 10.2
+ expect(DevOpsScore::Metric.last.instance_issues).to eq 3.2
+ expect(DevOpsScore::Metric.last.percentage_issues).to eq 31.37
+ end
+ end
+
context 'when usage ping is enabled' do
before do
stub_application_setting(usage_ping_enabled: true)
end
it 'sends a POST request' do
- response = stub_response(without_conv_index_params)
+ response = stub_response(without_dev_ops_score_params)
subject.execute
@@ -33,7 +88,7 @@ describe SubmitUsagePingService do
end
it 'refreshes usage data statistics before submitting' do
- stub_response(without_conv_index_params)
+ stub_response(without_dev_ops_score_params)
expect(Gitlab::UsageData).to receive(:to_json)
.with(force_refresh: true)
@@ -42,62 +97,21 @@ describe SubmitUsagePingService do
subject.execute
end
- it 'saves DevOps Score data from the response' do
- stub_response(with_conv_index_params)
+ context 'when conv_index data is passed' do
+ before do
+ stub_response(with_conv_index_params)
+ end
- expect { subject.execute }
- .to change { DevOpsScore::Metric.count }
- .by(1)
-
- expect(DevOpsScore::Metric.last.leader_issues).to eq 10.2
- expect(DevOpsScore::Metric.last.instance_issues).to eq 3.2
- expect(DevOpsScore::Metric.last.percentage_issues).to eq 31.37
+ it_behaves_like 'saves DevOps score data from the response'
end
- end
-
- def without_conv_index_params
- {
- conv_index: {}
- }
- end
- def with_conv_index_params
- {
- conv_index: {
- leader_issues: 10.2,
- instance_issues: 3.2,
- percentage_issues: 31.37,
-
- leader_notes: 25.3,
- instance_notes: 23.2,
-
- leader_milestones: 16.2,
- instance_milestones: 5.5,
+ context 'when DevOps score data is passed' do
+ before do
+ stub_response(with_dev_ops_score_params)
+ end
- leader_boards: 5.2,
- instance_boards: 3.2,
-
- leader_merge_requests: 5.2,
- instance_merge_requests: 3.2,
-
- leader_ci_pipelines: 25.1,
- instance_ci_pipelines: 21.3,
-
- leader_environments: 3.3,
- instance_environments: 2.2,
-
- leader_deployments: 41.3,
- instance_deployments: 15.2,
-
- leader_projects_prometheus_active: 0.31,
- instance_projects_prometheus_active: 0.30,
-
- leader_service_desk_issues: 15.8,
- instance_service_desk_issues: 15.1,
-
- non_existing_column: 'value'
- }
- }
+ it_behaves_like 'saves DevOps score data from the response'
+ end
end
def stub_response(body)