Commit 42295125 authored by Arturo Herrero's avatar Arturo Herrero

Test idempotent on propagation workers

Using 'an idempotent workers' shared example to test the idempotent of
the workers.
parent 847e5a5c
......@@ -4,16 +4,34 @@ require 'spec_helper'
RSpec.describe PropagateIntegrationGroupWorker do
describe '#perform' do
let!(:group1) { create(:group) }
let!(:group2) { create(:group) }
let!(:integration) { create(:redmine_service, :instance) }
let_it_be(:group1) { create(:group) }
let_it_be(:group2) { create(:group) }
let_it_be(:integration) { create(:redmine_service, :instance) }
it 'calls to BulkCreateIntegrationService' do
expect(BulkCreateIntegrationService).to receive(:new)
before do
allow(BulkCreateIntegrationService).to receive(:new)
.with(integration, match_array([group1, group2]), 'group')
.and_return(double(execute: nil))
end
it_behaves_like 'an idempotent worker' do
let(:job_args) { [integration.id, group1.id, group2.id] }
it 'calls to BulkCreateIntegrationService' do
expect(BulkCreateIntegrationService).to receive(:new)
.with(integration, match_array([group1, group2]), 'group')
.and_return(double(execute: nil))
subject
end
end
context 'with an invalid integration id' do
it 'returns without failure' do
expect(BulkCreateIntegrationService).not_to receive(:new)
subject.perform(integration.id, group1.id, group2.id)
subject.perform(0, group1.id, group2.id)
end
end
end
end
......@@ -4,17 +4,35 @@ require 'spec_helper'
RSpec.describe PropagateIntegrationInheritWorker do
describe '#perform' do
let(:integration) { create(:redmine_service, :instance) }
let!(:integration1) { create(:redmine_service, inherit_from_id: integration.id) }
let!(:integration2) { create(:bugzilla_service, inherit_from_id: integration.id) }
let!(:integration3) { create(:redmine_service) }
let_it_be(:integration) { create(:redmine_service, :instance) }
let_it_be(:integration1) { create(:redmine_service, inherit_from_id: integration.id) }
let_it_be(:integration2) { create(:bugzilla_service, inherit_from_id: integration.id) }
let_it_be(:integration3) { create(:redmine_service) }
it 'calls to BulkCreateIntegrationService' do
expect(BulkUpdateIntegrationService).to receive(:new)
before do
allow(BulkUpdateIntegrationService).to receive(:new)
.with(integration, match_array(integration1))
.and_return(double(execute: nil))
end
it_behaves_like 'an idempotent worker' do
let(:job_args) { [integration.id, integration1.id, integration3.id] }
it 'calls to BulkCreateIntegrationService' do
expect(BulkUpdateIntegrationService).to receive(:new)
.with(integration, match_array(integration1))
.and_return(double(execute: nil))
subject
end
end
context 'with an invalid integration id' do
it 'returns without failure' do
expect(BulkUpdateIntegrationService).not_to receive(:new)
subject.perform(integration.id, integration1.id, integration3.id)
subject.perform(0, integration1.id, integration3.id)
end
end
end
end
......@@ -4,16 +4,34 @@ require 'spec_helper'
RSpec.describe PropagateIntegrationProjectWorker do
describe '#perform' do
let!(:project1) { create(:project) }
let!(:project2) { create(:project) }
let!(:integration) { create(:redmine_service, :instance) }
let_it_be(:project1) { create(:project) }
let_it_be(:project2) { create(:project) }
let_it_be(:integration) { create(:redmine_service, :instance) }
it 'calls to BulkCreateIntegrationService' do
expect(BulkCreateIntegrationService).to receive(:new)
before do
allow(BulkCreateIntegrationService).to receive(:new)
.with(integration, match_array([project1, project2]), 'project')
.and_return(double(execute: nil))
end
it_behaves_like 'an idempotent worker' do
let(:job_args) { [integration.id, project1.id, project2.id] }
it 'calls to BulkCreateIntegrationService' do
expect(BulkCreateIntegrationService).to receive(:new)
.with(integration, match_array([project1, project2]), 'project')
.and_return(double(execute: nil))
subject
end
end
context 'with an invalid integration id' do
it 'returns without failure' do
expect(BulkCreateIntegrationService).not_to receive(:new)
subject.perform(integration.id, project1.id, project2.id)
subject.perform(0, project1.id, project2.id)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment