Welcome to mirror list, hosted at ThFree Co, Russian Federation.

environments_finder_spec.rb « environments « finders « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e3b1a121497ddf9688c7ace3e2c07616b9ec5eb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Environments::EnvironmentsFinder do
  let_it_be(:project) { create(:project, :repository) }
  let_it_be(:user) { project.creator }
  let_it_be(:environment) { create(:environment, :available, project: project) }
  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) }

  before do
    project.add_maintainer(user)
  end

  describe '#execute' do
    context 'with states parameter' do
      let_it_be(:stopped_environment) { create(:environment, :stopped, project: project) }

      it 'returns environments with the requested state' do
        result = described_class.new(project, user, states: 'available').execute

        expect(result).to contain_exactly(environment, environment_available)
      end

      it 'returns environments with any of the requested states' do
        result = described_class.new(project, user, states: %w[available stopped]).execute

        expect(result).to contain_exactly(environment, environment_stopped, environment_available, stopped_environment)
      end

      it 'raises exception when requested state is invalid' do
        expect { described_class.new(project, user, states: %w[invalid stopped]).execute }.to(
          raise_error(described_class::InvalidStatesError, 'Requested states are invalid')
        )
      end

      context 'works with symbols' do
        it 'returns environments with the requested state' do
          result = described_class.new(project, user, states: :available).execute

          expect(result).to contain_exactly(environment, environment_available)
        end

        it 'returns environments with any of the requested states' do
          result = described_class.new(project, user, states: [:available, :stopped]).execute

          expect(result).to contain_exactly(environment, environment_stopped, environment_available, stopped_environment)
        end
      end
    end

    context 'with search and states' do
      let_it_be(:environment_available_b) { create(:environment, :available, name: 'test/foldered-env', project: project) }

      it 'searches environments by name and state' do
        result = described_class.new(project, user, search: 'test', states: :available).execute

        expect(result).to contain_exactly(environment_available, environment_available_b)
      end

      it 'searches environments by name inside folder and state' do
        result = described_class.new(project, user, search: 'folder', states: :available).execute

        expect(result).to contain_exactly(environment_available_b)
      end

      context 'when enable_environments_search_within_folder FF is disabled' do
        before do
          stub_feature_flags(enable_environments_search_within_folder: false)
        end

        it 'ignores name inside folder' do
          result = described_class.new(project, user, search: 'folder', states: :available).execute

          expect(result).to be_empty
        end
      end
    end

    context 'with id' do
      it 'searches environments by name and id' do
        result = described_class.new(project, user, search: 'test', environment_ids: [environment_available.id]).execute

        expect(result).to contain_exactly(environment_available)
      end
    end

    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
  end
end