Commit 8db95b6a authored by charlie ablett's avatar charlie ablett

Merge branch 'accept-null-in-issuesetduedate' into 'master'

Accept null in the issueSetDueDate mutation

See merge request gitlab-org/gitlab!60139
parents 7dfb0770 6142d9e6
......@@ -7,8 +7,17 @@ module Mutations
argument :due_date,
Types::TimeType,
required: true,
description: 'The desired due date for the issue.'
required: false,
description: 'The desired due date for the issue, ' \
'due date will be removed if absent or set to null'
def ready?(**args)
unless args.key?(:due_date)
raise Gitlab::Graphql::Errors::ArgumentError, 'Argument dueDate must be provided (`null` accepted)'
end
super
end
def resolve(project_path:, iid:, due_date:)
issue = authorized_find!(project_path: project_path, iid: iid)
......
---
title: Allow issueSetDueDate GraphQL mutation to accept null values
merge_request: 60139
author:
type: added
......@@ -2337,7 +2337,7 @@ Input type: `IssueSetDueDateInput`
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationissuesetduedateclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationissuesetduedateduedate"></a>`dueDate` | [`Time!`](#time) | The desired due date for the issue. |
| <a id="mutationissuesetduedateduedate"></a>`dueDate` | [`Time`](#time) | The desired due date for the issue, due date will be removed if absent or set to null. |
| <a id="mutationissuesetduedateiid"></a>`iid` | [`String!`](#string) | The IID of the issue to mutate. |
| <a id="mutationissuesetduedateprojectpath"></a>`projectPath` | [`ID!`](#id) | The project the issue to mutate is in. |
......
......@@ -3,8 +3,9 @@
require 'spec_helper'
RSpec.describe Mutations::Issues::SetDueDate do
let(:issue) { create(:issue) }
let(:user) { create(:user) }
let(:issue) { create(:issue, due_date: '2021-05-01') }
let_it_be(:user) { create(:user) }
subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
......@@ -23,17 +24,25 @@ RSpec.describe Mutations::Issues::SetDueDate do
issue.project.add_developer(user)
end
it 'returns the issue with updated due date' do
it 'returns the issue with updated due date', :aggregate_failures do
expect(mutated_issue).to eq(issue)
expect(mutated_issue.due_date).to eq(Date.today + 2.days)
expect(subject[:errors]).to be_empty
end
context 'when due date is nil' do
let(:due_date) { nil }
it 'updates due date to be nil' do
expect(mutated_issue.due_date).to be nil
end
end
context 'when passing incorrect due date value' do
let(:due_date) { 'test' }
it 'does not update due date' do
expect(mutated_issue.due_date).to eq(issue.due_date)
it 'updates due date to be nil' do
expect(mutated_issue.due_date).to be nil
end
end
end
......
......@@ -42,11 +42,34 @@ RSpec.describe 'Setting Due Date of an issue' do
expect(graphql_errors).to include(a_hash_including('message' => error))
end
it 'updates the issue due date' do
post_graphql_mutation(mutation, current_user: current_user)
context 'when due date value is a valid date' do
it 'updates the issue due date' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']['dueDate']).to eq(2.days.since.to_date.to_s)
end
end
context 'when due date value is null' do
let(:input) { { due_date: nil } }
it 'updates the issue to remove the due date' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']['dueDate']).to eq(2.days.since.to_date.to_s)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']['dueDate']).to be nil
end
end
context 'when due date argument 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' => /Argument dueDate must be provided/))
end
end
context 'when the due date value is not a valid time' 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