2020-10-19 02:09:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe EnvironmentNamesFinder do
|
|
|
|
describe '#execute' do
|
|
|
|
let!(:group) { create(:group) }
|
2020-10-27 11:08:39 -04:00
|
|
|
let!(:public_project) { create(:project, :public, namespace: group) }
|
|
|
|
let!(:private_project) { create(:project, :private, namespace: group) }
|
2020-10-19 02:09:08 -04:00
|
|
|
let!(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2020-10-27 11:08:39 -04:00
|
|
|
create(:environment, name: 'gstg', project: public_project)
|
|
|
|
create(:environment, name: 'gprd', project: public_project)
|
|
|
|
create(:environment, name: 'gprd', project: private_project)
|
|
|
|
create(:environment, name: 'gcny', project: private_project)
|
2020-10-19 02:09:08 -04:00
|
|
|
end
|
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
context 'using a group' do
|
|
|
|
context 'with a group developer' do
|
|
|
|
it 'returns environment names for all projects' do
|
|
|
|
group.add_developer(user)
|
2020-10-19 02:09:08 -04:00
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
names = described_class.new(group, user).execute
|
2020-10-19 02:09:08 -04:00
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
expect(names).to eq(%w[gcny gprd gstg])
|
|
|
|
end
|
2020-10-19 02:09:08 -04:00
|
|
|
end
|
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
context 'with a group reporter' do
|
|
|
|
it 'returns environment names for all projects' do
|
|
|
|
group.add_reporter(user)
|
|
|
|
|
|
|
|
names = described_class.new(group, user).execute
|
2020-10-19 02:09:08 -04:00
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
expect(names).to eq(%w[gcny gprd gstg])
|
|
|
|
end
|
2020-10-19 02:09:08 -04:00
|
|
|
end
|
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
context 'with a public project reporter' do
|
|
|
|
it 'returns environment names for all public projects' do
|
|
|
|
public_project.add_reporter(user)
|
2020-10-19 02:09:08 -04:00
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
names = described_class.new(group, user).execute
|
2020-10-19 02:09:08 -04:00
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
expect(names).to eq(%w[gprd gstg])
|
|
|
|
end
|
2020-10-19 02:09:08 -04:00
|
|
|
end
|
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
context 'with a private project reporter' do
|
|
|
|
it 'returns environment names for all public projects' do
|
|
|
|
private_project.add_reporter(user)
|
|
|
|
|
|
|
|
names = described_class.new(group, user).execute
|
2020-10-19 02:09:08 -04:00
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
expect(names).to eq(%w[gcny gprd gstg])
|
|
|
|
end
|
2020-10-19 02:09:08 -04:00
|
|
|
end
|
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
context 'with a group guest' do
|
|
|
|
it 'returns environment names for all public projects' do
|
|
|
|
group.add_guest(user)
|
|
|
|
|
|
|
|
names = described_class.new(group, user).execute
|
|
|
|
|
|
|
|
expect(names).to eq(%w[gprd gstg])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a non-member' do
|
|
|
|
it 'returns environment names for all public projects' do
|
|
|
|
names = described_class.new(group, user).execute
|
|
|
|
|
|
|
|
expect(names).to eq(%w[gprd gstg])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without a user' do
|
|
|
|
it 'returns environment names for all public projects' do
|
|
|
|
names = described_class.new(group).execute
|
2020-10-19 02:09:08 -04:00
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
expect(names).to eq(%w[gprd gstg])
|
|
|
|
end
|
2020-10-19 02:09:08 -04:00
|
|
|
end
|
|
|
|
end
|
2020-10-21 23:08:25 -04:00
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
context 'using a public project' do
|
|
|
|
context 'with a project developer' do
|
|
|
|
it 'returns all the unique environment names' do
|
|
|
|
public_project.add_developer(user)
|
|
|
|
|
|
|
|
names = described_class.new(public_project, user).execute
|
|
|
|
|
|
|
|
expect(names).to eq(%w[gprd gstg])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a project reporter' do
|
|
|
|
it 'returns all the unique environment names' do
|
|
|
|
public_project.add_reporter(user)
|
|
|
|
|
|
|
|
names = described_class.new(public_project, user).execute
|
|
|
|
|
|
|
|
expect(names).to eq(%w[gprd gstg])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a project guest' do
|
|
|
|
it 'returns all the unique environment names' do
|
|
|
|
public_project.add_guest(user)
|
|
|
|
|
|
|
|
names = described_class.new(public_project, user).execute
|
2020-10-21 23:08:25 -04:00
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
expect(names).to eq(%w[gprd gstg])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a non-member' do
|
|
|
|
it 'returns all the unique environment names' do
|
|
|
|
names = described_class.new(public_project, user).execute
|
|
|
|
|
|
|
|
expect(names).to eq(%w[gprd gstg])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without a user' do
|
|
|
|
it 'returns all the unique environment names' do
|
|
|
|
names = described_class.new(public_project).execute
|
|
|
|
|
|
|
|
expect(names).to eq(%w[gprd gstg])
|
|
|
|
end
|
2020-10-21 23:08:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
context 'using a private project' do
|
|
|
|
context 'with a project developer' do
|
|
|
|
it 'returns all the unique environment names' do
|
|
|
|
private_project.add_developer(user)
|
|
|
|
|
|
|
|
names = described_class.new(private_project, user).execute
|
|
|
|
|
|
|
|
expect(names).to eq(%w[gcny gprd])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a project reporter' do
|
|
|
|
it 'returns all the unique environment names' do
|
|
|
|
private_project.add_reporter(user)
|
|
|
|
|
|
|
|
names = described_class.new(private_project, user).execute
|
|
|
|
|
|
|
|
expect(names).to eq(%w[gcny gprd])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a project guest' do
|
|
|
|
it 'does not return any environment names' do
|
|
|
|
private_project.add_guest(user)
|
|
|
|
|
|
|
|
names = described_class.new(private_project, user).execute
|
|
|
|
|
|
|
|
expect(names).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a non-member' do
|
|
|
|
it 'does not return any environment names' do
|
|
|
|
names = described_class.new(private_project, user).execute
|
|
|
|
|
|
|
|
expect(names).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without a user' do
|
|
|
|
it 'does not return any environment names' do
|
|
|
|
names = described_class.new(private_project).execute
|
2020-10-21 23:08:25 -04:00
|
|
|
|
2020-10-27 11:08:39 -04:00
|
|
|
expect(names).to be_empty
|
|
|
|
end
|
2020-10-21 23:08:25 -04:00
|
|
|
end
|
|
|
|
end
|
2020-10-19 02:09:08 -04:00
|
|
|
end
|
|
|
|
end
|