summaryrefslogtreecommitdiff
path: root/spec/workers/group_import_worker_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
commit9f46488805e86b1bc341ea1620b866016c2ce5ed (patch)
treef9748c7e287041e37d6da49e0a29c9511dc34768 /spec/workers/group_import_worker_spec.rb
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
downloadgitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/workers/group_import_worker_spec.rb')
-rw-r--r--spec/workers/group_import_worker_spec.rb59
1 files changed, 57 insertions, 2 deletions
diff --git a/spec/workers/group_import_worker_spec.rb b/spec/workers/group_import_worker_spec.rb
index 641aa45c9b0..bb7dc116a08 100644
--- a/spec/workers/group_import_worker_spec.rb
+++ b/spec/workers/group_import_worker_spec.rb
@@ -8,13 +8,52 @@ describe GroupImportWorker do
subject { described_class.new }
+ before do
+ allow_next_instance_of(described_class) do |job|
+ allow(job).to receive(:jid).and_return(SecureRandom.hex(8))
+ end
+ end
+
describe '#perform' do
context 'when it succeeds' do
- it 'calls the ImportService' do
- expect_any_instance_of(::Groups::ImportExport::ImportService).to receive(:execute)
+ before do
+ expect_next_instance_of(::Groups::ImportExport::ImportService) do |service|
+ expect(service).to receive(:execute)
+ end
+ end
+ it 'calls the ImportService' do
subject.perform(user.id, group.id)
end
+
+ context 'import state' do
+ it 'creates group import' do
+ expect(group.import_state).to be_nil
+
+ subject.perform(user.id, group.id)
+ import_state = group.reload.import_state
+
+ expect(import_state).to be_instance_of(GroupImportState)
+ expect(import_state.status_name).to eq(:finished)
+ expect(import_state.jid).not_to be_empty
+ end
+
+ it 'sets the group import status to started' do
+ expect_next_instance_of(GroupImportState) do |import|
+ expect(import).to receive(:start!).and_call_original
+ end
+
+ subject.perform(user.id, group.id)
+ end
+
+ it 'sets the group import status to finished' do
+ expect_next_instance_of(GroupImportState) do |import|
+ expect(import).to receive(:finish!).and_call_original
+ end
+
+ subject.perform(user.id, group.id)
+ end
+ end
end
context 'when it fails' do
@@ -24,6 +63,22 @@ describe GroupImportWorker do
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)
end
+
+ 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_next_instance_of(GroupImportState) do |import|
+ expect(import).to receive(:fail_op).and_call_original
+ end
+
+ expect { subject.perform(user.id, group.id) }.to raise_exception(Gitlab::ImportExport::Error)
+ end
+ end
end
end
end