diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/lib/bulk_imports/groups/loaders | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/lib/bulk_imports/groups/loaders')
3 files changed, 80 insertions, 9 deletions
diff --git a/spec/lib/bulk_imports/groups/loaders/group_loader_spec.rb b/spec/lib/bulk_imports/groups/loaders/group_loader_spec.rb index b14dfc615a9..183292722d2 100644 --- a/spec/lib/bulk_imports/groups/loaders/group_loader_spec.rb +++ b/spec/lib/bulk_imports/groups/loaders/group_loader_spec.rb @@ -7,21 +7,20 @@ RSpec.describe BulkImports::Groups::Loaders::GroupLoader do let(:user) { create(:user) } let(:data) { { foo: :bar } } let(:service_double) { instance_double(::Groups::CreateService) } - let(:entity) { create(:bulk_import_entity) } - let(:context) do - instance_double( - BulkImports::Pipeline::Context, - entity: entity, - current_user: user - ) - end + let(:bulk_import) { create(:bulk_import, user: user) } + let(:entity) { create(:bulk_import_entity, bulk_import: bulk_import) } + let(:context) { BulkImports::Pipeline::Context.new(entity) } subject { described_class.new } context 'when user can create group' do shared_examples 'calls Group Create Service to create a new group' do it 'calls Group Create Service to create a new group' do - expect(::Groups::CreateService).to receive(:new).with(context.current_user, data).and_return(service_double) + expect(::Groups::CreateService) + .to receive(:new) + .with(context.current_user, data) + .and_return(service_double) + expect(service_double).to receive(:execute) expect(entity).to receive(:update!) diff --git a/spec/lib/bulk_imports/groups/loaders/labels_loader_spec.rb b/spec/lib/bulk_imports/groups/loaders/labels_loader_spec.rb new file mode 100644 index 00000000000..ac2f9c8cb1d --- /dev/null +++ b/spec/lib/bulk_imports/groups/loaders/labels_loader_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::Groups::Loaders::LabelsLoader do + describe '#load' do + let(:user) { create(:user) } + let(:group) { create(:group) } + let(:entity) { create(:bulk_import_entity, group: group) } + let(:context) { BulkImports::Pipeline::Context.new(entity) } + + let(:data) do + { + 'title' => 'label', + 'description' => 'description', + 'color' => '#FFFFFF' + } + end + + it 'creates the label' do + expect { subject.load(context, data) }.to change(Label, :count).by(1) + + label = group.labels.first + + expect(label.title).to eq(data['title']) + expect(label.description).to eq(data['description']) + expect(label.color).to eq(data['color']) + end + end +end diff --git a/spec/lib/bulk_imports/groups/loaders/members_loader_spec.rb b/spec/lib/bulk_imports/groups/loaders/members_loader_spec.rb new file mode 100644 index 00000000000..d552578e7be --- /dev/null +++ b/spec/lib/bulk_imports/groups/loaders/members_loader_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::Groups::Loaders::MembersLoader do + describe '#load' do + let_it_be(:user_importer) { create(:user) } + let_it_be(:user_member) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:bulk_import) { create(:bulk_import, user: user_importer) } + let_it_be(:entity) { create(:bulk_import_entity, bulk_import: bulk_import, group: group) } + let_it_be(:context) { BulkImports::Pipeline::Context.new(entity) } + + let_it_be(:data) do + { + 'user_id' => user_member.id, + 'created_by_id' => user_importer.id, + 'access_level' => 30, + 'created_at' => '2020-01-01T00:00:00Z', + 'updated_at' => '2020-01-01T00:00:00Z', + 'expires_at' => nil + } + end + + it 'does nothing when there is no data' do + expect { subject.load(context, nil) }.not_to change(GroupMember, :count) + end + + it 'creates the member' do + expect { subject.load(context, data) }.to change(GroupMember, :count).by(1) + + member = group.members.last + + expect(member.user).to eq(user_member) + expect(member.created_by).to eq(user_importer) + expect(member.access_level).to eq(30) + expect(member.created_at).to eq('2020-01-01T00:00:00Z') + expect(member.updated_at).to eq('2020-01-01T00:00:00Z') + expect(member.expires_at).to eq(nil) + end + end +end |