2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe Ci::DailyBuildGroupReportResultsFinder do
|
2020-05-24 23:13:21 +05:30
|
|
|
describe '#execute' do
|
2021-02-22 17:27:13 +05:30
|
|
|
let_it_be(:project) { create(:project, :private) }
|
|
|
|
let_it_be(:current_user) { project.owner }
|
|
|
|
let_it_be(:ref_path) { 'refs/heads/master' }
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:limit) { nil }
|
2021-02-22 17:27:13 +05:30
|
|
|
let_it_be(:default_branch) { false }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
let_it_be(:rspec_coverage_1) { create_daily_coverage('rspec', 79.0, '2020-03-09') }
|
|
|
|
let_it_be(:karma_coverage_1) { create_daily_coverage('karma', 89.0, '2020-03-09') }
|
|
|
|
let_it_be(:rspec_coverage_2) { create_daily_coverage('rspec', 95.0, '2020-03-10') }
|
|
|
|
let_it_be(:karma_coverage_2) { create_daily_coverage('karma', 92.0, '2020-03-10') }
|
|
|
|
let_it_be(:rspec_coverage_3) { create_daily_coverage('rspec', 97.0, '2020-03-11') }
|
|
|
|
let_it_be(:karma_coverage_3) { create_daily_coverage('karma', 99.0, '2020-03-11') }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:attributes) do
|
|
|
|
{
|
2020-05-24 23:13:21 +05:30
|
|
|
current_user: current_user,
|
|
|
|
project: project,
|
|
|
|
ref_path: ref_path,
|
|
|
|
start_date: '2020-03-09',
|
|
|
|
end_date: '2020-03-10',
|
|
|
|
limit: limit
|
2021-02-22 17:27:13 +05:30
|
|
|
}
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
subject(:coverages) do
|
|
|
|
described_class.new(**attributes).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when ref_path is present' do
|
|
|
|
context 'when current user is allowed to read build report results' do
|
|
|
|
it 'returns all matching results within the given date range' do
|
|
|
|
expect(coverages).to match_array([
|
|
|
|
karma_coverage_2,
|
|
|
|
rspec_coverage_2,
|
|
|
|
karma_coverage_1,
|
|
|
|
rspec_coverage_1
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and limit is specified' do
|
|
|
|
let(:limit) { 2 }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'returns limited number of matching results within the given date range' do
|
|
|
|
expect(coverages).to match_array([
|
|
|
|
karma_coverage_2,
|
|
|
|
rspec_coverage_2
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
context 'when current user is not allowed to read build report results' do
|
|
|
|
let(:current_user) { create(:user) }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'returns an empty result' do
|
|
|
|
expect(coverages).to be_empty
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'when ref_path query parameter is not present' do
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:ref_path) { nil }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'when records with cover data from the default branch exist' do
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:default_branch) { true }
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it 'returns records with default_branch:true, irrespective of ref_path' do
|
2021-02-22 17:27:13 +05:30
|
|
|
rspec_coverage_4 = create_daily_coverage('rspec', 66.0, '2020-03-10')
|
|
|
|
|
|
|
|
expect(coverages).to contain_exactly(rspec_coverage_4)
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
private
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
def create_daily_coverage(group_name, coverage, date)
|
|
|
|
create(
|
|
|
|
:ci_daily_build_group_report_result,
|
|
|
|
project: project,
|
2021-02-22 17:27:13 +05:30
|
|
|
ref_path: ref_path || 'feature-branch',
|
2020-06-23 00:09:42 +05:30
|
|
|
group_name: group_name,
|
|
|
|
data: { 'coverage' => coverage },
|
2021-02-22 17:27:13 +05:30
|
|
|
date: date,
|
|
|
|
default_branch: default_branch
|
2020-06-23 00:09:42 +05:30
|
|
|
)
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|