Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2016-11-16 20:28:38 +0300
committerZ.J. van de Weg <git@zjvandeweg.nl>2016-11-17 23:34:24 +0300
commit1b4fdb9893af28606b7594ee656438c7ef21e9d8 (patch)
tree420a687514aedcc68c5a2dbe649123e3a52fdb02 /spec/lib
parent8c8bc07d32f1103bb7996b499ead6ad6eb5bd337 (diff)
Rename from service, and move to lib/gitlab
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/chat_commands/command_spec.rb19
-rw-r--r--spec/lib/gitlab/chat_commands/issue_create_spec.rb35
-rw-r--r--spec/lib/gitlab/chat_commands/issue_search_spec.rb39
-rw-r--r--spec/lib/gitlab/chat_commands/issue_show_spec.rb30
-rw-r--r--spec/lib/gitlab/chat_commands/merge_request_search_spec.rb36
-rw-r--r--spec/lib/gitlab/chat_commands/merge_request_show_spec.rb37
6 files changed, 196 insertions, 0 deletions
diff --git a/spec/lib/gitlab/chat_commands/command_spec.rb b/spec/lib/gitlab/chat_commands/command_spec.rb
new file mode 100644
index 00000000000..d28349ff1d8
--- /dev/null
+++ b/spec/lib/gitlab/chat_commands/command_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe Gitlab::ChatCommands::Command, service: true do
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+ let(:params) { { text: 'issue show 1' } }
+
+ subject { described_class.new(project, user, params).execute }
+
+ xdescribe '#execute' do
+ context 'when issue show is triggered' do
+ it 'calls IssueShowService' do
+ expect_any_instance_of(Mattermost::Commands::IssueShowService).to receive(:new).with(project, user, params)
+
+ subject
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/chat_commands/issue_create_spec.rb b/spec/lib/gitlab/chat_commands/issue_create_spec.rb
new file mode 100644
index 00000000000..184c09708a4
--- /dev/null
+++ b/spec/lib/gitlab/chat_commands/issue_create_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe Gitlab::ChatCommands::IssueCreate, service: true do
+ describe '#execute' do
+ let(:project) { create(:empty_project) }
+ let(:user) { create(:user) }
+ let(:regex_match) { described_class.match("issue create bird is the word") }
+
+ before { project.team << [user, :master] }
+
+ subject { described_class.new(project, user).execute(regex_match) }
+
+ context 'without description' do
+ it 'creates the issue' do
+ expect do
+ subject # this trigger the execution
+ end.to change { project.issues.count }.by(1)
+
+ expect(subject[:response_type]).to be :in_channel
+ expect(subject[:text]).to match 'bird is the word'
+ end
+ end
+
+ context 'with description' do
+ let(:description) { "Surfin bird" }
+ let(:regex_match) { described_class.match("issue create bird is the word\n#{description}") }
+
+ before { subject }
+
+ it 'creates the issue with description' do
+ expect(Issue.last.description).to eq description
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/chat_commands/issue_search_spec.rb b/spec/lib/gitlab/chat_commands/issue_search_spec.rb
new file mode 100644
index 00000000000..3e54333528a
--- /dev/null
+++ b/spec/lib/gitlab/chat_commands/issue_search_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper'
+
+describe Gitlab::ChatCommands::IssueSearch, service: true do
+ describe '#execute' do
+ let!(:issue) { create(:issue, title: 'The bird is the word') }
+ let(:project) { issue.project }
+ let(:user) { issue.author }
+ let(:regex_match) { described_class.match("issue search bird is the") }
+
+ before { project.team << [user, :master] }
+
+ subject { described_class.new(project, user).execute(regex_match) }
+
+ context 'without results' do
+ let(:regex_match) { described_class.match("issue search no results for this one") }
+
+ it "returns nil" do
+ expect(subject[:response_type]).to be :ephemeral
+ expect(subject[:text]).to start_with '404 not found!'
+ end
+ end
+
+ context 'with 1 result' do
+ it 'returns the issue' do
+ expect(subject[:response_type]).to be :in_channel
+ expect(subject[:text]).to match issue.title
+ end
+ end
+
+ context 'with 2 or more results' do
+ let!(:issue2) { create(:issue, project: project, title: 'bird is the word!') }
+
+ it 'returns multiple resources' do
+ expect(subject[:response_type]).to be :ephemeral
+ expect(subject[:text]).to start_with 'Multiple results were found'
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/chat_commands/issue_show_spec.rb b/spec/lib/gitlab/chat_commands/issue_show_spec.rb
new file mode 100644
index 00000000000..ddf7fc87c36
--- /dev/null
+++ b/spec/lib/gitlab/chat_commands/issue_show_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe Gitlab::ChatCommands::IssueShow, service: true do
+ describe '#execute' do
+ let(:issue) { create(:issue) }
+ let(:project) { issue.project }
+ let(:user) { issue.author }
+ let(:regex_match) { described_class.match("issue show #{issue.iid}") }
+
+ before { project.team << [user, :master] }
+
+ subject { described_class.new(project, user).execute(regex_match) }
+
+ context 'the issue exists' do
+ it 'returns the issue' do
+ expect(subject[:response_type]).to be :in_channel
+ expect(subject[:text]).to match issue.title
+ end
+ end
+
+ context 'the issue does not exist' do
+ let(:regex_match) { described_class.match("issue show 1234") }
+
+ it "returns nil" do
+ expect(subject[:response_type]).to be :ephemeral
+ expect(subject[:text]).to start_with '404 not found!'
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/chat_commands/merge_request_search_spec.rb b/spec/lib/gitlab/chat_commands/merge_request_search_spec.rb
new file mode 100644
index 00000000000..4cb4563e589
--- /dev/null
+++ b/spec/lib/gitlab/chat_commands/merge_request_search_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe Gitlab::ChatCommands::MergeRequestSearch, service: true do
+ describe '#execute' do
+ let!(:merge_request) { create(:merge_request, title: 'The bird is the word') }
+ let(:project) { merge_request.source_project }
+ let(:user) { merge_request.author }
+ let(:regex_match) { described_class.match("mergerequest search #{merge_request.title}") }
+
+ before { project.team << [user, :master] }
+
+ subject { described_class.new(project, user, {}).execute(regex_match) }
+
+ context 'the merge request exists' do
+ it 'returns the merge request' do
+ expect(subject[:response_type]).to be :in_channel
+ expect(subject[:text]).to match merge_request.title
+ end
+ end
+
+ context 'no results can be found' do
+ let(:regex_match) { described_class.match("mergerequest search 12334") }
+
+ it "returns a 404 message" do
+ expect(subject[:response_type]).to be :ephemeral
+ expect(subject[:text]).to start_with '404 not found!'
+ end
+ end
+ end
+
+ describe 'self.match' do
+ it 'matches a valid query' do
+ expect(described_class.match("mergerequest search my title here")).to be_truthy
+ end
+ end
+end
diff --git a/spec/lib/gitlab/chat_commands/merge_request_show_spec.rb b/spec/lib/gitlab/chat_commands/merge_request_show_spec.rb
new file mode 100644
index 00000000000..ed63ffa5f85
--- /dev/null
+++ b/spec/lib/gitlab/chat_commands/merge_request_show_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe Gitlab::ChatCommands::MergeRequestShow, service: true do
+ describe '#execute' do
+ let!(:merge_request) { create(:merge_request) }
+ let(:project) { merge_request.source_project }
+ let(:user) { merge_request.author }
+ let(:regex_match) { described_class.match("mergerequest show #{merge_request.iid}") }
+
+ before { project.team << [user, :master] }
+
+ subject { described_class.new(project, user).execute(regex_match) }
+
+ context 'the merge request exists' do
+ it 'returns the merge request' do
+ expect(subject[:response_type]).to be :in_channel
+ expect(subject[:text]).to match merge_request.title
+ end
+ end
+
+ context 'the merge request does not exist' do
+ let(:regex_match) { described_class.match("mergerequest show 12345") }
+
+ it "returns nil" do
+ expect(subject[:response_type]).to be :ephemeral
+ expect(subject[:text]).to start_with '404 not found!'
+ end
+ end
+ end
+
+ describe "self.match" do
+ it 'matches valid strings' do
+ expect(described_class.match("mergerequest show 123")).to be_truthy
+ expect(described_class.match("mergerequest show sdf23")).to be_falsy
+ end
+ end
+end