summaryrefslogtreecommitdiff
path: root/spec/models/ci/catalog/listing_spec.rb
blob: b6a9372c8b9b1ea5102f4f4b544d55492936c4c6 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::Catalog::Listing, feature_category: :pipeline_composition do
  let_it_be(:namespace) { create(:namespace) }
  let_it_be(:project_1) { create(:project, namespace: namespace) }
  let_it_be(:project_2) { create(:project, namespace: namespace) }
  let_it_be(:project_3) { create(:project) }

  let(:list) { described_class.new(namespace) }

  describe '#new' do
    context 'when namespace is not a root namespace' do
      let(:namespace) { create(:group, :nested) }

      it 'raises an exception' do
        expect { list }.to raise_error(ArgumentError, 'Namespace is not a root namespace')
      end
    end
  end

  describe '#resources' do
    subject(:resources) { list.resources }

    context 'when the namespace has no catalog resources' do
      it { is_expected.to be_empty }
    end

    context 'when the namespace has catalog resources' do
      let!(:resource) { create(:catalog_resource, project: project_1) }

      it 'contains only catalog resources for projects in that namespace' do
        is_expected.to contain_exactly(resource)
      end
    end
  end
end