diff options
Diffstat (limited to 'spec/lib/bulk_imports/common/transformers/member_attributes_transformer_spec.rb')
-rw-r--r-- | spec/lib/bulk_imports/common/transformers/member_attributes_transformer_spec.rb | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/spec/lib/bulk_imports/common/transformers/member_attributes_transformer_spec.rb b/spec/lib/bulk_imports/common/transformers/member_attributes_transformer_spec.rb index 1c9ed4f0f97..4565de32c70 100644 --- a/spec/lib/bulk_imports/common/transformers/member_attributes_transformer_spec.rb +++ b/spec/lib/bulk_imports/common/transformers/member_attributes_transformer_spec.rb @@ -85,14 +85,15 @@ RSpec.describe BulkImports::Common::Transformers::MemberAttributesTransformer, f end end - describe 'source user id caching' do + describe 'source user id and username caching' do context 'when user gid is present' do - it 'caches source user id' do + it 'caches source user id and username' do gid = 'gid://gitlab/User/7' data = member_data(email: user.email, gid: gid) expect_next_instance_of(BulkImports::UsersMapper) do |mapper| expect(mapper).to receive(:cache_source_user_id).with('7', user.id) + expect(mapper).to receive(:cache_source_username).with('source_username', user.username) end subject.transform(context, data) @@ -108,6 +109,35 @@ RSpec.describe BulkImports::Common::Transformers::MemberAttributesTransformer, f subject.transform(context, data) end end + + context 'when username is nil' do + it 'caches source user id only' do + gid = 'gid://gitlab/User/7' + data = nil_username_member_data(email: user.email, gid: gid) + + expect_next_instance_of(BulkImports::UsersMapper) do |mapper| + expect(mapper).to receive(:cache_source_user_id).with('7', user.id) + expect(mapper).not_to receive(:cache_source_username) + end + + subject.transform(context, data) + end + end + + context 'when source username matches destination username' do + it 'caches source user id only' do + gid = 'gid://gitlab/User/7' + data = member_data(email: user.email, gid: gid) + data["user"]["username"] = user.username + + expect_next_instance_of(BulkImports::UsersMapper) do |mapper| + expect(mapper).to receive(:cache_source_user_id).with('7', user.id) + expect(mapper).not_to receive(:cache_source_username) + end + + subject.transform(context, data) + end + end end end end @@ -136,7 +166,24 @@ RSpec.describe BulkImports::Common::Transformers::MemberAttributesTransformer, f }, 'user' => { 'user_gid' => gid, - 'public_email' => email + 'public_email' => email, + 'username' => 'source_username' + } + } + end + + def nil_username_member_data(email: '', gid: nil, access_level: 30) + { + 'created_at' => '2020-01-01T00:00:00Z', + 'updated_at' => '2020-01-01T00:00:00Z', + 'expires_at' => nil, + 'access_level' => { + 'integer_value' => access_level + }, + 'user' => { + 'user_gid' => gid, + 'public_email' => email, + 'username' => nil } } end |