Commit 077b9a1d authored by Sean Arnold's avatar Sean Arnold

Add oncall_users to oncall schedule Graphql type

Changelog: added
EE: true
parent 083556f8
...@@ -10161,6 +10161,7 @@ Describes an incident management on-call schedule. ...@@ -10161,6 +10161,7 @@ Describes an incident management on-call schedule.
| <a id="incidentmanagementoncallscheduledescription"></a>`description` | [`String`](#string) | Description of the 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="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="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="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. | | <a id="incidentmanagementoncallscheduletimezone"></a>`timezone` | [`String!`](#string) | Time zone of the on-call schedule. |
......
# frozen_string_literal: true
module Resolvers
module IncidentManagement
class OncallUsersResolver < BaseResolver
alias_method :schedule, :object
type [::Types::UserType], null: true
def resolve
::IncidentManagement::OncallUsersFinder.new(schedule.project, schedule: schedule).execute
end
end
end
end
...@@ -38,6 +38,11 @@ module Types ...@@ -38,6 +38,11 @@ module Types
null: true, null: true,
description: 'On-call rotation for the on-call schedule.', description: 'On-call rotation for the on-call schedule.',
resolver: ::Resolvers::IncidentManagement::OncallRotationsResolver.single resolver: ::Resolvers::IncidentManagement::OncallRotationsResolver.single
field :oncall_users,
[::Types::UserType],
null: false,
resolver: ::Resolvers::IncidentManagement::OncallUsersResolver
end end
end 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
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 ...@@ -15,6 +15,7 @@ RSpec.describe GitlabSchema.types['IncidentManagementOncallSchedule'] do
timezone timezone
rotations rotations
rotation rotation
oncallUsers
] ]
expect(described_class).to have_graphql_fields(*expected_fields) 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