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:
Diffstat (limited to 'spec/workers/jira_connect/sync_branch_worker_spec.rb')
-rw-r--r--spec/workers/jira_connect/sync_branch_worker_spec.rb89
1 files changed, 37 insertions, 52 deletions
diff --git a/spec/workers/jira_connect/sync_branch_worker_spec.rb b/spec/workers/jira_connect/sync_branch_worker_spec.rb
index c8453064b0d..7c715f36fb4 100644
--- a/spec/workers/jira_connect/sync_branch_worker_spec.rb
+++ b/spec/workers/jira_connect/sync_branch_worker_spec.rb
@@ -13,82 +13,67 @@ RSpec.describe JiraConnect::SyncBranchWorker do
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) }
+ let(:update_sequence_id) { 1 }
def expect_jira_sync_service_execute(args)
- expect_next_instance_of(JiraConnect::SyncService) do |instance|
- expect(instance).to receive(:execute).with(args.merge(update_sequence_id: nil))
+ expect_next_instances_of(JiraConnect::SyncService, IdempotentWorkerHelper::WORKER_EXEC_TIMES) 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
+ it_behaves_like 'an idempotent worker' do
+ let(:job_args) { [project_id, branch_name, commit_shas, update_sequence_id] }
- 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
+ before do
+ stub_request(:post, 'https://sample.atlassian.net/rest/devinfo/0.10/bulk').to_return(status: 200, body: '', headers: {})
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
+ commits: project.commits_by(oids: commit_shas),
+ update_sequence_id: update_sequence_id
)
subject
end
- end
- context 'when project no longer exists' do
- let(:project_id) { non_existing_record_id }
+ context 'without branch name' do
+ let(:branch_name) { nil }
- it 'does not call JiraConnect::SyncService' do
- expect(JiraConnect::SyncService).not_to receive(:new)
+ it 'calls JiraConnect::SyncService#execute' do
+ expect_jira_sync_service_execute(
+ branches: nil,
+ commits: project.commits_by(oids: commit_shas),
+ update_sequence_id: update_sequence_id
+ )
- subject
+ subject
+ end
end
- end
- context 'with update_sequence_id' do
- let(:update_sequence_id) { 1 }
- let(:request_path) { '/rest/devinfo/0.10/bulk' }
- let(:request_body) do
- {
- repositories: [
- Atlassian::JiraConnect::Serializers::RepositoryEntity.represent(
- project,
- commits: project.commits_by(oids: commit_shas),
- branches: [project.repository.find_branch(branch_name)],
- update_sequence_id: update_sequence_id
- )
- ]
- }
+ 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,
+ update_sequence_id: update_sequence_id
+ )
+
+ subject
+ end
end
- subject { described_class.new.perform(project_id, branch_name, commit_shas, update_sequence_id) }
+ context 'when project no longer exists' do
+ let(:project_id) { non_existing_record_id }
- it 'sends the reqeust with custom update_sequence_id' do
- expect_next(Atlassian::JiraConnect::Client).to receive(:post).with(request_path, request_body)
+ it 'does not call JiraConnect::SyncService' do
+ expect(JiraConnect::SyncService).not_to receive(:new)
- subject
+ subject
+ end
end
end
end