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:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-06 12:06:23 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-06 12:06:23 +0300
commitd15180e00b209d0fbe3d8ce61b3af269aecdf7f5 (patch)
treee24bcc044a3e471811b91ade8a23120a27210c3f /spec/lib
parent505c40d537244b35807129ade0c577f752e9d564 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/slash_commands/command_spec.rb5
-rw-r--r--spec/lib/gitlab/slash_commands/issue_comment_spec.rb117
-rw-r--r--spec/lib/gitlab/slash_commands/presenters/access_spec.rb10
-rw-r--r--spec/lib/gitlab/slash_commands/presenters/issue_comment_spec.rb37
-rw-r--r--spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb34
-rw-r--r--spec/lib/gitlab/usage_data_spec.rb3
6 files changed, 205 insertions, 1 deletions
diff --git a/spec/lib/gitlab/slash_commands/command_spec.rb b/spec/lib/gitlab/slash_commands/command_spec.rb
index dc412c80e68..5a8c721a634 100644
--- a/spec/lib/gitlab/slash_commands/command_spec.rb
+++ b/spec/lib/gitlab/slash_commands/command_spec.rb
@@ -115,5 +115,10 @@ describe Gitlab::SlashCommands::Command do
let(:params) { { text: 'issue move #78291 to gitlab/gitlab-ci' } }
it { is_expected.to eq(Gitlab::SlashCommands::IssueMove) }
end
+
+ context 'IssueComment is triggered' do
+ let(:params) { { text: "issue comment #503\ncomment body" } }
+ it { is_expected.to eq(Gitlab::SlashCommands::IssueComment) }
+ end
end
end
diff --git a/spec/lib/gitlab/slash_commands/issue_comment_spec.rb b/spec/lib/gitlab/slash_commands/issue_comment_spec.rb
new file mode 100644
index 00000000000..c6f56d10d1f
--- /dev/null
+++ b/spec/lib/gitlab/slash_commands/issue_comment_spec.rb
@@ -0,0 +1,117 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::SlashCommands::IssueComment do
+ describe '#execute' do
+ let(:project) { create(:project, :public) }
+ let(:issue) { create(:issue, project: project) }
+ let(:user) { issue.author }
+ let(:chat_name) { double(:chat_name, user: user) }
+ let(:regex_match) { described_class.match("issue comment #{issue.iid}\nComment body") }
+
+ subject { described_class.new(project, chat_name).execute(regex_match) }
+
+ context 'when the issue exists' do
+ context 'when project is private' do
+ let(:project) { create(:project) }
+
+ context 'when the user is not a member of the project' do
+ let(:chat_name) { double(:chat_name, user: create(:user)) }
+
+ it 'does not allow the user to comment' do
+ expect(subject[:response_type]).to be(:ephemeral)
+ expect(subject[:text]).to match('not found')
+ expect(issue.reload.notes.count).to be_zero
+ end
+ end
+ end
+
+ context 'when the user is not a member of the project' do
+ let(:chat_name) { double(:chat_name, user: create(:user)) }
+
+ context 'when the discussion is locked in the issue' do
+ before do
+ issue.update!(discussion_locked: true)
+ end
+
+ it 'does not allow the user to comment' do
+ expect(subject[:response_type]).to be(:ephemeral)
+ expect(subject[:text]).to match('You are not allowed')
+ expect(issue.reload.notes.count).to be_zero
+ end
+ end
+ end
+
+ context 'when the user can comment on the issue' do
+ context 'when comment body exists' do
+ it 'creates a new comment' do
+ expect { subject }.to change { issue.notes.count }.by(1)
+ end
+
+ it 'a new comment has a correct body' do
+ subject
+
+ expect(issue.notes.last.note).to eq('Comment body')
+ end
+ end
+
+ context 'when comment body does not exist' do
+ let(:regex_match) { described_class.match("issue comment #{issue.iid}") }
+
+ it 'does not create a new comment' do
+ expect { subject }.not_to change { issue.notes.count }
+ end
+
+ it 'displays the errors' do
+ expect(subject[:response_type]).to be(:ephemeral)
+ expect(subject[:text]).to match("- Note can't be blank")
+ end
+ end
+ end
+ end
+
+ context 'when the issue does not exist' do
+ let(:regex_match) { described_class.match("issue comment 2343242\nComment body") }
+
+ it 'returns not found' do
+ expect(subject[:response_type]).to be(:ephemeral)
+ expect(subject[:text]).to match('not found')
+ end
+ end
+ end
+
+ describe '.match' do
+ subject(:match) { described_class.match(command) }
+
+ context 'when a command has an issue ID' do
+ context 'when command has a comment body' do
+ let(:command) { "issue comment 503\nComment body" }
+
+ it 'matches an issue ID' do
+ expect(match[:iid]).to eq('503')
+ end
+
+ it 'matches an note body' do
+ expect(match[:note_body]).to eq('Comment body')
+ end
+ end
+ end
+
+ context 'when a command has a reference prefix for issue ID' do
+ let(:command) { "issue comment #503\nComment body" }
+
+ it 'matches an issue ID' do
+ expect(match[:iid]).to eq('503')
+ end
+ end
+
+ context 'when a command does not have an issue ID' do
+ let(:command) { 'issue comment' }
+
+ it 'does not match' do
+ is_expected.to be_nil
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/slash_commands/presenters/access_spec.rb b/spec/lib/gitlab/slash_commands/presenters/access_spec.rb
index c7b83467660..804184a7173 100644
--- a/spec/lib/gitlab/slash_commands/presenters/access_spec.rb
+++ b/spec/lib/gitlab/slash_commands/presenters/access_spec.rb
@@ -22,6 +22,16 @@ describe Gitlab::SlashCommands::Presenters::Access do
end
end
+ describe '#generic_access_denied' do
+ subject { described_class.new.generic_access_denied }
+
+ it { is_expected.to be_a(Hash) }
+
+ it_behaves_like 'displays an error message' do
+ let(:error_message) { 'You are not allowed to perform the given chatops command.' }
+ end
+ end
+
describe '#deactivated' do
subject { described_class.new.deactivated }
diff --git a/spec/lib/gitlab/slash_commands/presenters/issue_comment_spec.rb b/spec/lib/gitlab/slash_commands/presenters/issue_comment_spec.rb
new file mode 100644
index 00000000000..b5ef417cb93
--- /dev/null
+++ b/spec/lib/gitlab/slash_commands/presenters/issue_comment_spec.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::SlashCommands::Presenters::IssueComment do
+ let_it_be(:project) { create(:project) }
+ let_it_be(:issue) { create(:issue, project: project) }
+ let_it_be(:note) { create(:note, project: project, noteable: issue) }
+ let(:author) { note.author }
+
+ describe '#present' do
+ let(:attachment) { subject[:attachments].first }
+ subject { described_class.new(note).present }
+
+ it { is_expected.to be_a(Hash) }
+
+ it 'sets ephemeral response type' do
+ expect(subject[:response_type]).to be(:ephemeral)
+ end
+
+ it 'sets the title' do
+ expect(attachment[:title]).to eq("#{issue.title} ยท #{issue.to_reference}")
+ end
+
+ it 'sets the fallback text' do
+ expect(attachment[:fallback]).to eq("New comment on #{issue.to_reference}: #{issue.title}")
+ end
+
+ it 'sets the fields' do
+ expect(attachment[:fields]).to eq([{ title: 'Comment', value: note.note }])
+ end
+
+ it 'sets the color' do
+ expect(attachment[:color]).to eq('#38ae67')
+ end
+ end
+end
diff --git a/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb
index 7a01f7d1de8..96ebeb8ff76 100644
--- a/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb
+++ b/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb
@@ -34,22 +34,54 @@ describe Gitlab::UsageDataCounters::WebIdeCounter, :clean_gitlab_redis_shared_st
it_behaves_like 'counter examples'
end
+ describe 'previews counter' do
+ let(:setting_enabled) { true }
+
+ before do
+ stub_application_setting(web_ide_clientside_preview_enabled: setting_enabled)
+ end
+
+ context 'when web ide clientside preview is enabled' do
+ let(:increment_counter_method) { :increment_previews_count }
+ let(:total_counter_method) { :total_previews_count }
+
+ it_behaves_like 'counter examples'
+ end
+
+ context 'when web ide clientside preview is not enabled' do
+ let(:setting_enabled) { false }
+
+ it 'does not increment the counter' do
+ expect(described_class.total_previews_count).to eq(0)
+
+ 2.times { described_class.increment_previews_count }
+
+ expect(described_class.total_previews_count).to eq(0)
+ end
+ end
+ end
+
describe '.totals' do
commits = 5
merge_requests = 3
views = 2
+ previews = 4
before do
+ stub_application_setting(web_ide_clientside_preview_enabled: true)
+
commits.times { described_class.increment_commits_count }
merge_requests.times { described_class.increment_merge_requests_count }
views.times { described_class.increment_views_count }
+ previews.times { described_class.increment_previews_count }
end
it 'can report all totals' do
expect(described_class.totals).to include(
web_ide_commits: commits,
web_ide_views: views,
- web_ide_merge_requests: merge_requests
+ web_ide_merge_requests: merge_requests,
+ web_ide_previews: previews
)
end
end
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb
index b0886963a04..0ad196bd050 100644
--- a/spec/lib/gitlab/usage_data_spec.rb
+++ b/spec/lib/gitlab/usage_data_spec.rb
@@ -76,6 +76,7 @@ describe Gitlab::UsageData do
avg_cycle_analytics
influxdb_metrics_enabled
prometheus_metrics_enabled
+ web_ide_clientside_preview_enabled
))
end
@@ -93,6 +94,7 @@ describe Gitlab::UsageData do
web_ide_views
web_ide_commits
web_ide_merge_requests
+ web_ide_previews
navbar_searches
cycle_analytics_views
productivity_analytics_views
@@ -252,6 +254,7 @@ describe Gitlab::UsageData do
expect(subject[:container_registry_enabled]).to eq(Gitlab.config.registry.enabled)
expect(subject[:dependency_proxy_enabled]).to eq(Gitlab.config.dependency_proxy.enabled)
expect(subject[:gitlab_shared_runners_enabled]).to eq(Gitlab.config.gitlab_ci.shared_runners_enabled)
+ expect(subject[:web_ide_clientside_preview_enabled]).to eq(Gitlab::CurrentSettings.web_ide_clientside_preview_enabled?)
end
end