2021-03-08 18:12:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe MemberUserEntity do
|
2022-06-21 17:19:12 +05:30
|
|
|
let_it_be(:user) { create(:user, last_activity_on: Date.today) }
|
2021-03-08 18:12:59 +05:30
|
|
|
let_it_be(:emoji) { 'slight_smile' }
|
|
|
|
let_it_be(:user_status) { create(:user_status, user: user, emoji: emoji) }
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
let(:entity) { described_class.new(user) }
|
|
|
|
let(:entity_hash) { entity.as_json }
|
|
|
|
|
|
|
|
it 'matches json schema' do
|
2022-07-01 11:34:44 +05:30
|
|
|
expect(entity.to_json).to match_schema('entities/member_user_default')
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly exposes `avatar_url`' do
|
|
|
|
avatar_url = 'https://www.gravatar.com/avatar/c4637cb869d5f94c3193bde4f23d4cdc?s=80&d=identicon'
|
|
|
|
allow(user).to receive(:avatar_url).and_return(avatar_url)
|
|
|
|
|
|
|
|
expect(entity_hash[:avatar_url]).to match(avatar_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly exposes `blocked`' do
|
|
|
|
allow(user).to receive(:blocked?).and_return(true)
|
|
|
|
|
|
|
|
expect(entity_hash[:blocked]).to be(true)
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it 'correctly exposes `is_bot`' do
|
|
|
|
allow(user).to receive(:bot?).and_return(true)
|
|
|
|
|
|
|
|
expect(entity_hash[:is_bot]).to be(true)
|
|
|
|
end
|
|
|
|
|
2022-07-01 11:34:44 +05:30
|
|
|
it 'does not expose `two_factor_enabled` by default' do
|
|
|
|
expect(entity_hash[:two_factor_enabled]).to be(nil)
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly exposes `status.emoji`' do
|
|
|
|
expect(entity_hash[:status][:emoji]).to match(emoji)
|
|
|
|
end
|
2022-06-21 17:19:12 +05:30
|
|
|
|
|
|
|
it 'correctly exposes `created_at`' do
|
|
|
|
expect(entity_hash[:created_at]).to be(user.created_at)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly exposes `last_activity_on`' do
|
|
|
|
expect(entity_hash[:last_activity_on]).to be(user.last_activity_on)
|
|
|
|
end
|
2022-07-01 11:34:44 +05:30
|
|
|
|
|
|
|
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
|
2022-08-13 15:12:31 +05:30
|
|
|
source.add_member(current_user, Gitlab::Access::DEVELOPER)
|
2022-07-01 11:34:44 +05:30
|
|
|
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
|
2022-08-13 15:12:31 +05:30
|
|
|
source.add_member(current_user, minimum_manage_member_role)
|
2022-07-01 11:34:44 +05:30
|
|
|
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
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|