Commit 82302cc1 authored by John Hope's avatar John Hope Committed by Gabriel Mazetto

Allow null as an acceptable value for issue weight in GraphQL API

parent e430a1ed
...@@ -2548,7 +2548,7 @@ Input type: `IssueSetWeightInput` ...@@ -2548,7 +2548,7 @@ Input type: `IssueSetWeightInput`
| <a id="mutationissuesetweightclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. | | <a id="mutationissuesetweightclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationissuesetweightiid"></a>`iid` | [`String!`](#string) | The IID of the issue to mutate. | | <a id="mutationissuesetweightiid"></a>`iid` | [`String!`](#string) | The IID of the issue to mutate. |
| <a id="mutationissuesetweightprojectpath"></a>`projectPath` | [`ID!`](#id) | The project the issue to mutate is in. | | <a id="mutationissuesetweightprojectpath"></a>`projectPath` | [`ID!`](#id) | The project the issue to mutate is in. |
| <a id="mutationissuesetweightweight"></a>`weight` | [`Int!`](#int) | The desired weight for the issue. | | <a id="mutationissuesetweightweight"></a>`weight` | [`Int`](#int) | The desired weight for the issue. If set to null, weight is removed. |
#### Fields #### Fields
......
...@@ -7,8 +7,17 @@ module Mutations ...@@ -7,8 +7,17 @@ module Mutations
argument :weight, argument :weight,
GraphQL::INT_TYPE, GraphQL::INT_TYPE,
required: true, required: false,
description: 'The desired weight for the issue.' description: 'The desired weight for the issue. ' \
'If set to null, weight is removed.'
def ready?(**args)
unless args.key?(:weight)
raise Gitlab::Graphql::Errors::ArgumentError, 'The `weight` argument is required (`null` accepted).'
end
super
end
def resolve(project_path:, iid:, weight:) def resolve(project_path:, iid:, weight:)
issue = authorized_find!(project_path: project_path, iid: iid) issue = authorized_find!(project_path: project_path, iid: iid)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Mutations::Issues::SetWeight do RSpec.describe Mutations::Issues::SetWeight do
let(:issue) { create(:issue) } let(:issue) { create(:issue, weight: 1) }
let(:user) { create(:user) } let(:user) { create(:user) }
subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
...@@ -20,11 +20,19 @@ RSpec.describe Mutations::Issues::SetWeight do ...@@ -20,11 +20,19 @@ RSpec.describe Mutations::Issues::SetWeight do
issue.project.add_developer(user) issue.project.add_developer(user)
end end
it 'returns the issue with correct weight' do it 'returns the issue with correct weight', :aggregate_failures do
expect(mutated_issue).to eq(issue) expect(mutated_issue).to eq(issue)
expect(mutated_issue.weight).to eq(2) expect(mutated_issue.weight).to eq(2)
expect(subject[:errors]).to be_empty expect(subject[:errors]).to be_empty
end end
context 'when the weight is nil' do
let(:weight) { nil }
it 'updates weight to be nil' do
expect(mutated_issue.weight).to be nil
end
end
end end
end end
end end
...@@ -6,7 +6,7 @@ RSpec.describe 'Setting weight of an issue' do ...@@ -6,7 +6,7 @@ RSpec.describe 'Setting weight of an issue' do
include GraphqlHelpers include GraphqlHelpers
let(:current_user) { create(:user) } let(:current_user) { create(:user) }
let(:issue) { create(:issue) } let(:issue) { create(:issue, weight: 1) }
let(:project) { issue.project } let(:project) { issue.project }
let(:input) { { weight: 2 } } let(:input) { { weight: 2 } }
...@@ -44,11 +44,34 @@ RSpec.describe 'Setting weight of an issue' do ...@@ -44,11 +44,34 @@ RSpec.describe 'Setting weight of an issue' do
expect(graphql_errors).to include(a_hash_including('message' => error)) expect(graphql_errors).to include(a_hash_including('message' => error))
end end
it 'updates the issue weight' do context 'when weight is a number' do
post_graphql_mutation(mutation, current_user: current_user) it 'updates the issue weight' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']['weight']).to eq(2)
end
end
context 'when weight is null' do
let(:input) { { weight: nil } }
it 'updates the issue weight' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success) expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']['weight']).to eq(2) expect(mutation_response['issue']['weight']).to eq(nil)
end
end
context 'when weight is not given' do
let(:input) { {} }
it 'returns an error' do
post_graphql_mutation(mutation, current_user: current_user)
expect(graphql_errors).to include(a_hash_including('message' => /The `weight` argument is required \(`null` accepted\)/))
end
end end
context 'when weight is not an integer' do context 'when weight is not an integer' do
......
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