Commit c075322e authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch '251140-add-oncall-users-to-schedule' into 'master'

Add oncall_users to oncall schedule Graphql type

See merge request gitlab-org/gitlab!68237
parents a6a7c422 838a90fe
......@@ -10199,6 +10199,7 @@ Describes an incident management on-call schedule.
| <a id="incidentmanagementoncallscheduledescription"></a>`description` | [`String`](#string) | Description of the on-call schedule. |
| <a id="incidentmanagementoncallscheduleiid"></a>`iid` | [`ID!`](#id) | Internal ID of the on-call schedule. |
| <a id="incidentmanagementoncallschedulename"></a>`name` | [`String!`](#string) | Name of the on-call schedule. |
| <a id="incidentmanagementoncallscheduleoncallusers"></a>`oncallUsers` | [`[UserCore!]`](#usercore) | |
| <a id="incidentmanagementoncallschedulerotations"></a>`rotations` | [`IncidentManagementOncallRotationConnection!`](#incidentmanagementoncallrotationconnection) | On-call rotations for the on-call schedule. (see [Connections](#connections)) |
| <a id="incidentmanagementoncallscheduletimezone"></a>`timezone` | [`String!`](#string) | Time zone of the on-call schedule. |
......
......@@ -18,6 +18,8 @@ module Resolvers
end
def resolve_with_lookahead(**args)
context[:execution_time] = Time.current
apply_lookahead(::IncidentManagement::EscalationPoliciesFinder.new(current_user, project, args).execute)
end
......
# frozen_string_literal: true
module Resolvers
module IncidentManagement
class OncallUsersResolver < BaseResolver
alias_method :schedule, :object
type [::Types::UserType], null: true
def resolve
oncall_at = context[:execution_time] || Time.current
::IncidentManagement::OncallUsersFinder.new(schedule.project, schedule: schedule, oncall_at: oncall_at).execute
end
end
end
end
......@@ -38,6 +38,11 @@ module Types
null: true,
description: 'On-call rotation for the on-call schedule.',
resolver: ::Resolvers::IncidentManagement::OncallRotationsResolver.single
field :oncall_users,
[::Types::UserType],
null: true,
resolver: ::Resolvers::IncidentManagement::OncallUsersResolver
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::IncidentManagement::OncallUsersResolver do
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
let_it_be(:schedule) { create(:incident_management_oncall_schedule, :with_rotation, :utc) }
let_it_be(:project) { schedule.project }
let(:args) { {} }
subject(:users) { sync(resolve_oncall_users(args)) }
before do
stub_licensed_features(oncall_schedules: true)
project.add_reporter(current_user)
end
it 'returns on-call users' do
expect(users.length).to eq(1)
expect(users.first).to be_a(::User)
expect(schedule.participants.pluck(:user_id)).to include(users.first.id)
end
it 'calls the finder with the execution_time context' do
execution_time = Time.current
context = { current_user: current_user, execution_time: execution_time }
expect(::IncidentManagement::OncallUsersFinder).to receive(:new)
.with(project, hash_including(oncall_at: execution_time))
.and_call_original
resolve_oncall_users({}, context)
end
context 'when an error occurs while finding shifts' do
before do
stub_licensed_features(oncall_schedules: false)
end
it 'returns no users' do
expect(subject).to eq(::User.none)
end
end
private
def resolve_oncall_users(args = {}, context = { current_user: current_user })
resolve(described_class, obj: schedule, args: args, ctx: context)
end
end
......@@ -15,6 +15,7 @@ RSpec.describe GitlabSchema.types['IncidentManagementOncallSchedule'] do
timezone
rotations
rotation
oncallUsers
]
expect(described_class).to have_graphql_fields(*expected_fields)
......
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