2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Members::CreateService do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project_user) { create(:user) }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(user)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
it 'adds user to members' do
|
|
|
|
params = { user_ids: project_user.id.to_s, access_level: Gitlab::Access::GUEST }
|
2018-03-27 19:54:05 +05:30
|
|
|
result = described_class.new(user, params).execute(project)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(result[:status]).to eq(:success)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(project.users).to include project_user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds no user to members' do
|
|
|
|
params = { user_ids: '', access_level: Gitlab::Access::GUEST }
|
2018-03-27 19:54:05 +05:30
|
|
|
result = described_class.new(user, params).execute(project)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(result[:status]).to eq(:error)
|
|
|
|
expect(result[:message]).to be_present
|
|
|
|
expect(project.users).not_to include project_user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'limits the number of users to 100' do
|
|
|
|
user_ids = 1.upto(101).to_a.join(',')
|
|
|
|
params = { user_ids: user_ids, access_level: Gitlab::Access::GUEST }
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
result = described_class.new(user, params).execute(project)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
expect(result[:status]).to eq(:error)
|
|
|
|
expect(result[:message]).to be_present
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(project.users).not_to include project_user
|
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
it 'does not add an invalid member' do
|
|
|
|
params = { user_ids: project_user.id.to_s, access_level: -1 }
|
|
|
|
result = described_class.new(user, params).execute(project)
|
|
|
|
|
|
|
|
expect(result[:status]).to eq(:error)
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(result[:message]).to include("#{project_user.username}: Access level is not included in the list")
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(project.users).not_to include project_user
|
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
it 'does not add a member with an existing invite' do
|
|
|
|
invited_member = create(:project_member, :invited, project: project)
|
|
|
|
|
|
|
|
params = { user_ids: invited_member.invite_email,
|
|
|
|
access_level: Gitlab::Access::GUEST }
|
|
|
|
result = described_class.new(user, params).execute(project)
|
|
|
|
|
|
|
|
expect(result[:status]).to eq(:error)
|
|
|
|
expect(result[:message]).to eq('Invite email has already been taken')
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|