summaryrefslogtreecommitdiff
path: root/spec/workers/jira_connect
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 01:45:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 01:45:44 +0000
commit85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch)
tree9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/workers/jira_connect
parent15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff)
downloadgitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/workers/jira_connect')
-rw-r--r--spec/workers/jira_connect/sync_branch_worker_spec.rb65
-rw-r--r--spec/workers/jira_connect/sync_merge_request_worker_spec.rb30
2 files changed, 95 insertions, 0 deletions
diff --git a/spec/workers/jira_connect/sync_branch_worker_spec.rb b/spec/workers/jira_connect/sync_branch_worker_spec.rb
new file mode 100644
index 00000000000..2da3ea9d256
--- /dev/null
+++ b/spec/workers/jira_connect/sync_branch_worker_spec.rb
@@ -0,0 +1,65 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe JiraConnect::SyncBranchWorker do
+ describe '#perform' do
+ let_it_be(:project) { create(:project, :repository) }
+ let(:project_id) { project.id }
+ let(:branch_name) { 'master' }
+ let(:commit_shas) { %w(b83d6e3 5a62481) }
+
+ subject { described_class.new.perform(project_id, branch_name, commit_shas) }
+
+ def expect_jira_sync_service_execute(args)
+ expect_next_instance_of(JiraConnect::SyncService) do |instance|
+ expect(instance).to receive(:execute).with(args)
+ end
+ end
+
+ it 'calls JiraConnect::SyncService#execute' do
+ expect_jira_sync_service_execute(
+ branches: [instance_of(Gitlab::Git::Branch)],
+ commits: project.commits_by(oids: commit_shas)
+ )
+
+ subject
+ end
+
+ context 'without branch name' do
+ let(:branch_name) { nil }
+
+ it 'calls JiraConnect::SyncService#execute' do
+ expect_jira_sync_service_execute(
+ branches: nil,
+ commits: project.commits_by(oids: commit_shas)
+ )
+
+ subject
+ end
+ end
+
+ context 'without commits' do
+ let(:commit_shas) { nil }
+
+ it 'calls JiraConnect::SyncService#execute' do
+ expect_jira_sync_service_execute(
+ branches: [instance_of(Gitlab::Git::Branch)],
+ commits: nil
+ )
+
+ subject
+ end
+ end
+
+ context 'when project no longer exists' do
+ let(:project_id) { non_existing_record_id }
+
+ it 'does not call JiraConnect::SyncService' do
+ expect(JiraConnect::SyncService).not_to receive(:new)
+
+ subject
+ end
+ end
+ end
+end
diff --git a/spec/workers/jira_connect/sync_merge_request_worker_spec.rb b/spec/workers/jira_connect/sync_merge_request_worker_spec.rb
new file mode 100644
index 00000000000..764201e750a
--- /dev/null
+++ b/spec/workers/jira_connect/sync_merge_request_worker_spec.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe JiraConnect::SyncMergeRequestWorker do
+ describe '#perform' do
+ let(:merge_request) { create(:merge_request) }
+ let(:merge_request_id) { merge_request.id }
+
+ subject { described_class.new.perform(merge_request_id) }
+
+ it 'calls JiraConnect::SyncService#execute' do
+ expect_next_instance_of(JiraConnect::SyncService) do |service|
+ expect(service).to receive(:execute).with(merge_requests: [merge_request])
+ end
+
+ subject
+ end
+
+ context 'when MR no longer exists' do
+ let(:merge_request_id) { non_existing_record_id }
+
+ it 'does not call JiraConnect::SyncService' do
+ expect(JiraConnect::SyncService).not_to receive(:new)
+
+ subject
+ end
+ end
+ end
+end