debian-mirror-gitlab/spec/workers/group_import_worker_spec.rb

73 lines
2.1 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe GroupImportWorker do
2021-01-03 14:25:43 +05:30
let(:user) { create(:user) }
let(:group) { create(:group) }
2020-03-13 15:44:24 +05:30
subject { described_class.new }
2020-05-24 23:13:21 +05:30
before do
2021-01-03 14:25:43 +05:30
create(:group_import_state, group: group, user: user)
2020-05-24 23:13:21 +05:30
allow_next_instance_of(described_class) do |job|
allow(job).to receive(:jid).and_return(SecureRandom.hex(8))
end
end
2021-01-03 14:25:43 +05:30
describe 'sidekiq options' do
it 'disables retry' do
expect(described_class.sidekiq_options['retry']).to eq(false)
end
it 'disables dead' do
expect(described_class.sidekiq_options['dead']).to eq(false)
end
end
2020-03-13 15:44:24 +05:30
describe '#perform' do
context 'when it succeeds' do
2020-05-24 23:13:21 +05:30
before do
expect_next_instance_of(::Groups::ImportExport::ImportService) do |service|
expect(service).to receive(:execute)
end
end
2020-03-13 15:44:24 +05:30
2020-05-24 23:13:21 +05:30
it 'calls the ImportService' do
2020-03-13 15:44:24 +05:30
subject.perform(user.id, group.id)
end
2020-05-24 23:13:21 +05:30
2021-01-03 14:25:43 +05:30
it 'updates the existing state' do
expect { subject.perform(user.id, group.id) }
.not_to change { GroupImportState.count }
2020-06-23 00:09:42 +05:30
2021-01-03 14:25:43 +05:30
expect(group.import_state.reload).to be_finished
2020-06-23 00:09:42 +05:30
end
2020-03-13 15:44:24 +05:30
end
context 'when it fails' do
it 'raises an exception when params are invalid' do
expect_any_instance_of(::Groups::ImportExport::ImportService).not_to receive(:execute)
2020-04-22 19:07:51 +05:30
expect { subject.perform(non_existing_record_id, group.id) }.to raise_exception(ActiveRecord::RecordNotFound)
expect { subject.perform(user.id, non_existing_record_id) }.to raise_exception(ActiveRecord::RecordNotFound)
2020-03-13 15:44:24 +05:30
end
2020-05-24 23:13:21 +05:30
context 'import state' do
before do
expect_next_instance_of(::Groups::ImportExport::ImportService) do |service|
expect(service).to receive(:execute).and_raise(Gitlab::ImportExport::Error)
end
end
it 'sets the group import status to failed' do
expect { subject.perform(user.id, group.id) }.to raise_exception(Gitlab::ImportExport::Error)
2021-01-03 14:25:43 +05:30
expect(group.import_state.reload.status).to eq(-1)
2020-05-24 23:13:21 +05:30
end
end
2020-03-13 15:44:24 +05:30
end
end
end