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

projects_finder_spec.rb « namespaces « finders « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0f48aa6a9f415a795e62cc200d7643bb9cbeef62 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Namespaces::ProjectsFinder do
  let_it_be(:current_user) { create(:user) }
  let_it_be(:namespace) { create(:group, :public) }
  let_it_be(:subgroup) { create(:group, parent: namespace) }
  let_it_be(:project_1) { create(:project, :public, group: namespace, path: 'project', name: 'Project') }
  let_it_be(:project_2) { create(:project, :public, group: namespace, path: 'test-project', name: 'Test Project') }
  let_it_be(:project_3) { create(:project, :public, path: 'sub-test-project', group: subgroup, name: 'Sub Test Project') }
  let_it_be(:project_4) { create(:project, :public, path: 'test-project-2', group: namespace, name: 'Test Project 2') }

  let(:params) { {} }

  let(:finder) { described_class.new(namespace: namespace, params: params, current_user: current_user) }

  subject(:projects) { finder.execute }

  describe '#execute' do
    context 'without a namespace' do
      let(:namespace) { nil }

      it 'returns an empty array' do
        expect(projects).to be_empty
      end
    end

    context 'with a namespace' do
      it 'returns the project for the namespace' do
        expect(projects).to contain_exactly(project_1, project_2, project_4)
      end

      context 'when include_subgroups is provided' do
        let(:params) { { include_subgroups: true } }

        it 'returns all projects for the namespace' do
          expect(projects).to contain_exactly(project_1, project_2, project_3, project_4)
        end

        context 'when ids are provided' do
          let(:params) { { include_subgroups: true, ids: [project_3.id] } }

          it 'returns all projects for the ids' do
            expect(projects).to contain_exactly(project_3)
          end
        end
      end

      context 'when ids are provided' do
        let(:params) { { ids: [project_1.id] } }

        it 'returns all projects for the ids' do
          expect(projects).to contain_exactly(project_1)
        end
      end

      context 'when sort is similarity' do
        let(:params) { { sort: :similarity, search: 'test' } }

        it 'returns projects by similarity' do
          expect(projects).to contain_exactly(project_2, project_4)
        end
      end

      context 'when search parameter is missing' do
        let(:params) { { sort: :similarity } }

        it 'returns all projects' do
          expect(projects).to contain_exactly(project_1, project_2, project_4)
        end
      end

      context 'when sort parameter is missing' do
        let(:params) { { search: 'test' } }

        it 'returns matching projects' do
          expect(projects).to contain_exactly(project_2, project_4)
        end
      end
    end
  end
end