debian-mirror-gitlab/spec/finders/environments/environment_names_finder_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

184 lines
5.1 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
2021-06-08 01:23:25 +05:30
RSpec.describe Environments::EnvironmentNamesFinder do
2021-01-03 14:25:43 +05:30
describe '#execute' do
let!(:group) { create(:group) }
2021-01-29 00:20:46 +05:30
let!(:public_project) { create(:project, :public, namespace: group) }
let!(:private_project) { create(:project, :private, namespace: group) }
2021-01-03 14:25:43 +05:30
let!(:user) { create(:user) }
before do
2021-01-29 00:20:46 +05:30
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)
2021-01-03 14:25:43 +05:30
end
2021-01-29 00:20:46 +05:30
context 'using a group' do
context 'with a group developer' do
it 'returns environment names for all projects' do
group.add_developer(user)
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
names = described_class.new(group, user).execute
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
expect(names).to eq(%w[gcny gprd gstg])
end
2021-01-03 14:25:43 +05:30
end
2021-01-29 00:20:46 +05:30
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
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
expect(names).to eq(%w[gcny gprd gstg])
end
2021-01-03 14:25:43 +05:30
end
2021-01-29 00:20:46 +05:30
context 'with a public project reporter' do
it 'returns environment names for all public projects' do
public_project.add_reporter(user)
names = described_class.new(group, user).execute
expect(names).to eq(%w[gprd gstg])
end
end
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
expect(names).to eq(%w[gcny gprd gstg])
end
end
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
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
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
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
expect(names).to eq(%w[gprd gstg])
end
2021-01-03 14:25:43 +05:30
end
end
2021-01-29 00:20:46 +05:30
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
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
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
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
2021-01-03 14:25:43 +05:30
end
end
2021-01-29 00:20:46 +05:30
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
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
expect(names).to be_empty
end
2021-01-03 14:25:43 +05:30
end
end
end
end