2020-05-15 06:08:40 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe Ci::DailyBuildGroupReportResultsFinder do
|
2020-05-15 06:08:40 +00:00
|
|
|
describe '#execute' do
|
2020-12-15 00:10:07 +00:00
|
|
|
let_it_be(:project) { create(:project, :private) }
|
2021-02-23 18:10:40 +00:00
|
|
|
let(:user_without_permission) { create(:user) }
|
|
|
|
let_it_be(:user_with_permission) { project.owner }
|
2020-12-15 00:10:07 +00:00
|
|
|
let_it_be(:ref_path) { 'refs/heads/master' }
|
2020-05-15 06:08:40 +00:00
|
|
|
let(:limit) { nil }
|
2020-12-15 00:10:07 +00:00
|
|
|
let_it_be(:default_branch) { false }
|
2021-02-23 18:10:40 +00:00
|
|
|
let(:start_date) { '2020-03-09' }
|
|
|
|
let(:end_date) { '2020-03-10' }
|
|
|
|
let(:sort) { true }
|
2020-05-15 06:08:40 +00:00
|
|
|
|
2020-12-15 00:10:07 +00:00
|
|
|
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-15 06:08:40 +00:00
|
|
|
|
2021-02-23 18:10:40 +00:00
|
|
|
let(:finder) { described_class.new(params: params, current_user: current_user) }
|
|
|
|
|
|
|
|
let(:params) do
|
2020-12-15 00:10:07 +00:00
|
|
|
{
|
2020-05-15 06:08:40 +00:00
|
|
|
project: project,
|
2021-02-23 18:10:40 +00:00
|
|
|
coverage: true,
|
2020-05-15 06:08:40 +00:00
|
|
|
ref_path: ref_path,
|
2021-02-23 18:10:40 +00:00
|
|
|
start_date: start_date,
|
|
|
|
end_date: end_date,
|
|
|
|
limit: limit,
|
|
|
|
sort: sort
|
2020-12-15 00:10:07 +00:00
|
|
|
}
|
2020-05-15 06:08:40 +00:00
|
|
|
end
|
|
|
|
|
2021-02-23 18:10:40 +00:00
|
|
|
subject(:coverages) { finder.execute }
|
|
|
|
|
|
|
|
context 'when params are provided' do
|
|
|
|
context 'when current user is not allowed to read data' do
|
|
|
|
let(:current_user) { user_without_permission }
|
|
|
|
|
|
|
|
it 'returns an empty collection' do
|
|
|
|
expect(coverages).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2020-12-15 00:10:07 +00:00
|
|
|
|
2021-02-23 18:10:40 +00:00
|
|
|
context 'when current user is allowed to read data' do
|
|
|
|
let(:current_user) { user_with_permission }
|
|
|
|
|
|
|
|
it 'returns matching coverages within the given date range' do
|
2020-12-15 00:10:07 +00:00
|
|
|
expect(coverages).to match_array([
|
|
|
|
karma_coverage_2,
|
|
|
|
rspec_coverage_2,
|
|
|
|
karma_coverage_1,
|
|
|
|
rspec_coverage_1
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
2021-02-23 18:10:40 +00:00
|
|
|
context 'when ref_path is nil' do
|
|
|
|
let(:default_branch) { true }
|
|
|
|
let(:ref_path) { nil }
|
|
|
|
|
|
|
|
it 'returns coverages for the default branch' do
|
|
|
|
rspec_coverage_4 = create_daily_coverage('rspec', 66.0, '2020-03-10')
|
|
|
|
|
|
|
|
expect(coverages).to contain_exactly(rspec_coverage_4)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when limit is specified' do
|
2020-12-15 00:10:07 +00:00
|
|
|
let(:limit) { 2 }
|
2020-05-15 06:08:40 +00:00
|
|
|
|
2021-02-23 18:10:40 +00:00
|
|
|
it 'returns limited number of matching coverages within the given date range' do
|
2020-12-15 00:10:07 +00:00
|
|
|
expect(coverages).to match_array([
|
|
|
|
karma_coverage_2,
|
|
|
|
rspec_coverage_2
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
2021-02-25 18:11:05 +00:00
|
|
|
|
|
|
|
context 'when provided dates are nil' do
|
|
|
|
let(:start_date) { nil }
|
|
|
|
let(:end_date) { nil }
|
|
|
|
let(:rspec_coverage_4) { create_daily_coverage('rspec', 98.0, 91.days.ago.to_date.to_s) }
|
|
|
|
|
|
|
|
it 'returns all coverages from the last 90 days' do
|
|
|
|
expect(coverages).to match_array(
|
|
|
|
[
|
|
|
|
karma_coverage_3,
|
|
|
|
rspec_coverage_3,
|
|
|
|
karma_coverage_2,
|
|
|
|
rspec_coverage_2,
|
|
|
|
karma_coverage_1,
|
|
|
|
rspec_coverage_1
|
|
|
|
]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2020-05-15 06:08:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-05 15:08:23 +00:00
|
|
|
|
2020-08-06 21:10:15 +00:00
|
|
|
private
|
|
|
|
|
2020-06-05 15:08:23 +00:00
|
|
|
def create_daily_coverage(group_name, coverage, date)
|
|
|
|
create(
|
|
|
|
:ci_daily_build_group_report_result,
|
|
|
|
project: project,
|
2020-12-15 00:10:07 +00:00
|
|
|
ref_path: ref_path || 'feature-branch',
|
2020-06-05 15:08:23 +00:00
|
|
|
group_name: group_name,
|
|
|
|
data: { 'coverage' => coverage },
|
2020-12-15 00:10:07 +00:00
|
|
|
date: date,
|
|
|
|
default_branch: default_branch
|
2020-06-05 15:08:23 +00:00
|
|
|
)
|
|
|
|
end
|
2020-05-15 06:08:40 +00:00
|
|
|
end
|