debian-mirror-gitlab/spec/presenters/packages/nuget/service_index_presenter_spec.rb

68 lines
1.8 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Packages::Nuget::ServiceIndexPresenter do
let_it_be(:project) { create(:project) }
2021-03-08 18:12:59 +05:30
let_it_be(:group) { create(:group) }
let(:presenter) { described_class.new(target) }
2020-07-28 23:09:34 +05:30
describe '#version' do
subject { presenter.version }
2021-03-08 18:12:59 +05:30
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
2020-07-28 23:09:34 +05:30
end
describe '#resources' do
subject { presenter.resources }
2021-03-08 18:12:59 +05:30
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
2020-07-28 23:09:34 +05:30
end
end
end
2021-03-08 18:12:59 +05:30
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
2020-07-28 23:09:34 +05:30
end
end