diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/workers/jira_connect | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/workers/jira_connect')
4 files changed, 75 insertions, 13 deletions
diff --git a/spec/workers/jira_connect/sync_branch_worker_spec.rb b/spec/workers/jira_connect/sync_branch_worker_spec.rb index 4aa2f89de7b..c8453064b0d 100644 --- a/spec/workers/jira_connect/sync_branch_worker_spec.rb +++ b/spec/workers/jira_connect/sync_branch_worker_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe JiraConnect::SyncBranchWorker do + include AfterNextHelpers + describe '#perform' do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, :repository, group: group) } @@ -67,7 +69,7 @@ RSpec.describe JiraConnect::SyncBranchWorker do context 'with update_sequence_id' do let(:update_sequence_id) { 1 } - let(:request_url) { 'https://sample.atlassian.net/rest/devinfo/0.10/bulk' } + let(:request_path) { '/rest/devinfo/0.10/bulk' } let(:request_body) do { repositories: [ @@ -78,14 +80,13 @@ RSpec.describe JiraConnect::SyncBranchWorker do update_sequence_id: update_sequence_id ) ] - }.to_json + } end subject { described_class.new.perform(project_id, branch_name, commit_shas, update_sequence_id) } it 'sends the reqeust with custom update_sequence_id' do - expect(Atlassian::JiraConnect::Client).to receive(:post) - .with(URI(request_url), headers: anything, body: request_body) + expect_next(Atlassian::JiraConnect::Client).to receive(:post).with(request_path, request_body) subject end diff --git a/spec/workers/jira_connect/sync_builds_worker_spec.rb b/spec/workers/jira_connect/sync_builds_worker_spec.rb new file mode 100644 index 00000000000..7c58803d778 --- /dev/null +++ b/spec/workers/jira_connect/sync_builds_worker_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::JiraConnect::SyncBuildsWorker do + include AfterNextHelpers + include ServicesHelper + + describe '#perform' do + let_it_be(:pipeline) { create(:ci_pipeline) } + + let(:sequence_id) { Random.random_number(1..10_000) } + let(:pipeline_id) { pipeline.id } + + subject { described_class.new.perform(pipeline_id, sequence_id) } + + context 'when pipeline exists' do + it 'calls the Jira sync service' do + expect_next(::JiraConnect::SyncService, pipeline.project) + .to receive(:execute).with(pipelines: contain_exactly(pipeline), update_sequence_id: sequence_id) + + subject + end + end + + context 'when pipeline does not exist' do + let(:pipeline_id) { non_existing_record_id } + + it 'does not call the sync service' do + expect_next(::JiraConnect::SyncService).not_to receive(:execute) + + subject + end + end + + context 'when the feature flag is disabled' do + before do + stub_feature_flags(jira_sync_builds: false) + end + + it 'does not call the sync service' do + expect_next(::JiraConnect::SyncService).not_to receive(:execute) + + subject + end + end + + context 'when the feature flag is enabled for this project' do + before do + stub_feature_flags(jira_sync_builds: pipeline.project) + end + + it 'calls the sync service' do + expect_next(::JiraConnect::SyncService).to receive(:execute) + + 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 index b3c0db4f260..1a40aa2b3ad 100644 --- a/spec/workers/jira_connect/sync_merge_request_worker_spec.rb +++ b/spec/workers/jira_connect/sync_merge_request_worker_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe JiraConnect::SyncMergeRequestWorker do + include AfterNextHelpers + describe '#perform' do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, :repository, group: group) } @@ -33,7 +35,7 @@ RSpec.describe JiraConnect::SyncMergeRequestWorker do context 'with update_sequence_id' do let(:update_sequence_id) { 1 } - let(:request_url) { 'https://sample.atlassian.net/rest/devinfo/0.10/bulk' } + let(:request_path) { '/rest/devinfo/0.10/bulk' } let(:request_body) do { repositories: [ @@ -43,14 +45,13 @@ RSpec.describe JiraConnect::SyncMergeRequestWorker do update_sequence_id: update_sequence_id ) ] - }.to_json + } end subject { described_class.new.perform(merge_request_id, update_sequence_id) } it 'sends the request with custom update_sequence_id' do - expect(Atlassian::JiraConnect::Client).to receive(:post) - .with(URI(request_url), headers: anything, body: request_body) + expect_next(Atlassian::JiraConnect::Client).to receive(:post).with(request_path, request_body) subject end diff --git a/spec/workers/jira_connect/sync_project_worker_spec.rb b/spec/workers/jira_connect/sync_project_worker_spec.rb index 25210de828c..f7fa565d534 100644 --- a/spec/workers/jira_connect/sync_project_worker_spec.rb +++ b/spec/workers/jira_connect/sync_project_worker_spec.rb @@ -36,7 +36,7 @@ RSpec.describe JiraConnect::SyncProjectWorker, factory_default: :keep do end it_behaves_like 'an idempotent worker' do - let(:request_url) { 'https://sample.atlassian.net/rest/devinfo/0.10/bulk' } + let(:request_path) { '/rest/devinfo/0.10/bulk' } let(:request_body) do { repositories: [ @@ -46,13 +46,13 @@ RSpec.describe JiraConnect::SyncProjectWorker, factory_default: :keep do update_sequence_id: update_sequence_id ) ] - }.to_json + } end it 'sends the request with custom update_sequence_id' do - expect(Atlassian::JiraConnect::Client).to receive(:post) - .exactly(IdempotentWorkerHelper::WORKER_EXEC_TIMES).times - .with(URI(request_url), headers: anything, body: request_body) + allow_next_instances_of(Atlassian::JiraConnect::Client, IdempotentWorkerHelper::WORKER_EXEC_TIMES) do |client| + expect(client).to receive(:post).with(request_path, request_body) + end subject end |