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

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

76 lines
2.8 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2021-06-08 01:23:25 +05:30
RSpec.describe Environments::EnvironmentsFinder do
2021-09-30 23:02:18 +05:30
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { project.creator }
let_it_be(:environment) { create(:environment, :available, project: project) }
2022-10-11 01:57:18 +05:30
let_it_be(:environment_stopped) { create(:environment, :stopped, name: 'test/test2', project: project) }
let_it_be(:environment_available) { create(:environment, :available, name: 'test/test3', project: project) }
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
before do
project.add_maintainer(user)
end
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
describe '#execute' do
context 'with states parameter' do
2021-09-30 23:02:18 +05:30
let_it_be(:stopped_environment) { create(:environment, :stopped, project: project) }
2020-04-22 19:07:51 +05:30
it 'returns environments with the requested state' do
2021-04-29 21:17:54 +05:30
result = described_class.new(project, user, states: 'available').execute
2020-04-22 19:07:51 +05:30
2021-09-30 23:02:18 +05:30
expect(result).to contain_exactly(environment, environment_available)
2020-04-22 19:07:51 +05:30
end
it 'returns environments with any of the requested states' do
2021-04-29 21:17:54 +05:30
result = described_class.new(project, user, states: %w(available stopped)).execute
2020-04-22 19:07:51 +05:30
2021-09-30 23:02:18 +05:30
expect(result).to contain_exactly(environment, environment_stopped, environment_available, stopped_environment)
2020-04-22 19:07:51 +05:30
end
it 'raises exception when requested state is invalid' do
2021-04-29 21:17:54 +05:30
expect { described_class.new(project, user, states: %w(invalid stopped)).execute }.to(
2020-04-22 19:07:51 +05:30
raise_error(described_class::InvalidStatesError, 'Requested states are invalid')
)
end
context 'works with symbols' do
it 'returns environments with the requested state' do
2021-04-29 21:17:54 +05:30
result = described_class.new(project, user, states: :available).execute
2020-04-22 19:07:51 +05:30
2021-09-30 23:02:18 +05:30
expect(result).to contain_exactly(environment, environment_available)
2020-04-22 19:07:51 +05:30
end
it 'returns environments with any of the requested states' do
2021-04-29 21:17:54 +05:30
result = described_class.new(project, user, states: [:available, :stopped]).execute
2020-04-22 19:07:51 +05:30
2021-09-30 23:02:18 +05:30
expect(result).to contain_exactly(environment, environment_stopped, environment_available, stopped_environment)
2020-04-22 19:07:51 +05:30
end
end
end
context 'with search and states' do
it 'searches environments by name and state' do
2021-04-29 21:17:54 +05:30
result = described_class.new(project, user, search: 'test', states: :available).execute
2020-04-22 19:07:51 +05:30
2021-09-30 23:02:18 +05:30
expect(result).to contain_exactly(environment_available)
end
end
context 'with id' do
it 'searches environments by name and state' do
result = described_class.new(project, user, search: 'test', environment_ids: [environment_available.id]).execute
expect(result).to contain_exactly(environment_available)
2020-04-22 19:07:51 +05:30
end
end
2022-10-11 01:57:18 +05:30
it 'filters environments by type' do
result = described_class.new(project, user, type: 'test').execute
expect(result).to contain_exactly(environment_stopped, environment_available)
end
2020-04-22 19:07:51 +05:30
end
2017-08-17 22:00:37 +05:30
end