2021-02-22 17:27:13 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Resolvers::ProjectPipelineStatisticsResolver do
|
|
|
|
include GraphqlHelpers
|
|
|
|
|
2021-08-04 16:29:09 +05:30
|
|
|
let_it_be(:project) { create(:project, :private) }
|
|
|
|
let_it_be(:guest) { create(:user) }
|
|
|
|
let_it_be(:reporter) { create(:user) }
|
|
|
|
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
2022-04-01 21:47:47 +05:30
|
|
|
before do
|
2021-08-04 16:29:09 +05:30
|
|
|
project.add_guest(guest)
|
|
|
|
project.add_reporter(reporter)
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(described_class).to have_nullable_graphql_type(::Types::Ci::AnalyticsType)
|
|
|
|
end
|
|
|
|
|
2022-04-01 21:47:47 +05:30
|
|
|
shared_examples 'returns the pipelines statistics for a given project' do
|
|
|
|
it do
|
2021-02-22 17:27:13 +05:30
|
|
|
result = resolve_statistics(project, {})
|
|
|
|
expect(result.keys).to contain_exactly(
|
|
|
|
:week_pipelines_labels,
|
|
|
|
:week_pipelines_totals,
|
|
|
|
:week_pipelines_successful,
|
|
|
|
:month_pipelines_labels,
|
|
|
|
:month_pipelines_totals,
|
|
|
|
:month_pipelines_successful,
|
|
|
|
:year_pipelines_labels,
|
|
|
|
:year_pipelines_totals,
|
|
|
|
:year_pipelines_successful,
|
|
|
|
:pipeline_times_labels,
|
|
|
|
:pipeline_times_values
|
|
|
|
)
|
|
|
|
end
|
2022-04-01 21:47:47 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'it returns nils' do
|
|
|
|
it do
|
|
|
|
result = resolve_statistics(project, {})
|
|
|
|
|
|
|
|
expect(result).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolve_statistics(project, args)
|
|
|
|
ctx = { current_user: current_user }
|
|
|
|
resolve(described_class, obj: project, args: args, ctx: ctx)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#resolve' do
|
|
|
|
it_behaves_like 'returns the pipelines statistics for a given project'
|
2021-08-04 16:29:09 +05:30
|
|
|
|
|
|
|
context 'when the user does not have access to the CI/CD analytics data' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
2022-04-01 21:47:47 +05:30
|
|
|
it_behaves_like 'it returns nils'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project is public' do
|
|
|
|
let_it_be(:project) { create(:project, :public) }
|
|
|
|
|
|
|
|
context 'public pipelines are disabled' do
|
|
|
|
before do
|
|
|
|
project.update!(public_builds: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user is not a member' do
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
|
|
|
|
it_behaves_like 'it returns nils'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user is a guest' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it_behaves_like 'it returns nils'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user is a reporter or above' do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
it_behaves_like 'returns the pipelines statistics for a given project'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'public pipelines are enabled' do
|
|
|
|
before do
|
|
|
|
project.update!(public_builds: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user is not a member' do
|
|
|
|
let(:current_user) { create(:user) }
|
2021-08-04 16:29:09 +05:30
|
|
|
|
2022-04-01 21:47:47 +05:30
|
|
|
it_behaves_like 'returns the pipelines statistics for a given project'
|
|
|
|
end
|
2021-08-04 16:29:09 +05:30
|
|
|
end
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
end
|
|
|
|
end
|