Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
da8b6c25
Commit
da8b6c25
authored
Dec 16, 2020
by
Sean Arnold
Committed by
syasonik
Jan 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add read service and specs
Adjust factory
parent
326e793d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
0 deletions
+140
-0
ee/app/services/incident_management/oncall_shifts/read_service.rb
...ervices/incident_management/oncall_shifts/read_service.rb
+58
-0
ee/spec/factories/incident_management/oncall_rotations.rb
ee/spec/factories/incident_management/oncall_rotations.rb
+8
-0
ee/spec/services/incident_management/oncall_shifts/read_service_spec.rb
...es/incident_management/oncall_shifts/read_service_spec.rb
+74
-0
No files found.
ee/app/services/incident_management/oncall_shifts/read_service.rb
0 → 100644
View file @
da8b6c25
# frozen_string_literal: true
module
IncidentManagement
module
OncallShifts
class
ReadService
# @param rotation [IncidentManagement::OncallRotation]
# @param current_user [User]
# @param params [Hash<Symbol,Any>]
# @option params - starts_at [Time]
# @option params - ends_at [Time]
def
initialize
(
rotation
,
current_user
,
starts_at
:,
ends_at
:)
@rotation
=
rotation
@current_user
=
current_user
@starts_at
=
starts_at
@ends_at
=
ends_at
end
def
execute
return
error_no_license
unless
available?
return
error_no_permissions
unless
allowed?
success
(
::
IncidentManagement
::
OncallShiftGenerator
.
new
(
rotation
)
.
for_timeframe
(
starts_at:
starts_at
,
ends_at:
ends_at
)
)
end
private
attr_reader
:rotation
,
:current_user
,
:starts_at
,
:ends_at
def
available?
::
Gitlab
::
IncidentManagement
.
oncall_schedules_available?
(
rotation
.
project
)
end
def
allowed?
Ability
.
allowed?
(
current_user
,
:read_incident_management_oncall_schedule
,
rotation
)
end
def
error
(
message
)
ServiceResponse
.
error
(
message:
message
)
end
def
success
(
shifts
)
ServiceResponse
.
success
(
payload:
{
shifts:
shifts
})
end
def
error_no_permissions
error
(
_
(
'You have insufficient permissions to view shifts for this rotation'
))
end
def
error_no_license
error
(
_
(
'Your license does not support on-call rotations'
))
end
end
end
end
ee/spec/factories/incident_management/oncall_rotations.rb
View file @
da8b6c25
...
@@ -7,5 +7,13 @@ FactoryBot.define do
...
@@ -7,5 +7,13 @@ FactoryBot.define do
starts_at
{
Time
.
current
}
starts_at
{
Time
.
current
}
length
{
5
}
length
{
5
}
length_unit
{
:days
}
length_unit
{
:days
}
trait
:with_participant
do
after
(
:create
)
do
|
rotation
|
user
=
create
(
:user
)
rotation
.
project
.
add_reporter
(
user
)
create
(
:incident_management_oncall_participant
,
rotation:
rotation
,
user:
user
)
end
end
end
end
end
end
ee/spec/services/incident_management/oncall_shifts/read_service_spec.rb
0 → 100644
View file @
da8b6c25
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
::
IncidentManagement
::
OncallShifts
::
ReadService
do
let_it_be_with_refind
(
:rotation
)
{
create
(
:incident_management_oncall_rotation
,
:with_participant
)
}
let_it_be
(
:project
)
{
rotation
.
project
}
let_it_be
(
:user_with_permissions
)
{
create
(
:user
)
}
let_it_be
(
:user_without_permissions
)
{
create
(
:user
)
}
let_it_be
(
:current_user
)
{
user_with_permissions
}
let
(
:params
)
{
{
starts_at:
rotation
.
starts_at
+
15
.
minutes
,
ends_at:
rotation
.
starts_at
+
3
.
weeks
}
}
let
(
:service
)
{
described_class
.
new
(
rotation
,
current_user
,
params
)
}
before_all
do
project
.
add_reporter
(
user_with_permissions
)
end
before
do
stub_licensed_features
(
oncall_schedules:
true
)
end
describe
'#execute'
do
shared_examples
'error response'
do
|
message
|
it
'has an informative message'
do
expect
(
execute
).
to
be_error
expect
(
execute
.
message
).
to
eq
(
message
)
end
end
subject
(
:execute
)
{
service
.
execute
}
context
'when the current_user is anonymous'
do
let
(
:current_user
)
{
nil
}
it_behaves_like
'error response'
,
'You have insufficient permissions to view shifts for this rotation'
end
context
'when the current_user does not have permissions to create on-call schedules'
do
let
(
:current_user
)
{
user_without_permissions
}
it_behaves_like
'error response'
,
'You have insufficient permissions to view shifts for this rotation'
end
context
'when feature is not available'
do
before
do
stub_licensed_features
(
oncall_schedules:
false
)
end
it_behaves_like
'error response'
,
'Your license does not support on-call rotations'
end
context
'when feature flag is disabled'
do
before
do
stub_feature_flags
(
oncall_schedules_mvc:
false
)
end
it_behaves_like
'error response'
,
'Your license does not support on-call rotations'
end
context
'with valid params'
do
it
'successfully returns a sorted collection of IncidentManagement::OncallShifts'
do
expect
(
execute
).
to
be_success
shifts
=
execute
.
payload
[
:shifts
]
expect
(
shifts
).
to
all
(
be_a
(
::
IncidentManagement
::
OncallShift
)
)
expect
(
shifts
).
to
all
(
be_valid
)
expect
(
shifts
.
sort_by
(
&
:starts_at
)).
to
eq
(
shifts
)
expect
(
shifts
.
first
.
starts_at
).
to
be
<=
params
[
:starts_at
]
expect
(
shifts
.
last
.
ends_at
).
to
be
>=
params
[
:ends_at
]
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment