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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-09-14 03:06:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-09-14 03:06:25 +0300
commita93dfc1b7e55b118b1cf4a67afeb46556292914c (patch)
tree65b874b7940d0d05c4ebedaef43b8a1009362651 /spec/services/issues
parent188a57f93bba5953800de490fcc6246966a073fd (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/issues')
-rw-r--r--spec/services/issues/zoom_link_service_spec.rb243
1 files changed, 243 insertions, 0 deletions
diff --git a/spec/services/issues/zoom_link_service_spec.rb b/spec/services/issues/zoom_link_service_spec.rb
new file mode 100644
index 00000000000..baa6d774864
--- /dev/null
+++ b/spec/services/issues/zoom_link_service_spec.rb
@@ -0,0 +1,243 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Issues::ZoomLinkService do
+ set(:user) { create(:user) }
+ set(:issue) { create(:issue) }
+
+ let(:project) { issue.project }
+ let(:service) { described_class.new(issue, user) }
+ let(:zoom_link) { 'https://zoom.us/j/123456789' }
+
+ before do
+ project.add_reporter(user)
+ end
+
+ shared_context 'with Zoom link' do
+ before do
+ issue.update!(description: "Description\n\n#{zoom_link}")
+ end
+ end
+
+ shared_context 'with Zoom link not at the end' do
+ before do
+ issue.update!(description: "Description with #{zoom_link} some where")
+ end
+ end
+
+ shared_context 'without Zoom link' do
+ before do
+ issue.update!(description: "Description\n\nhttp://example.com")
+ end
+ end
+
+ shared_context 'without issue description' do
+ before do
+ issue.update!(description: nil)
+ end
+ end
+
+ shared_context 'feature flag disabled' do
+ before do
+ stub_feature_flags(issue_zoom_integration: false)
+ end
+ end
+
+ shared_context 'insufficient permissions' do
+ before do
+ project.add_guest(user)
+ end
+ end
+
+ describe '#add_link' do
+ shared_examples 'can add link' do
+ it 'appends the link to issue description' do
+ expect(result).to be_success
+ expect(result.payload[:description])
+ .to eq("#{issue.description}\n\n#{zoom_link}")
+ end
+ end
+
+ shared_examples 'cannot add link' do
+ it 'cannot add the link' do
+ expect(result).to be_error
+ expect(result.message).to eq('Failed to add a Zoom meeting')
+ end
+ end
+
+ subject(:result) { service.add_link(zoom_link) }
+
+ context 'without Zoom link in the issue description' do
+ include_context 'without Zoom link'
+ include_examples 'can add link'
+
+ context 'with invalid Zoom link' do
+ let(:zoom_link) { 'https://not-zoom.link' }
+
+ include_examples 'cannot add link'
+ end
+
+ context 'when feature flag is disabled' do
+ include_context 'feature flag disabled'
+ include_examples 'cannot add link'
+ end
+
+ context 'with insufficient permissions' do
+ include_context 'insufficient permissions'
+ include_examples 'cannot add link'
+ end
+ end
+
+ context 'with Zoom link in the issue description' do
+ include_context 'with Zoom link'
+ include_examples 'cannot add link'
+
+ context 'but not at the end' do
+ include_context 'with Zoom link not at the end'
+ include_examples 'can add link'
+ end
+ end
+
+ context 'without issue description' do
+ include_context 'without issue description'
+ include_examples 'can add link'
+ end
+ end
+
+ describe '#can_add_link?' do
+ subject { service.can_add_link? }
+
+ context 'without Zoom link in the issue description' do
+ include_context 'without Zoom link'
+
+ it { is_expected.to eq(true) }
+
+ context 'when feature flag is disabled' do
+ include_context 'feature flag disabled'
+
+ it { is_expected.to eq(false) }
+ end
+
+ context 'with insufficient permissions' do
+ include_context 'insufficient permissions'
+
+ it { is_expected.to eq(false) }
+ end
+ end
+
+ context 'with Zoom link in the issue description' do
+ include_context 'with Zoom link'
+
+ it { is_expected.to eq(false) }
+ end
+ end
+
+ describe '#remove_link' do
+ shared_examples 'cannot remove link' do
+ it 'cannot remove the link' do
+ expect(result).to be_error
+ expect(result.message).to eq('Failed to remove a Zoom meeting')
+ end
+ end
+
+ subject(:result) { service.remove_link }
+
+ context 'with Zoom link in the issue description' do
+ include_context 'with Zoom link'
+
+ it 'removes the link from the issue description' do
+ expect(result).to be_success
+ expect(result.payload[:description])
+ .to eq(issue.description.delete_suffix("\n\n#{zoom_link}"))
+ end
+
+ context 'when feature flag is disabled' do
+ include_context 'feature flag disabled'
+ include_examples 'cannot remove link'
+ end
+
+ context 'with insufficient permissions' do
+ include_context 'insufficient permissions'
+ include_examples 'cannot remove link'
+ end
+
+ context 'but not at the end' do
+ include_context 'with Zoom link not at the end'
+ include_examples 'cannot remove link'
+ end
+ end
+
+ context 'without Zoom link in the issue description' do
+ include_context 'without Zoom link'
+ include_examples 'cannot remove link'
+ end
+
+ context 'without issue description' do
+ include_context 'without issue description'
+ include_examples 'cannot remove link'
+ end
+ end
+
+ describe '#can_remove_link?' do
+ subject { service.can_remove_link? }
+
+ context 'with Zoom link in the issue description' do
+ include_context 'with Zoom link'
+
+ it { is_expected.to eq(true) }
+
+ context 'when feature flag is disabled' do
+ include_context 'feature flag disabled'
+
+ it { is_expected.to eq(false) }
+ end
+
+ context 'with insufficient permissions' do
+ include_context 'insufficient permissions'
+
+ it { is_expected.to eq(false) }
+ end
+ end
+
+ context 'without Zoom link in the issue description' do
+ include_context 'without Zoom link'
+
+ it { is_expected.to eq(false) }
+ end
+ end
+
+ describe '#parse_link' do
+ subject { service.parse_link(description) }
+
+ context 'with valid Zoom links' do
+ where(:description) do
+ [
+ 'Some text https://zoom.us/j/123456789 more text',
+ 'Mixed https://zoom.us/j/123456789 http://example.com',
+ 'Multiple link https://zoom.us/my/name https://zoom.us/j/123456789'
+ ]
+ end
+
+ with_them do
+ it { is_expected.to eq('https://zoom.us/j/123456789') }
+ end
+ end
+
+ context 'with invalid Zoom links' do
+ where(:description) do
+ [
+ nil,
+ '',
+ 'Text only',
+ 'Non-Zoom http://example.com',
+ 'Almost Zoom http://zoom.us'
+ ]
+ end
+
+ with_them do
+ it { is_expected.to eq(nil) }
+ end
+ end
+ end
+end