2021-01-03 14:25:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
RSpec.describe InviteMembersHelper do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:developer) { create(:user, developer_projects: [project]) }
|
|
|
|
let(:owner) { project.owner }
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'with project' do
|
|
|
|
before do
|
|
|
|
assign(:project, project)
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe "#directly_invite_members?" do
|
|
|
|
context 'when the user is an owner' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user) { owner }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
allow(helper).to receive(:experiment_enabled?).with(:invite_members_version_a) { false }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(helper.directly_invite_members?).to eq false
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'returns true' do
|
|
|
|
allow(helper).to receive(:experiment_enabled?).with(:invite_members_version_a) { true }
|
|
|
|
|
|
|
|
expect(helper.directly_invite_members?).to eq true
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'when the user is a developer' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user) { developer }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
allow(helper).to receive(:experiment_enabled?).with(:invite_members_version_a) { true }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(helper.directly_invite_members?).to eq false
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe "#indirectly_invite_members?" do
|
|
|
|
context 'when a user is a developer' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user) { developer }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
allow(helper).to receive(:experiment_enabled?).with(:invite_members_version_b) { false }
|
|
|
|
|
|
|
|
expect(helper.indirectly_invite_members?).to eq false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
allow(helper).to receive(:experiment_enabled?).with(:invite_members_version_b) { true }
|
|
|
|
|
|
|
|
expect(helper.indirectly_invite_members?).to eq true
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'when a user is an owner' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user) { owner }
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'returns false' do
|
|
|
|
allow(helper).to receive(:experiment_enabled?).with(:invite_members_version_b) { true }
|
|
|
|
|
|
|
|
expect(helper.indirectly_invite_members?).to eq false
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'with group' do
|
|
|
|
let_it_be(:group) { create(:group) }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe "#invite_group_members?" do
|
|
|
|
context 'when the user is an owner' do
|
|
|
|
before do
|
|
|
|
group.add_owner(owner)
|
|
|
|
allow(helper).to receive(:current_user) { owner }
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'returns false' do
|
|
|
|
allow(helper).to receive(:experiment_enabled?).with(:invite_members_empty_group_version_a) { false }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(helper.invite_group_members?(group)).to eq false
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'returns true' do
|
|
|
|
allow(helper).to receive(:experiment_enabled?).with(:invite_members_empty_group_version_a) { true }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(helper.invite_group_members?(group)).to eq true
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'when the user is a developer' do
|
|
|
|
before do
|
|
|
|
group.add_developer(developer)
|
|
|
|
allow(helper).to receive(:current_user) { developer }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
allow(helper).to receive(:experiment_enabled?).with(:invite_members_empty_group_version_a) { true }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(helper.invite_group_members?(group)).to eq false
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|