Commit fcfee0cc authored by Terri Chu's avatar Terri Chu

Merge branch '323653-fix-update-board-update-cadence-id' into 'master'

Fix update/create board mutation for iteration_cadence_id param

See merge request gitlab-org/gitlab!84998
parents 5158681b 19737bc8
...@@ -47,6 +47,15 @@ module Mutations ...@@ -47,6 +47,15 @@ module Mutations
args[:milestone_id] = args[:milestone_id].model_id args[:milestone_id] = args[:milestone_id].model_id
end end
if args[:iteration_cadence_id]
# TODO: remove this line when the compatibility layer is removed
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
args[:iteration_cadence_id] = ::Types::GlobalIDType[::Iterations::Cadence].coerce_isolated_input(
args[:iteration_cadence_id]
)
args[:iteration_cadence_id] = args[:iteration_cadence_id].model_id
end
args[:label_ids] &&= args[:label_ids].map do |label_id| args[:label_ids] &&= args[:label_ids].map do |label_id|
::GitlabSchema.parse_gid(label_id, expected_type: ::Label).model_id ::GitlabSchema.parse_gid(label_id, expected_type: ::Label).model_id
end end
......
...@@ -9,6 +9,7 @@ RSpec.describe Mutations::Boards::Update do ...@@ -9,6 +9,7 @@ RSpec.describe Mutations::Boards::Update do
let_it_be(:board) { create(:board, project: project) } let_it_be(:board) { create(:board, project: project) }
let_it_be(:milestone) { create(:milestone, project: project) } let_it_be(:milestone) { create(:milestone, project: project) }
let_it_be(:iteration) { create(:iteration, group: group) } let_it_be(:iteration) { create(:iteration, group: group) }
let_it_be(:iteration_cadence) { iteration.iterations_cadence }
let_it_be(:label1) { create(:label, project: project) } let_it_be(:label1) { create(:label, project: project) }
let_it_be(:label2) { create(:label, project: project) } let_it_be(:label2) { create(:label, project: project) }
...@@ -83,6 +84,25 @@ RSpec.describe Mutations::Boards::Update do ...@@ -83,6 +84,25 @@ RSpec.describe Mutations::Boards::Update do
end end
end end
# Needs be tested separately from updating iteration as that one will also update
# cadence_id to the iteration's cadence_id
context 'when updating only iteration_cadence' do
let(:mutation_params) do
{
id: board.to_global_id,
iteration_cadence_id: iteration_cadence.to_global_id
}
end
it 'updates iteration cadence' do
expect do
subject
board.reload
end.to change(board, :iteration_cadence).from(nil).to(iteration_cadence)
end
end
context 'when passing labels param' do context 'when passing labels param' do
before do before do
mutation_params.delete(:label_ids) mutation_params.delete(:label_ids)
......
...@@ -3,15 +3,43 @@ ...@@ -3,15 +3,43 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Mutations::Boards::Create do RSpec.describe Mutations::Boards::Create do
include GraphqlHelpers
let_it_be(:current_user, reload: true) { create(:user) }
let_it_be(:parent) { create(:group) } let_it_be(:parent) { create(:group) }
let_it_be(:iteration_cadence) { create(:iterations_cadence, group: parent) }
let(:group_path) { parent.full_path } let(:group_path) { parent.full_path }
let(:name) { 'board name' }
let(:params) do let(:params) do
{ {
group_path: group_path, group_path: group_path,
name: name name: name,
iteration_cadence_id: iteration_cadence.to_global_id.to_s
} }
end end
let(:mutation) { graphql_mutation(:create_board, params) }
subject { post_graphql_mutation(mutation, current_user: current_user) }
def mutation_response
graphql_mutation_response(:create_board)
end
it_behaves_like 'boards create mutation' it_behaves_like 'boards create mutation'
context 'when the user has permission to create a board' do
before do
parent.add_maintainer(current_user)
end
it 'sets cadence_id on creation' do
expect { subject }.to change(::Board, :count).by(1)
created_board = ::Board.last
expect(created_board.iteration_cadence).to eq(iteration_cadence)
end
end
end end
...@@ -4,6 +4,16 @@ require 'spec_helper' ...@@ -4,6 +4,16 @@ require 'spec_helper'
RSpec.describe Mutations::Boards::Create do RSpec.describe Mutations::Boards::Create do
let_it_be(:parent) { create(:project) } let_it_be(:parent) { create(:project) }
let_it_be(:current_user, reload: true) { create(:user) }
let(:name) { 'board name' }
let(:mutation) { graphql_mutation(:create_board, params) }
subject { post_graphql_mutation(mutation, current_user: current_user) }
def mutation_response
graphql_mutation_response(:create_board)
end
let(:project_path) { parent.full_path } let(:project_path) { parent.full_path }
let(:params) do let(:params) do
......
...@@ -3,16 +3,6 @@ ...@@ -3,16 +3,6 @@
RSpec.shared_examples 'boards create mutation' do RSpec.shared_examples 'boards create mutation' do
include GraphqlHelpers include GraphqlHelpers
let_it_be(:current_user, reload: true) { create(:user) }
let(:name) { 'board name' }
let(:mutation) { graphql_mutation(:create_board, params) }
subject { post_graphql_mutation(mutation, current_user: current_user) }
def mutation_response
graphql_mutation_response(:create_board)
end
context 'when the user does not have permission' do context 'when the user does not have permission' do
it_behaves_like 'a mutation that returns a top-level access error' it_behaves_like 'a mutation that returns a top-level access error'
......
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