Commit 5d54f74d authored by Sean Arnold's avatar Sean Arnold

Add URLs to oncall schedule entity

- Add specs for entity
parent a1f74822
......@@ -8,8 +8,9 @@ module EE
def preload_all
super
ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), group_saml_identities: :saml_provider)
ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), oncall_participants: { rotation: :schedule })
users = members.map(&:user)
ActiveRecord::Associations::Preloader.new.preload(users, group_saml_identities: :saml_provider)
ActiveRecord::Associations::Preloader.new.preload(users, oncall_participants: { rotation: :schedule })
end
end
end
......@@ -22,9 +22,7 @@ module IncidentManagement
scope :for_iid, -> (iid) { where(iid: iid) }
def project_name
project.name
end
delegate :name, to: :project, prefix: true
private
......
......@@ -2,7 +2,16 @@
module IncidentManagement
class OncallScheduleEntity < Grape::Entity
include Gitlab::Routing
expose :name
expose :project_name
expose :schedule_url do |schedule|
project_incident_management_oncall_schedules_url(schedule.project)
end
expose :project_url do |schedule|
project_url(schedule.project)
end
end
end
{
"type": "object",
"allOf": [
{ "$ref": "../../../../../../spec/fixtures/api/schemas/entities/member_user.json" },
{
"required" : [
"oncall_schedules"
],
"properties" : {
"oncall_schedules": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"project_name": { "type": "string" }
}
}
}
}
}
]
}
......@@ -28,6 +28,9 @@ RSpec.describe User do
it { is_expected.to have_many(:board_preferences) }
it { is_expected.to have_many(:boards_epic_user_preferences).class_name('Boards::EpicUserPreference') }
it { is_expected.to have_many(:user_permission_export_uploads) }
it { is_expected.to have_many(:oncall_participants).class_name('IncidentManagement::OncallParticipant') }
it { is_expected.to have_many(:oncall_rotations).class_name('IncidentManagement::OncallRotation').through(:oncall_participants) }
it { is_expected.to have_many(:oncall_schedules).class_name('IncidentManagement::OncallSchedule').through(:oncall_rotations) }
end
describe 'nested attributes' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::OncallScheduleEntity do
let(:schedule) { create(:incident_management_oncall_schedule) }
let(:schedule_url) { Gitlab::Routing.url_helpers.project_incident_management_oncall_schedules_url(schedule.project) }
let(:project_url) { Gitlab::Routing.url_helpers.project_url(schedule.project) }
subject { described_class.new(schedule) }
describe '.as_json' do
it 'includes oncall schdule attributes' do
attributes = subject.as_json
expect(attributes[:name]).to eq(schedule.name)
expect(attributes[:project_name]).to eq(schedule.project.name)
expect(attributes[:schedule_url]).to eq(schedule_url)
expect(attributes[:project_url]).to eq(project_url)
end
end
end
......@@ -18,6 +18,5 @@
},
"additionalProperties": false
}
},
"additionalProperties": false
}
}
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