Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-07-01 00:09:49 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-01 00:09:49 +0300
commit9877050db1dd1693c672a6b29a356c5b2a7edce0 (patch)
tree07e8b3837333294337121b96f296eb5622a8a7e9 /spec/serializers
parent370736438075748c36abd7fd7dd32a8ef98048f9 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/member_user_entity_spec.rb70
1 files changed, 65 insertions, 5 deletions
diff --git a/spec/serializers/member_user_entity_spec.rb b/spec/serializers/member_user_entity_spec.rb
index 0e6d4bcc3fb..85f29845d65 100644
--- a/spec/serializers/member_user_entity_spec.rb
+++ b/spec/serializers/member_user_entity_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe MemberUserEntity do
let(:entity_hash) { entity.as_json }
it 'matches json schema' do
- expect(entity.to_json).to match_schema('entities/member_user')
+ expect(entity.to_json).to match_schema('entities/member_user_default')
end
it 'correctly exposes `avatar_url`' do
@@ -27,10 +27,8 @@ RSpec.describe MemberUserEntity do
expect(entity_hash[:blocked]).to be(true)
end
- it 'correctly exposes `two_factor_enabled`' do
- allow(user).to receive(:two_factor_enabled?).and_return(true)
-
- expect(entity_hash[:two_factor_enabled]).to be(true)
+ it 'does not expose `two_factor_enabled` by default' do
+ expect(entity_hash[:two_factor_enabled]).to be(nil)
end
it 'correctly exposes `status.emoji`' do
@@ -44,4 +42,66 @@ RSpec.describe MemberUserEntity do
it 'correctly exposes `last_activity_on`' do
expect(entity_hash[:last_activity_on]).to be(user.last_activity_on)
end
+
+ context 'when options includes a source' do
+ let(:current_user) { create(:user) }
+ let(:options) { { current_user: current_user, source: source } }
+ let(:entity) { described_class.new(user, options) }
+
+ shared_examples 'correctly exposes user two_factor_enabled' do
+ context 'when the current_user has a role lower than minimum manage member role' do
+ before do
+ source.add_user(current_user, Gitlab::Access::DEVELOPER)
+ end
+
+ it 'does not expose user two_factor_enabled' do
+ expect(entity_hash[:two_factor_enabled]).to be(nil)
+ end
+
+ it 'matches json schema' do
+ expect(entity.to_json).to match_schema('entities/member_user_default')
+ end
+ end
+
+ context 'when the current user has a minimum manage member role or higher' do
+ before do
+ source.add_user(current_user, minimum_manage_member_role)
+ end
+
+ it 'matches json schema' do
+ expect(entity.to_json).to match_schema('entities/member_user_for_admin_member')
+ end
+
+ it 'exposes user two_factor_enabled' do
+ expect(entity_hash[:two_factor_enabled]).to be(false)
+ end
+ end
+
+ context 'when the current user is self' do
+ let(:current_user) { user }
+
+ it 'exposes user two_factor_enabled' do
+ expect(entity_hash[:two_factor_enabled]).to be(false)
+ end
+
+ it 'matches json schema' do
+ expect(entity.to_json).to match_schema('entities/member_user_for_admin_member')
+ end
+ end
+ end
+
+ context 'when the source is a group' do
+ let(:source) { create(:group) }
+ let(:minimum_manage_member_role) { Gitlab::Access::OWNER }
+
+ it_behaves_like 'correctly exposes user two_factor_enabled'
+ end
+
+ context 'when the source is a project' do
+ let(:source) { create(:project) }
+ let(:minimum_manage_member_role) { Gitlab::Access::MAINTAINER }
+
+ it_behaves_like 'correctly exposes user two_factor_enabled'
+ end
+ end
end