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

73 lines
2 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-09-30 23:02:18 +05:30
shared_examples 'returning valid resources' do |resources_count: 9, include_publish_service: true|
2021-03-08 18:12:59 +05:30
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
2021-09-30 23:02:18 +05:30
it "does #{'not ' unless include_publish_service}return the publish resource", :aggregate_failures do
2021-03-08 18:12:59 +05:30
services_types = subject.map { |res| res[:@type] }
2021-09-30 23:02:18 +05:30
publish_service_versions = [
described_class::SERVICE_VERSIONS[:publish],
described_class::SERVICE_VERSIONS[:symbol]
].flatten
publish_service_versions.each do |publish_service_version|
2021-03-08 18:12:59 +05:30
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 }
2021-09-30 23:02:18 +05:30
# at the group level we don't have the publish, symbol, and download service
2021-03-08 18:12:59 +05:30
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