summaryrefslogtreecommitdiff
path: root/spec/services/slash_commands
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-08-09 19:26:45 +0200
committerRémy Coutable <remy@rymai.me>2016-08-13 00:06:11 +0200
commit7cc4ab14b8a2f1d7d374a320b79374764527659f (patch)
tree6dfd4067d98db291f9b8f5db05909967e0c7cd27 /spec/services/slash_commands
parenta54fdc384fee9daeab1b9fb638dae5dce4e4be15 (diff)
downloadgitlab-ce-7cc4ab14b8a2f1d7d374a320b79374764527659f.tar.gz
New Notes::SlashCommandsService service
Check for update_issuable permission in Notes::SlashCommandsService Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/services/slash_commands')
-rw-r--r--spec/services/slash_commands/interpret_service_spec.rb247
1 files changed, 200 insertions, 47 deletions
diff --git a/spec/services/slash_commands/interpret_service_spec.rb b/spec/services/slash_commands/interpret_service_spec.rb
index fa0f65495ce..d03c84f59b3 100644
--- a/spec/services/slash_commands/interpret_service_spec.rb
+++ b/spec/services/slash_commands/interpret_service_spec.rb
@@ -18,8 +18,7 @@ describe SlashCommands::InterpretService, services: true do
:assign, :reassign,
:unassign, :remove_assignee,
:milestone,
- :remove_milestone,
- :clear_milestone,
+ :clear_milestone, :remove_milestone,
:labels, :label,
:unlabel, :remove_labels, :remove_label,
:clear_labels, :clear_label,
@@ -35,10 +34,12 @@ describe SlashCommands::InterpretService, services: true do
describe '#execute' do
let(:service) { described_class.new(project, user) }
+ let(:issue) { create(:issue) }
+ let(:merge_request) { create(:merge_request) }
shared_examples 'open command' do
it 'returns state_event: "open" if content contains /open' do
- changes = service.execute(content)
+ changes = service.execute(content, issuable)
expect(changes).to eq(state_event: 'reopen')
end
@@ -46,7 +47,7 @@ describe SlashCommands::InterpretService, services: true do
shared_examples 'close command' do
it 'returns state_event: "close" if content contains /open' do
- changes = service.execute(content)
+ changes = service.execute(content, issuable)
expect(changes).to eq(state_event: 'close')
end
@@ -54,31 +55,47 @@ describe SlashCommands::InterpretService, services: true do
shared_examples 'assign command' do
it 'fetches assignee and populates assignee_id if content contains /assign' do
- changes = service.execute(content)
+ changes = service.execute(content, issuable)
expect(changes).to eq(assignee_id: user.id)
end
end
+ shared_examples 'unassign command' do
+ it 'populates assignee_id: nil if content contains /unassign' do
+ changes = service.execute(content, issuable)
+
+ expect(changes).to eq(assignee_id: nil)
+ end
+ end
+
shared_examples 'milestone command' do
it 'fetches milestone and populates milestone_id if content contains /milestone' do
- changes = service.execute(content)
+ changes = service.execute(content, issuable)
expect(changes).to eq(milestone_id: milestone.id)
end
end
+ shared_examples 'clear_milestone command' do
+ it 'populates milestone_id: nil if content contains /clear_milestone' do
+ changes = service.execute(content, issuable)
+
+ expect(changes).to eq(milestone_id: nil)
+ end
+ end
+
shared_examples 'label command' do
it 'fetches label ids and populates add_label_ids if content contains /label' do
- changes = service.execute(content)
+ changes = service.execute(content, issuable)
expect(changes).to eq(add_label_ids: [bug.id, inprogress.id])
end
end
- shared_examples 'remove_labels command' do
- it 'fetches label ids and populates remove_label_ids if content contains /label' do
- changes = service.execute(content)
+ shared_examples 'unlabel command' do
+ it 'fetches label ids and populates remove_label_ids if content contains /unlabel' do
+ changes = service.execute(content, issuable)
expect(changes).to eq(remove_label_ids: [inprogress.id])
end
@@ -86,15 +103,63 @@ describe SlashCommands::InterpretService, services: true do
shared_examples 'clear_labels command' do
it 'populates label_ids: [] if content contains /clear_labels' do
- changes = service.execute(content)
+ changes = service.execute(content, issuable)
expect(changes).to eq(label_ids: [])
end
end
- shared_examples 'command returning no changes' do
- it 'returns an empty hash if content contains /open' do
- changes = service.execute(content)
+ shared_examples 'todo command' do
+ it 'populates todo_event: "mark" if content contains /todo' do
+ changes = service.execute(content, issuable)
+
+ expect(changes).to eq(todo_event: 'mark')
+ end
+ end
+
+ shared_examples 'done command' do
+ it 'populates todo_event: "done" if content contains /done' do
+ changes = service.execute(content, issuable)
+
+ expect(changes).to eq(todo_event: 'done')
+ end
+ end
+
+ shared_examples 'subscribe command' do
+ it 'populates subscription_event: "subscribe" if content contains /subscribe' do
+ changes = service.execute(content, issuable)
+
+ expect(changes).to eq(subscription_event: 'subscribe')
+ end
+ end
+
+ shared_examples 'unsubscribe command' do
+ it 'populates subscription_event: "unsubscribe" if content contains /unsubscribe' do
+ changes = service.execute(content, issuable)
+
+ expect(changes).to eq(subscription_event: 'unsubscribe')
+ end
+ end
+
+ shared_examples 'due_date command' do
+ it 'populates due_date: Date.new(2016, 8, 28) if content contains /due_date 2016-08-28' do
+ changes = service.execute(content, issuable)
+
+ expect(changes).to eq(due_date: Date.new(2016, 8, 28))
+ end
+ end
+
+ shared_examples 'clear_due_date command' do
+ it 'populates due_date: nil if content contains /clear_due_date' do
+ changes = service.execute(content, issuable)
+
+ expect(changes).to eq(due_date: nil)
+ end
+ end
+
+ shared_examples 'empty command' do
+ it 'populates {} if content contains an unsupported command' do
+ changes = service.execute(content, issuable)
expect(changes).to be_empty
end
@@ -102,116 +167,204 @@ describe SlashCommands::InterpretService, services: true do
it_behaves_like 'open command' do
let(:content) { '/open' }
+ let(:issuable) { issue }
+ end
+
+ it_behaves_like 'open command' do
+ let(:content) { '/open' }
+ let(:issuable) { merge_request }
end
it_behaves_like 'open command' do
let(:content) { '/reopen' }
+ let(:issuable) { issue }
end
it_behaves_like 'close command' do
let(:content) { '/close' }
+ let(:issuable) { issue }
+ end
+
+ it_behaves_like 'close command' do
+ let(:content) { '/close' }
+ let(:issuable) { merge_request }
end
it_behaves_like 'assign command' do
let(:content) { "/assign @#{user.username}" }
+ let(:issuable) { issue }
+ end
+
+ it_behaves_like 'assign command' do
+ let(:content) { "/assign @#{user.username}" }
+ let(:issuable) { merge_request }
end
it 'does not populate assignee_id if content contains /assign with an unknown user' do
- changes = service.execute('/assign joe')
+ changes = service.execute('/assign joe', issue)
expect(changes).to be_empty
end
it 'does not populate assignee_id if content contains /assign without user' do
- changes = service.execute('/assign')
+ changes = service.execute('/assign', issue)
expect(changes).to be_empty
end
- it 'populates assignee_id: nil if content contains /unassign' do
- changes = service.execute('/unassign')
+ it_behaves_like 'unassign command' do
+ let(:content) { '/unassign' }
+ let(:issuable) { issue }
+ end
+
+ it_behaves_like 'unassign command' do
+ let(:content) { '/unassign' }
+ let(:issuable) { merge_request }
+ end
+
+ it_behaves_like 'unassign command' do
+ let(:content) { '/remove_assignee' }
+ let(:issuable) { issue }
+ end
- expect(changes).to eq(assignee_id: nil)
+ it_behaves_like 'milestone command' do
+ let(:content) { "/milestone %#{milestone.title}" }
+ let(:issuable) { issue }
end
it_behaves_like 'milestone command' do
let(:content) { "/milestone %#{milestone.title}" }
+ let(:issuable) { merge_request }
+ end
+
+ it_behaves_like 'clear_milestone command' do
+ let(:content) { '/clear_milestone' }
+ let(:issuable) { issue }
+ end
+
+ it_behaves_like 'clear_milestone command' do
+ let(:content) { '/clear_milestone' }
+ let(:issuable) { merge_request }
end
- it 'populates milestone_id: nil if content contains /clear_milestone' do
- changes = service.execute('/clear_milestone')
+ it_behaves_like 'clear_milestone command' do
+ let(:content) { '/remove_milestone' }
+ let(:issuable) { issue }
+ end
- expect(changes).to eq(milestone_id: nil)
+ it_behaves_like 'label command' do
+ let(:content) { %(/label ~"#{inprogress.title}" ~#{bug.title} ~unknown) }
+ let(:issuable) { issue }
end
it_behaves_like 'label command' do
let(:content) { %(/label ~"#{inprogress.title}" ~#{bug.title} ~unknown) }
+ let(:issuable) { merge_request }
end
it_behaves_like 'label command' do
let(:content) { %(/labels ~"#{inprogress.title}" ~#{bug.title} ~unknown) }
+ let(:issuable) { issue }
end
- it_behaves_like 'remove_labels command' do
+ it_behaves_like 'unlabel command' do
let(:content) { %(/unlabel ~"#{inprogress.title}") }
+ let(:issuable) { issue }
end
- it_behaves_like 'remove_labels command' do
+ it_behaves_like 'unlabel command' do
+ let(:content) { %(/unlabel ~"#{inprogress.title}") }
+ let(:issuable) { merge_request }
+ end
+
+ it_behaves_like 'unlabel command' do
let(:content) { %(/remove_labels ~"#{inprogress.title}") }
+ let(:issuable) { issue }
end
- it_behaves_like 'remove_labels command' do
+ it_behaves_like 'unlabel command' do
let(:content) { %(/remove_label ~"#{inprogress.title}") }
+ let(:issuable) { issue }
end
it_behaves_like 'clear_labels command' do
let(:content) { '/clear_labels' }
+ let(:issuable) { issue }
end
it_behaves_like 'clear_labels command' do
- let(:content) { '/clear_label' }
+ let(:content) { '/clear_labels' }
+ let(:issuable) { merge_request }
end
- it 'populates todo: :mark if content contains /todo' do
- changes = service.execute('/todo')
+ it_behaves_like 'clear_labels command' do
+ let(:content) { '/clear_label' }
+ let(:issuable) { issue }
+ end
- expect(changes).to eq(todo_event: 'mark')
+ it_behaves_like 'todo command' do
+ let(:content) { '/todo' }
+ let(:issuable) { issue }
end
- it 'populates todo: :done if content contains /done' do
- changes = service.execute('/done')
+ it_behaves_like 'todo command' do
+ let(:content) { '/todo' }
+ let(:issuable) { merge_request }
+ end
- expect(changes).to eq(todo_event: 'done')
+ it_behaves_like 'done command' do
+ let(:content) { '/done' }
+ let(:issuable) { issue }
end
- it 'populates subscription: :subscribe if content contains /subscribe' do
- changes = service.execute('/subscribe')
+ it_behaves_like 'done command' do
+ let(:content) { '/done' }
+ let(:issuable) { merge_request }
+ end
- expect(changes).to eq(subscription_event: 'subscribe')
+ it_behaves_like 'subscribe command' do
+ let(:content) { '/subscribe' }
+ let(:issuable) { issue }
end
- it 'populates subscription: :unsubscribe if content contains /unsubscribe' do
- changes = service.execute('/unsubscribe')
+ it_behaves_like 'subscribe command' do
+ let(:content) { '/subscribe' }
+ let(:issuable) { merge_request }
+ end
- expect(changes).to eq(subscription_event: 'unsubscribe')
+ it_behaves_like 'unsubscribe command' do
+ let(:content) { '/unsubscribe' }
+ let(:issuable) { issue }
end
- it 'populates due_date: Time.now.tomorrow if content contains /due_date 2016-08-28' do
- changes = service.execute('/due_date 2016-08-28')
+ it_behaves_like 'unsubscribe command' do
+ let(:content) { '/unsubscribe' }
+ let(:issuable) { merge_request }
+ end
- expect(changes).to eq(due_date: Date.new(2016, 8, 28))
+ it_behaves_like 'due_date command' do
+ let(:content) { '/due_date 2016-08-28' }
+ let(:issuable) { issue }
end
- it 'populates due_date: Time.now.tomorrow if content contains /due_date foo' do
- changes = service.execute('/due_date foo')
+ it_behaves_like 'empty command' do
+ let(:content) { '/due_date foo bar' }
+ let(:issuable) { issue }
+ end
- expect(changes).to be_empty
+ it_behaves_like 'empty command' do
+ let(:content) { '/due_date 2016-08-28' }
+ let(:issuable) { merge_request }
end
- it 'populates due_date: nil if content contains /clear_due_date' do
- changes = service.execute('/clear_due_date')
+ it_behaves_like 'clear_due_date command' do
+ let(:content) { '/clear_due_date' }
+ let(:issuable) { issue }
+ end
- expect(changes).to eq(due_date: nil)
+ it_behaves_like 'empty command' do
+ let(:content) { '/clear_due_date' }
+ let(:issuable) { merge_request }
end
end
end