debian-mirror-gitlab/spec/lib/gitlab/slash_commands/command_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

147 lines
4.7 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::SlashCommands::Command do
2020-03-09 13:42:32 +05:30
let(:project) { create(:project, :repository) }
2017-08-17 22:00:37 +05:30
let(:user) { create(:user) }
2018-03-27 19:54:05 +05:30
let(:chat_name) { double(:chat_name, user: user) }
2017-08-17 22:00:37 +05:30
describe '#execute' do
subject do
2018-03-27 19:54:05 +05:30
described_class.new(project, chat_name, params).execute
2017-08-17 22:00:37 +05:30
end
context 'when no command is available' do
let(:params) { { text: 'issue show 1' } }
2017-09-10 17:25:29 +05:30
let(:project) { create(:project, has_external_issue_tracker: true) }
2017-08-17 22:00:37 +05:30
it 'displays 404 messages' do
expect(subject[:response_type]).to be(:ephemeral)
expect(subject[:text]).to start_with('404 not found')
end
end
context 'when an unknown command is triggered' do
let(:params) { { command: '/gitlab', text: "unknown command 123" } }
it 'displays the help message' do
expect(subject[:response_type]).to be(:ephemeral)
2019-12-04 20:38:33 +05:30
expect(subject[:text]).to start_with('The specified command is not valid')
2017-08-17 22:00:37 +05:30
expect(subject[:text]).to match('/gitlab issue show')
end
end
context 'the user can not create an issue' do
let(:params) { { text: "issue create my new issue" } }
it 'rejects the actions' do
expect(subject[:response_type]).to be(:ephemeral)
2019-12-04 20:38:33 +05:30
expect(subject[:text]).to start_with('You are not allowed')
2017-08-17 22:00:37 +05:30
end
end
context 'when trying to do deployment' do
let(:params) { { text: 'deploy staging to production' } }
let!(:build) { create(:ci_build, pipeline: pipeline) }
let!(:pipeline) { create(:ci_pipeline, project: project) }
let!(:staging) { create(:environment, name: 'staging', project: project) }
2018-12-13 13:39:08 +05:30
let!(:deployment) { create(:deployment, :success, environment: staging, deployable: build) }
2017-08-17 22:00:37 +05:30
let!(:manual) do
create(:ci_build, :manual, pipeline: pipeline,
name: 'first',
environment: 'production')
end
context 'and user can not create deployment' do
it 'returns action' do
expect(subject[:response_type]).to be(:ephemeral)
2019-12-04 20:38:33 +05:30
expect(subject[:text]).to start_with('You are not allowed')
2017-08-17 22:00:37 +05:30
end
end
context 'and user has deployment permission' do
before do
build.project.add_developer(user)
create(:protected_branch, :developers_can_merge,
name: build.ref, project: project)
end
it 'returns action' do
expect(subject[:text]).to include('Deployment started from staging to production')
expect(subject[:response_type]).to be(:in_channel)
end
context 'when duplicate action exists' do
let!(:manual2) do
create(:ci_build, :manual, pipeline: pipeline,
name: 'second',
environment: 'production')
end
it 'returns error' do
expect(subject[:response_type]).to be(:ephemeral)
2017-09-10 17:25:29 +05:30
expect(subject[:text]).to include("Couldn't find a deployment manual action.")
2017-08-17 22:00:37 +05:30
end
end
end
end
end
describe '#match_command' do
2018-03-27 19:54:05 +05:30
subject { described_class.new(project, chat_name, params).match_command.first }
2017-08-17 22:00:37 +05:30
context 'IssueShow is triggered' do
let(:params) { { text: 'issue show 123' } }
2017-09-10 17:25:29 +05:30
it { is_expected.to eq(Gitlab::SlashCommands::IssueShow) }
2017-08-17 22:00:37 +05:30
end
context 'IssueCreate is triggered' do
let(:params) { { text: 'issue create my title' } }
2017-09-10 17:25:29 +05:30
it { is_expected.to eq(Gitlab::SlashCommands::IssueNew) }
2017-08-17 22:00:37 +05:30
end
context 'IssueSearch is triggered' do
let(:params) { { text: 'issue search my query' } }
2017-09-10 17:25:29 +05:30
it { is_expected.to eq(Gitlab::SlashCommands::IssueSearch) }
2017-08-17 22:00:37 +05:30
end
2018-05-09 12:01:36 +05:30
context 'IssueMove is triggered' do
let(:params) { { text: 'issue move #78291 to gitlab/gitlab-ci' } }
2020-01-01 13:55:28 +05:30
2018-05-09 12:01:36 +05:30
it { is_expected.to eq(Gitlab::SlashCommands::IssueMove) }
end
2019-12-26 22:10:19 +05:30
context 'IssueComment is triggered' do
let(:params) { { text: "issue comment #503\ncomment body" } }
2020-01-01 13:55:28 +05:30
2019-12-26 22:10:19 +05:30
it { is_expected.to eq(Gitlab::SlashCommands::IssueComment) }
end
2023-01-13 00:05:48 +05:30
context 'when incident declare is triggered' do
context 'IncidentNew is triggered' do
let(:params) { { text: 'incident declare' } }
it { is_expected.to eq(Gitlab::SlashCommands::IncidentManagement::IncidentNew) }
end
context 'when feature flag is disabled' do
before do
stub_feature_flags(incident_declare_slash_command: false)
end
context 'IncidentNew is triggered' do
let(:params) { { text: 'incident declare' } }
it { is_expected.not_to eq(Gitlab::SlashCommands::IncidentManagement::IncidentNew) }
end
end
end
2017-08-17 22:00:37 +05:30
end
end