Commit dd136677 authored by Sean Arnold's avatar Sean Arnold Committed by Douglas Barbosa Alexandre

Add singular resolver for oncall rotations

- Move from using association directly to finder
- Add specs for new resolver
parent 2c00eada
......@@ -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
......@@ -31,7 +31,14 @@ module Types
field :rotations,
OncallRotationType.connection_type,
null: false,
description: 'On-call rotations for the on-call schedule.'
description: 'On-call rotations for the on-call schedule.',
resolver: ::Resolvers::IncidentManagement::OncallRotationsResolver
field :rotation,
OncallRotationType,
null: false,
description: 'On-call rotation for the on-call schedule.',
resolver: ::Resolvers::IncidentManagement::OncallRotationsResolver.single
end
end
end
# 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