Commit c493eb0e authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'sarnold-324421-add-singular-rotation-resolver' into 'master'

Add singular resolver for oncall rotations

See merge request gitlab-org/gitlab!58729
parents 9b685113 700b14af
......@@ -3333,6 +3333,7 @@ Describes an incident management on-call schedule.
| `description` | [`String`](#string) | Description of the on-call schedule. |
| `iid` | [`ID!`](#id) | Internal ID of the on-call schedule. |
| `name` | [`String!`](#string) | Name of the on-call schedule. |
| `rotation` | [`IncidentManagementOncallRotation`](#incidentmanagementoncallrotation) | On-call rotation for the on-call schedule. |
| `rotations` | [`IncidentManagementOncallRotationConnection!`](#incidentmanagementoncallrotationconnection) | On-call rotations for the on-call schedule. |
| `timezone` | [`String!`](#string) | Time zone of the on-call schedule. |
......
# frozen_string_literal: true
module Resolvers
module IncidentManagement
class OncallRotationsResolver < BaseResolver
alias_method :schedule, :object
type Types::IncidentManagement::OncallRotationType.connection_type, null: true
when_single do
argument :id,
::Types::GlobalIDType[::IncidentManagement::OncallRotation],
required: true,
description: 'ID of the on-call rotation.',
prepare: ->(id, ctx) { id.model_id }
end
def resolve(**args)
::IncidentManagement::OncallRotationsFinder.new(context[:current_user], schedule.project, schedule, args).execute
end
end
end
end
......@@ -32,6 +32,12 @@ module Types
OncallRotationType.connection_type,
null: false,
description: 'On-call rotations for the on-call schedule.'
field :rotation,
OncallRotationType,
null: true,
description: 'On-call rotation for the on-call schedule.',
resolver: ::Resolvers::IncidentManagement::OncallRotationsResolver.single
end
end
end
---
title: Add singular oncall rotation field to oncall schedules type
merge_request: 58729
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::IncidentManagement::OncallRotationsResolver do
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
let_it_be(:rotation) { create(:incident_management_oncall_rotation, :with_participants, :utc) }
let_it_be(:second_rotation) { create(:incident_management_oncall_rotation, :with_participants, :utc, schedule: rotation.schedule) }
let_it_be(:schedule) { rotation.schedule }
let_it_be(:project) { rotation.project }
let(:args) { {} }
let(:resolver) { described_class }
subject(:resolved_rotations) { sync(resolve_oncall_rotations(args, current_user: current_user).to_a) }
before do
stub_licensed_features(oncall_schedules: true)
project.add_reporter(current_user)
end
specify do
expect(described_class).to have_nullable_graphql_type(Types::IncidentManagement::OncallRotationType.connection_type)
end
it 'returns on-call rotations' do
expect(resolved_rotations.length).to eq(2)
expect(resolved_rotations.first).to be_a(::IncidentManagement::OncallRotation)
expect(resolved_rotations.first).to have_attributes(id: second_rotation.id)
expect(resolved_rotations.last).to have_attributes(id: rotation.id)
end
context 'when user does not have permissions' do
let(:another_user) { create(:user) }
subject(:resolved_rotations) { sync(resolve_oncall_rotations(args, current_user: another_user).to_a) }
it 'returns no rotations' do
expect(resolved_rotations.length).to eq(0)
end
end
context 'when resolving a single item' do
let(:resolver) { described_class.single }
subject(:resolved_rotation) { sync(resolve_oncall_rotations(args, current_user: current_user)) }
context 'when id given' do
let(:args) { { id: rotation.to_global_id } }
it 'returns the on-call rotation' do
expect(resolved_rotation).to eq(rotation)
end
end
end
private
def resolve_oncall_rotations(args = {}, context = { current_user: current_user })
resolve(resolver, obj: schedule, args: args, ctx: context)
end
end
......@@ -14,6 +14,7 @@ RSpec.describe GitlabSchema.types['IncidentManagementOncallSchedule'] do
description
timezone
rotations
rotation
]
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