Commit 279cb5d7 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Add a IncidentManagement::OncallScheduleResolver

Add a GraphQL resolver for on-call schedules
parent af318c1b
......@@ -151,7 +151,8 @@ module EE
field :incident_management_oncall_schedules,
::Types::IncidentManagement::OncallScheduleType.connection_type,
null: true,
description: 'Incident Management On-call schedules of the project'
description: 'Incident Management On-call schedules of the project',
resolver: ::Resolvers::IncidentManagement::OncallScheduleResolver
def self.sast_ci_configuration(project)
::Security::CiConfiguration::SastParserService.new(project).configuration
......
# frozen_string_literal: true
module Resolvers
module IncidentManagement
class OncallScheduleResolver < BaseResolver
alias_method :project, :synchronized_object
type Types::IncidentManagement::OncallScheduleType.connection_type, null: true
def resolve(**args)
return [] unless Ability.allowed?(current_user, :read_incident_management_oncall_schedule, project)
project.incident_management_oncall_schedules
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::IncidentManagement::OncallScheduleResolver do
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:oncall_schedule) { create(:incident_management_oncall_schedule, project: project) }
subject { sync(resolve_oncall_schedules) }
specify do
expect(described_class).to have_nullable_graphql_type(Types::IncidentManagement::OncallScheduleType.connection_type)
end
context 'user does not have permissions' do
it { is_expected.to eq(IncidentManagement::OncallSchedule.none) }
end
context 'user has permissions' do
before do
project.add_maintainer(current_user)
end
it { is_expected.to contain_exactly(oncall_schedule) }
# TODO: check feature flag
# TODO: check license "Premium"
end
private
def resolve_oncall_schedules(args = {}, context = { current_user: current_user })
resolve(described_class, obj: project, args: args, ctx: context)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'getting Incident Management on-call schedules' do
include GraphqlHelpers
let_it_be(:project) { create(:project) }
let_it_be(:current_user) { create(:user) }
let(:params) { {} }
let(:fields) do
<<~QUERY
nodes {
#{all_graphql_fields_for('IncidentManagementOncallSchedule')}
}
QUERY
end
let(:query) do
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
query_graphql_field('incidentManagementOncallSchedules', {}, fields)
)
end
let(:oncall_schedules) { graphql_data.dig('project', 'incidentManagementOncallSchedules', 'nodes') }
context 'without project permissions' do
let(:user) { create(:user) }
before do
post_graphql(query, current_user: current_user)
end
it_behaves_like 'a working graphql query'
it { expect(oncall_schedules).to be_nil }
end
context 'with project permissions' do
before do
project.add_maintainer(current_user)
end
context 'without on-call schedules' do
before do
post_graphql(query, current_user: current_user)
end
it_behaves_like 'a working graphql query'
it { expect(oncall_schedules).to be_empty }
end
context 'with on-call schedules' do
let!(:oncall_schedule) { create(:incident_management_oncall_schedule, project: project) }
let(:last_oncall_schedule) { oncall_schedules.last }
before do
post_graphql(query, current_user: current_user)
end
it_behaves_like 'a working graphql query'
it 'returns the correct properties of the on-call schedule' do
expect(last_oncall_schedule).to include(
'iid' => oncall_schedule.iid.to_s,
'name' => oncall_schedule.name,
'description' => oncall_schedule.description,
'timezone' => oncall_schedule.timezone
)
end
end
end
end
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