Commit d26d90bd authored by Stan Hu's avatar Stan Hu

Merge branch 'requirements-track2' into 'master'

Add test reports to usage ping

See merge request gitlab-org/gitlab!47809
parents 0072a1e3 c97ff908
......@@ -13,6 +13,8 @@ module RequirementsManagement
enum state: { passed: 1, failed: 2 }
scope :without_build, -> { where(build_id: nil) }
scope :with_build, -> { where.not(build_id: nil) }
scope :for_user_build, ->(user_id, build_id) { where(author_id: user_id, build_id: build_id) }
class << self
......
---
title: Added usage ping statistics about created requirement test reports
merge_request: 47809
author:
type: added
......@@ -105,7 +105,10 @@ module EE
return {} unless ::License.feature_available?(:requirements)
{
requirements_created: count(RequirementsManagement::Requirement)
requirements_created: count(RequirementsManagement::Requirement),
requirement_test_reports_manual: count(RequirementsManagement::TestReport.without_build),
requirement_test_reports_ci: count(RequirementsManagement::TestReport.with_build),
requirements_with_test_report: distinct_count(RequirementsManagement::TestReport, :requirement_id)
}
end
......
......@@ -189,6 +189,13 @@ RSpec.describe Gitlab::UsageData do
describe '.requirements_counts' do
subject { described_class.requirements_counts }
let_it_be(:requirement1) { create(:requirement) }
let_it_be(:requirement2) { create(:requirement) }
let_it_be(:requirement3) { create(:requirement) }
let_it_be(:test_report1) { create(:test_report, requirement: requirement1) }
let_it_be(:test_report2) { create(:test_report, requirement: requirement2, build: nil) }
let_it_be(:test_report3) { create(:test_report, requirement: requirement1) }
context 'when requirements are disabled' do
it 'returns empty hash' do
stub_licensed_features(requirements: false)
......@@ -201,9 +208,12 @@ RSpec.describe Gitlab::UsageData do
it 'returns created requirements count' do
stub_licensed_features(requirements: true)
create_list(:requirement, 2)
expect(subject).to eq({ requirements_created: 2 })
expect(subject).to eq({
requirements_created: 3,
requirement_test_reports_manual: 1,
requirement_test_reports_ci: 2,
requirements_with_test_report: 2
})
end
end
end
......
......@@ -19,17 +19,30 @@ RSpec.describe RequirementsManagement::TestReport do
end
describe 'scopes' do
describe 'for_user_build' do
it "returns only test reports matching build's user and pipeline" do
user = create(:user)
build = create(:ci_build)
report1 = create(:test_report, author: user, build: build)
create(:test_report, author: user)
create(:test_report, build: build)
let_it_be(:user) { create(:user) }
let_it_be(:build) { create(:ci_build) }
let_it_be(:report1) { create(:test_report, author: user, build: build) }
let_it_be(:report2) { create(:test_report, author: user) }
let_it_be(:report3) { create(:test_report, build: build) }
let_it_be(:report4) { create(:test_report, build: nil) }
describe '.for_user_build' do
it "returns only test reports matching build's user and pipeline" do
expect(described_class.for_user_build(user.id, build.id)).to match_array([report1])
end
end
describe '.with_build' do
it 'returns only test reports which reference a CI build' do
expect(described_class.with_build).to match_array([report1, report2, report3])
end
end
describe '.without_build' do
it 'returns only test reports which do not refer any CI build' do
expect(described_class.without_build).to match_array([report4])
end
end
end
describe '.persist_requirement_reports' do
......
......@@ -52,3 +52,4 @@ UsageData/DistinctCountByLargeForeignKey:
- 'project_id'
- 'user_id'
- 'resource_owner_id'
- 'requirement_id'
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