Commit 9c87275f authored by 🙈  jacopo beschi 🙉's avatar 🙈 jacopo beschi 🙉 Committed by Mayra Cabrera

Show meaningful message on /due quick action with invalid date

When using /due quick action with an invalid date a meaninful error
message is shown.
parent 1961fd1f
---
title: Show meaningful message on /due quick action with invalid date
merge_request: 32349
author: Jacopo Beschi @jacopo-beschi
type: changed
......@@ -25,7 +25,11 @@ module Gitlab
Chronic.parse(due_date_param).try(:to_date)
end
command :due do |due_date|
@updates[:due_date] = due_date if due_date
if due_date
@updates[:due_date] = due_date
else
@execution_message[:due] = _('Failed to set due date because the date format is invalid.')
end
end
desc _('Remove due date')
......
......@@ -4984,6 +4984,9 @@ msgstr ""
msgid "Failed to save preferences."
msgstr ""
msgid "Failed to set due date because the date format is invalid."
msgstr ""
msgid "Failed to update branch!"
msgstr ""
......
......@@ -970,34 +970,6 @@ describe QuickActions::InterpretService do
let(:issuable) { merge_request }
end
it_behaves_like 'due command' do
let(:content) { '/due 2016-08-28' }
let(:issuable) { issue }
end
it_behaves_like 'due command' do
let(:content) { '/due tomorrow' }
let(:issuable) { issue }
let(:expected_date) { Date.tomorrow }
end
it_behaves_like 'due command' do
let(:content) { '/due 5 days from now' }
let(:issuable) { issue }
let(:expected_date) { 5.days.from_now.to_date }
end
it_behaves_like 'due command' do
let(:content) { '/due in 2 days' }
let(:issuable) { issue }
let(:expected_date) { 2.days.from_now.to_date }
end
it_behaves_like 'empty command' do
let(:content) { '/due foo bar' }
let(:issuable) { issue }
end
it_behaves_like 'empty command' do
let(:content) { '/due 2016-08-28' }
let(:issuable) { merge_request }
......@@ -1131,6 +1103,39 @@ describe QuickActions::InterpretService do
end
end
context '/due command' do
it 'returns invalid date format message when the due date is invalid' do
issue = build(:issue, project: project)
_, _, message = service.execute('/due invalid date', issue)
expect(message).to eq('Failed to set due date because the date format is invalid.')
end
it_behaves_like 'due command' do
let(:content) { '/due 2016-08-28' }
let(:issuable) { issue }
end
it_behaves_like 'due command' do
let(:content) { '/due tomorrow' }
let(:issuable) { issue }
let(:expected_date) { Date.tomorrow }
end
it_behaves_like 'due command' do
let(:content) { '/due 5 days from now' }
let(:issuable) { issue }
let(:expected_date) { 5.days.from_now.to_date }
end
it_behaves_like 'due command' do
let(:content) { '/due in 2 days' }
let(:issuable) { issue }
let(:expected_date) { 2.days.from_now.to_date }
end
end
context '/copy_metadata command' do
let(:todo_label) { create(:label, project: project, title: 'To Do') }
let(:inreview_label) { create(:label, project: project, title: 'In Review') }
......
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