debian-mirror-gitlab/spec/workers/jira_connect/sync_branch_worker_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.1 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe JiraConnect::SyncBranchWorker do
2021-02-22 17:27:13 +05:30
include AfterNextHelpers
2021-09-30 23:02:18 +05:30
it_behaves_like 'worker with data consistency',
described_class,
data_consistency: :delayed
2020-11-24 15:15:51 +05:30
describe '#perform' do
2021-01-29 00:20:46 +05:30
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, group: group) }
let_it_be(:subscription) { create(:jira_connect_subscription, installation: create(:jira_connect_installation), namespace: group) }
2020-11-24 15:15:51 +05:30
let(:project_id) { project.id }
let(:branch_name) { 'master' }
let(:commit_shas) { %w(b83d6e3 5a62481) }
2021-03-08 18:12:59 +05:30
let(:update_sequence_id) { 1 }
2020-11-24 15:15:51 +05:30
2021-09-30 23:02:18 +05:30
def perform
described_class.new.perform(project_id, branch_name, commit_shas, update_sequence_id)
end
2020-11-24 15:15:51 +05:30
def expect_jira_sync_service_execute(args)
2021-09-30 23:02:18 +05:30
expect_next(JiraConnect::SyncService).to receive(:execute).with(args)
2020-11-24 15:15:51 +05:30
end
2021-09-30 23:02:18 +05:30
it 'calls JiraConnect::SyncService#execute' do
expect_jira_sync_service_execute(
branches: [instance_of(Gitlab::Git::Branch)],
commits: project.commits_by(oids: commit_shas),
update_sequence_id: update_sequence_id
)
2020-11-24 15:15:51 +05:30
2021-09-30 23:02:18 +05:30
perform
end
context 'without branch name' do
let(:branch_name) { nil }
2020-11-24 15:15:51 +05:30
it 'calls JiraConnect::SyncService#execute' do
expect_jira_sync_service_execute(
2021-09-30 23:02:18 +05:30
branches: nil,
2021-03-08 18:12:59 +05:30
commits: project.commits_by(oids: commit_shas),
update_sequence_id: update_sequence_id
2020-11-24 15:15:51 +05:30
)
2021-09-30 23:02:18 +05:30
perform
2020-11-24 15:15:51 +05:30
end
2021-09-30 23:02:18 +05:30
end
2021-01-29 00:20:46 +05:30
2021-09-30 23:02:18 +05:30
context 'without commits' do
let(:commit_shas) { nil }
2021-03-08 18:12:59 +05:30
2021-09-30 23:02:18 +05:30
it 'calls JiraConnect::SyncService#execute' do
expect_jira_sync_service_execute(
branches: [instance_of(Gitlab::Git::Branch)],
commits: nil,
update_sequence_id: update_sequence_id
)
2021-03-08 18:12:59 +05:30
2021-09-30 23:02:18 +05:30
perform
2021-01-29 00:20:46 +05:30
end
2021-09-30 23:02:18 +05:30
end
2021-01-29 00:20:46 +05:30
2021-09-30 23:02:18 +05:30
context 'when project no longer exists' do
let(:project_id) { non_existing_record_id }
2021-01-29 00:20:46 +05:30
2021-09-30 23:02:18 +05:30
it 'does not call JiraConnect::SyncService' do
expect(JiraConnect::SyncService).not_to receive(:new)
2021-01-29 00:20:46 +05:30
2021-09-30 23:02:18 +05:30
perform
2021-01-29 00:20:46 +05:30
end
end
2020-11-24 15:15:51 +05:30
end
end