debian-mirror-gitlab/spec/requests/api/group_milestones_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

131 lines
4.1 KiB
Ruby
Raw Permalink Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe API::GroupMilestones, feature_category: :team_planning do
2020-10-24 23:57:45 +05:30
let_it_be(:user) { create(:user) }
2023-05-27 22:25:52 +05:30
let_it_be_with_refind(:group) { create(:group, :private) }
2020-10-24 23:57:45 +05:30
let_it_be(:project) { create(:project, namespace: group) }
let_it_be(:group_member) { create(:group_member, group: group, user: user) }
2023-05-27 22:25:52 +05:30
let_it_be(:closed_milestone) do
create(:closed_milestone, group: group, title: 'version1', description: 'closed milestone')
end
let_it_be_with_reload(:milestone) do
create(:milestone, group: group, title: 'version2', description: 'open milestone', updated_at: 4.days.ago)
end
2021-09-30 23:02:18 +05:30
2020-10-24 23:57:45 +05:30
let(:route) { "/groups/#{group.id}/milestones" }
2023-05-27 22:25:52 +05:30
shared_examples 'listing all milestones' do
it 'returns correct list of milestones' do
get api(route, user), params: params
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to eq(milestones.size)
expect(json_response.map { |entry| entry["id"] }).to eq(milestones.map(&:id))
end
end
2020-10-24 23:57:45 +05:30
it_behaves_like 'group and project milestones', "/groups/:id/milestones"
describe 'GET /groups/:id/milestones' do
2023-05-27 22:25:52 +05:30
let_it_be(:ancestor_group) { create(:group, :private) }
let_it_be(:ancestor_group_milestone) { create(:milestone, group: ancestor_group, updated_at: 2.days.ago) }
2020-10-24 23:57:45 +05:30
2023-05-27 22:25:52 +05:30
before_all do
group.update!(parent: ancestor_group)
end
2020-10-24 23:57:45 +05:30
2023-05-27 22:25:52 +05:30
context 'when include_parent_milestones is true' do
let(:params) { { include_parent_milestones: true } }
2020-10-24 23:57:45 +05:30
context 'when user has access to ancestor groups' do
let(:milestones) { [ancestor_group_milestone, milestone, closed_milestone] }
before do
ancestor_group.add_guest(user)
group.add_guest(user)
end
it_behaves_like 'listing all milestones'
context 'when iids param is present' do
2023-05-27 22:25:52 +05:30
let(:params) { { include_parent_milestones: true, iids: [milestone.iid] } }
2020-10-24 23:57:45 +05:30
it_behaves_like 'listing all milestones'
end
2023-05-27 22:25:52 +05:30
context 'when updated_before param is present' do
let(:params) { { updated_before: 1.day.ago.iso8601, include_parent_milestones: true } }
it_behaves_like 'listing all milestones' do
let(:milestones) { [ancestor_group_milestone, milestone] }
end
end
context 'when updated_after param is present' do
let(:params) { { updated_after: 1.day.ago.iso8601, include_parent_milestones: true } }
it_behaves_like 'listing all milestones' do
let(:milestones) { [closed_milestone] }
end
end
2020-10-24 23:57:45 +05:30
end
context 'when user has no access to ancestor groups' do
let(:user) { create(:user) }
before do
group.add_guest(user)
end
it_behaves_like 'listing all milestones' do
let(:milestones) { [milestone, closed_milestone] }
end
end
end
2023-05-27 22:25:52 +05:30
context 'when updated_before param is present' do
let(:params) { { updated_before: 1.day.ago.iso8601 } }
it_behaves_like 'listing all milestones' do
let(:milestones) { [milestone] }
end
end
context 'when updated_after param is present' do
let(:params) { { updated_after: 1.day.ago.iso8601 } }
it_behaves_like 'listing all milestones' do
let(:milestones) { [closed_milestone] }
end
end
2017-09-10 17:25:29 +05:30
end
2021-04-29 21:17:54 +05:30
describe 'GET /groups/:id/milestones/:milestone_id/issues' do
let!(:issue) { create(:issue, project: project, milestone: milestone) }
def perform_request
get api("/groups/#{group.id}/milestones/#{milestone.id}/issues", user)
end
it 'returns multiple issues without performing N + 1' do
perform_request
control_count = ActiveRecord::QueryRecorder.new { perform_request }.count
create(:issue, project: project, milestone: milestone)
expect { perform_request }.not_to exceed_query_limit(control_count)
end
end
2017-09-10 17:25:29 +05:30
def setup_for_group
2021-04-29 21:17:54 +05:30
context_group.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
2022-07-16 23:28:13 +05:30
context_group.add_reporter(user)
2021-04-29 21:17:54 +05:30
public_project.update!(namespace: context_group)
2017-09-10 17:25:29 +05:30
context_group.reload
end
end