Commit 8f3b98b4 authored by Mark Chao's avatar Mark Chao

Merge branch '298840-ajk-fix-epic-id-processing' into 'master'

Fix epic assignment in the createIssue mutation

See merge request gitlab-org/gitlab!51817
parents b35c01cb 1c9c841e
......@@ -5,6 +5,7 @@ module EE
module Issues
module Create
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
prepended do
include ::Mutations::Issues::CommonEEMutationArguments
......@@ -14,10 +15,21 @@ module EE
description: 'The ID of an epic to associate the issue with.'
end
override :resolve
def resolve(**args)
super
rescue ActiveRecord::RecordNotFound => e
{ errors: [e.message], issue: nil }
end
private
def create_issue_params(params)
params[:epic_id] &&= params[:epic_id]&.model_id
override :build_create_issue_params
def build_create_issue_params(params)
# TODO: remove this line when the compatibility layer is removed
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
params[:epic_id] = ::Types::GlobalIDType[::Epic].coerce_isolated_input(params[:epic_id]) if params[:epic_id]
params[:epic_id] = params[:epic_id]&.model_id if params.key?(:epic_id)
super(params)
end
......
---
title: Fix epic assignment in the createIssue mutation
merge_request: 51817
author:
type: fixed
......@@ -3,7 +3,10 @@
require 'spec_helper'
RSpec.describe Mutations::Issues::Create do
let_it_be(:project) { create(:project) }
include GraphqlHelpers
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:user) { create(:user) }
let_it_be(:assignee1) { create(:user) }
let_it_be(:assignee2) { create(:user) }
......@@ -19,12 +22,16 @@ RSpec.describe Mutations::Issues::Create do
}
end
let(:mutation_params) do
let(:inputs) do
{
project_path: project.full_path,
assignee_ids: [assignee1.to_global_id, assignee2.to_global_id],
health_status: Issue.health_statuses[:at_risk]
}.merge(expected_attributes)
}
end
let(:mutation_params) do
inputs.merge(expected_attributes)
end
let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
......@@ -43,7 +50,7 @@ RSpec.describe Mutations::Issues::Create do
context 'when user can create issues' do
before do
project.add_developer(user)
group.add_developer(user)
end
it 'creates issue with correct EE values' do
......@@ -51,6 +58,46 @@ RSpec.describe Mutations::Issues::Create do
expect(mutated_issue.assignees.pluck(:id)).to eq([assignee1.id, assignee2.id])
expect(mutated_issue.health_status).to eq('at_risk')
end
context 'when the epic_id parameter is passed' do
let(:epic) { create(:epic, group: group) }
let(:mutation_params) do
inputs.merge(expected_attributes).merge(epic_id: epic.to_global_id)
end
context 'epics are available' do
before do
stub_licensed_features(epics: true)
end
it 'is successful, and assigns the issue to the epic' do
expect(subject[:errors]).to be_empty
expect(mutated_issue).to have_attributes(epic: epic)
end
context 'the project is not in a group' do
let(:project) { create(:project) }
it 'is successful, but it does not add the epic' do
project.add_developer(user)
expect(subject[:errors]).to be_empty
expect(mutated_issue).not_to have_attributes(epic: epic)
end
end
end
context 'epics are unavailable' do
it 'is unsuccessful' do
expect(subject[:errors]).to contain_exactly("Couldn't find Epic")
end
it 'does not create an issue' do
expect(mutated_issue).to be_nil
end
end
end
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