Commit 14b4120f authored by Serena Fang's avatar Serena Fang Committed by Douglas Barbosa Alexandre

Add specs for group token name

Add specs to user_spec and user_type_spec
parent 7fa72910
......@@ -52,10 +52,13 @@ RSpec.describe GitlabSchema.types['User'] do
let_it_be(:user) { create(:user) }
let_it_be(:requested_user) { create(:user, name: 'John Smith') }
let_it_be(:requested_project_bot) { create(:user, :project_bot, name: 'Project bot') }
let_it_be(:requested_group_bot) { create(:user, :project_bot, name: 'Group bot') }
let_it_be(:project) { create(:project, :public) }
let_it_be(:group) { create(:group, :public) }
before do
project.add_maintainer(requested_project_bot)
group.add_maintainer(requested_group_bot)
end
let(:username) { requested_user.username }
......@@ -123,6 +126,50 @@ RSpec.describe GitlabSchema.types['User'] do
end
end
end
context 'a group bot' do
let(:username) { requested_group_bot.username }
context 'when requester is nil' do
let(:current_user) { nil }
it 'returns `****`' do
expect(user_name).to eq('****')
end
end
context 'when the requester is not a group member' do
it 'returns `Group bot` for a non group member in a public group' do
expect(user_name).to eq('Group bot')
end
context 'in a private group' do
let(:group) { create(:group, :private) }
it 'returns `****` for a non group member in a private group' do
expect(user_name).to eq('****')
end
end
end
context 'with a group member' do
before do
group.add_guest(user)
end
it 'returns `Group bot` for a group member' do
expect(user_name).to eq('Group bot')
end
context 'in a private group' do
let(:group) { create(:group, :private) }
it 'returns `Group bot` for a group member in a private group' do
expect(user_name).to eq('Group bot')
end
end
end
end
end
end
......@@ -142,6 +189,14 @@ RSpec.describe GitlabSchema.types['User'] do
expect(subject).to eq('Project bot')
end
end
context 'a group bot' do
let(:username) { requested_group_bot.username }
it 'returns name' do
expect(subject).to eq('Group bot')
end
end
end
end
......
......@@ -78,6 +78,63 @@ RSpec.describe API::Entities::User do
end
end
context 'with group bot user' do
let(:group) { create(:group) }
let(:user) { create(:user, :project_bot, name: 'group bot') }
before do
group.add_maintainer(user)
end
it 'exposes user as a bot' do
expect(subject[:bot]).to eq(true)
end
context 'when the requester is not a group member' do
context 'with a public group' do
it 'exposes group bot user name' do
expect(subject[:name]).to eq('group bot')
end
end
context 'with a private group' do
let(:group) { create(:group, :private) }
it 'does not expose group bot user name' do
expect(subject[:name]).to eq('****')
end
end
end
context 'when the requester is nil' do
let(:current_user) { nil }
it 'does not expose group bot user name' do
expect(subject[:name]).to eq('****')
end
end
context 'when the requester is a group maintainer' do
let(:current_user) { create(:user) }
before do
group.add_maintainer(current_user)
end
it 'exposes group bot user name' do
expect(subject[:name]).to eq('group bot')
end
end
context 'when the requester is an admin' do
let(:current_user) { create(:user, :admin) }
it 'exposes group bot user name', :enable_admin_mode do
expect(subject[:name]).to eq('group bot')
end
end
end
it 'exposes local_time' do
local_time = '2:30 PM'
expect(entity).to receive(:local_time).with(timezone).and_return(local_time)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment