Commit e5699a3f authored by Eulyeon Ko's avatar Eulyeon Ko Committed by Bob Van Landuyt

Allow iteration to be created without cadence

After turning off iteration_cadences FF,
creating a new iteration should be possible.

1. The mutation resolver for creating an iteration
is updated to accept a request even if there are
mulitple cadences when iteration_cadeces FF is off.

2. Iteration model is updated so that the first cadence
is used as the default cadence for each group when
creating a new iteration

EE: true
Changelog: fixed

Apply 4 suggestion(s) to 1 file(s)

Fix indentation on set_cadence method
parent b1088a03
......@@ -68,7 +68,7 @@ module Mutations
# Once we introduce cadence CRUD support we need to specify to which iteration cadence a given iteration
# belongs if there are more than once cadence in the group. Eventually `iterations_cadence_id` argument should
# become required and there should be no need for group_path argument for iteration.
if args[:iterations_cadence].blank? && parent.iterations_cadences.count > 1
if args[:iterations_cadence].blank? && parent.iterations_cadences.count > 1 && parent.iteration_cadences_feature_flag_enabled?
raise Gitlab::Graphql::Errors::ArgumentError, 'Please provide iterations_cadence_id argument to assign iteration to respective cadence'
end
end
......
......@@ -311,7 +311,7 @@ module EE
# set to 0, i.e. unspecified when creating default iterations as we do validate for presence.
iterations_in_advance: 0,
duration_in_weeks: 0
).safe_find_or_create_by!(group: group)
).order(id: :asc).safe_find_or_create_by!(group: group)
end
# TODO: remove this as part of https://gitlab.com/gitlab-org/gitlab/-/issues/296100
......
......@@ -87,6 +87,22 @@ RSpec.describe 'Creating an Iteration' do
it_behaves_like 'a mutation that returns top-level errors',
errors: ['Please provide iterations_cadence_id argument to assign iteration to respective cadence']
context 'when iteration_cadences FF is disabled' do
before do
stub_feature_flags(iteration_cadences: false)
end
it 'creates a new iteration in the default cadence' do
post_graphql_mutation(mutation, current_user: current_user)
iteration_hash = mutation_response['iteration']
aggregate_failures do
expect(iteration_hash['title']).to eq('title')
expect(iteration_hash['iterationCadence']['id']).to eq(group.iterations_cadences.first.to_global_id.to_s)
end
end
end
end
end
......
......@@ -110,38 +110,65 @@ RSpec.describe Iterations::CreateService do
it_behaves_like 'iterations create service'
end
context 'group with multiple cadences' do
let_it_be(:cadence) { create_list(:iterations_cadence, 2, group: group) }
context 'group with multiple cadences', :aggregate_failures do
let_it_be(:parent, refind: true) { group }
let(:base_params) do
{
title: 'v2.1.9',
description: 'Patch release to fix security issue',
start_date: Time.current.to_s,
due_date: 1.day.from_now.to_s
}
end
let(:response) { described_class.new(parent, user, params).execute }
let(:saved_iteration) { response.payload[:iteration] }
it_behaves_like 'iterations create service'
context 'with specific cadence being passed as param' do
let_it_be(:user) { create(:user) }
let_it_be(:cadences) { create_list(:iterations_cadence, 2, group: group) }
let(:params) do
{
title: 'v2.1.9',
description: 'Patch release to fix security issue',
start_date: Time.current.to_s,
due_date: 1.day.from_now.to_s,
iterations_cadence_id: group.iterations_cadences.last.id
}
let(:params) { base_params.merge(iterations_cadence_id: cadences.last.id) }
before do
parent.add_developer(user)
end
let(:response) { described_class.new(parent, user, params).execute }
let(:iteration) { response.payload[:iteration] }
it 'creates an iteration' do
expect(response).to be_success
expect(saved_iteration).to be_persisted
expect(saved_iteration.iterations_cadence_id).to eq(cadences.last.id)
end
end
context 'when iteration_cadences FF is disabled' do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:cadences) { create_list(:iterations_cadence, 2, group: group) }
let_it_be(:other_iteration) { create(:iteration, iterations_cadence: cadences.second) }
let_it_be(:parent, refind: true) { group }
let(:params) { base_params }
let(:ordered_cadences) { group.iterations_cadences.order(id: :asc) }
before do
stub_feature_flags(iteration_cadences: false)
parent.add_developer(user)
end
context 'valid params' do
it 'creates an iteration' do
expect(response.success?).to be_truthy
expect(iteration).to be_persisted
expect(iteration.iterations_cadence_id).to eq(group.iterations_cadences.last.id)
end
it 'creates an iteration in the default (first) cadence' do
expect(response).to be_success
expect(saved_iteration).to be_persisted
expect(saved_iteration.title).to eq('v2.1.9')
expect(saved_iteration.iterations_cadence_id).to eq(ordered_cadences.first.id)
end
it 'does not update the iterations from the non-default cadences' do
expect(response).to be_success
expect(other_iteration.iterations_cadence_id).to eq(ordered_cadences.second.id)
end
end
end
......
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