2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-24 06:25:44 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe SubmitUsagePingService do
|
2019-04-21 06:03:26 -04:00
|
|
|
include StubRequests
|
|
|
|
|
2017-05-24 06:25:44 -04:00
|
|
|
context 'when usage ping is disabled' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(usage_ping_enabled: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not run' do
|
|
|
|
expect(HTTParty).not_to receive(:post)
|
|
|
|
|
|
|
|
result = subject.execute
|
|
|
|
|
|
|
|
expect(result).to eq false
|
|
|
|
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)
|
|
|
|
|
|
|
|
subject.execute
|
|
|
|
|
|
|
|
expect(response).to have_been_requested
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'refreshes usage data statistics before submitting' do
|
|
|
|
stub_response(without_conv_index_params)
|
|
|
|
|
|
|
|
expect(Gitlab::UsageData).to receive(:to_json)
|
|
|
|
.with(force_refresh: true)
|
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
subject.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves conversational development index data from the response' do
|
|
|
|
stub_response(with_conv_index_params)
|
|
|
|
|
|
|
|
expect { subject.execute }
|
|
|
|
.to change { ConversationalDevelopmentIndex::Metric.count }
|
|
|
|
.by(1)
|
|
|
|
|
|
|
|
expect(ConversationalDevelopmentIndex::Metric.last.leader_issues).to eq 10.2
|
2017-08-01 02:46:43 -04:00
|
|
|
expect(ConversationalDevelopmentIndex::Metric.last.instance_issues).to eq 3.2
|
|
|
|
expect(ConversationalDevelopmentIndex::Metric.last.percentage_issues).to eq 31.37
|
2017-05-24 06:25:44 -04:00
|
|
|
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,
|
2017-08-01 02:46:43 -04:00
|
|
|
percentage_issues: 31.37,
|
2017-05-24 06:25:44 -04:00
|
|
|
|
|
|
|
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,
|
2017-08-01 02:46:43 -04:00
|
|
|
instance_service_desk_issues: 15.1,
|
|
|
|
|
|
|
|
non_existing_column: 'value'
|
2017-05-24 06:25:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_response(body)
|
2019-04-21 06:03:26 -04:00
|
|
|
stub_full_request('https://version.gitlab.com/usage_data', method: :post)
|
2017-06-21 09:48:12 -04:00
|
|
|
.to_return(
|
2017-05-24 06:25:44 -04:00
|
|
|
headers: { 'Content-Type' => 'application/json' },
|
|
|
|
body: body.to_json
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|