summaryrefslogtreecommitdiff
path: root/spec/presenters/packages/nuget/service_index_presenter_spec.rb
blob: 9c95fbc8fd2c066c8ea533dabf1c0582fe50db9d (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::Packages::Nuget::ServiceIndexPresenter do
  let_it_be(:project) { create(:project) }
  let_it_be(:group) { create(:group) }

  let(:presenter) { described_class.new(target) }

  describe '#version' do
    subject { presenter.version }

    context 'for a group' do
      let(:target) { group }

      it { is_expected.to eq '3.0.0' }
    end

    context 'for a project' do
      let(:target) { project }

      it { is_expected.to eq '3.0.0' }
    end
  end

  describe '#resources' do
    subject { presenter.resources }

    shared_examples 'returning valid resources' do |resources_count: 8, include_publish_service: true|
      it 'has valid resources' do
        expect(subject.size).to eq resources_count
        subject.each do |resource|
          %i[@id @type comment].each do |field|
            expect(resource).to have_key(field)
            expect(resource[field]).to be_a(String)
          end
        end
      end

      it "does #{'not ' unless include_publish_service}return the publish resource" do
        services_types = subject.map { |res| res[:@type] }

        described_class::SERVICE_VERSIONS[:publish].each do |publish_service_version|
          if include_publish_service
            expect(services_types).to include(publish_service_version)
          else
            expect(services_types).not_to include(publish_service_version)
          end
        end
      end
    end

    context 'for a group' do
      let(:target) { group }

      # at the group level we don't have the publish and download service
      it_behaves_like 'returning valid resources', resources_count: 6, include_publish_service: false
    end

    context 'for a project' do
      let(:target) { project }

      it_behaves_like 'returning valid resources'
    end
  end
end