diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
commit | 5afcbe03ead9ada87621888a31a62652b10a7e4f (patch) | |
tree | 9918b67a0d0f0bafa6542e839a8be37adf73102d /spec/models/packages/dependency_link_spec.rb | |
parent | c97c0201564848c1f53226fe19d71fdcc472f7d0 (diff) |
Add latest changes from gitlab-org/gitlab@16-4-stable-eev16.4.0-rc42
Diffstat (limited to 'spec/models/packages/dependency_link_spec.rb')
-rw-r--r-- | spec/models/packages/dependency_link_spec.rb | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/spec/models/packages/dependency_link_spec.rb b/spec/models/packages/dependency_link_spec.rb index d8fde8f5eb3..3022a960c4c 100644 --- a/spec/models/packages/dependency_link_spec.rb +++ b/spec/models/packages/dependency_link_spec.rb @@ -1,7 +1,28 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe Packages::DependencyLink, type: :model do +RSpec.describe Packages::DependencyLink, type: :model, feature_category: :package_registry do + let_it_be(:package1) { create(:package) } + let_it_be(:package2) { create(:package) } + let_it_be(:dependency1) { create(:packages_dependency) } + let_it_be(:dependency2) { create(:packages_dependency) } + + let_it_be(:dependency_link1) do + create(:packages_dependency_link, :dev_dependencies, package: package1, dependency: dependency1) + end + + let_it_be(:dependency_link2) do + create(:packages_dependency_link, :dependencies, package: package1, dependency: dependency2) + end + + let_it_be(:dependency_link3) do + create(:packages_dependency_link, :dependencies, package: package2, dependency: dependency1) + end + + let_it_be(:dependency_link4) do + create(:packages_dependency_link, :dependencies, package: package2, dependency: dependency2) + end + describe 'relationships' do it { is_expected.to belong_to(:package).inverse_of(:dependency_links) } it { is_expected.to belong_to(:dependency).inverse_of(:dependency_links) } @@ -53,4 +74,49 @@ RSpec.describe Packages::DependencyLink, type: :model do end end end + + describe '.dependency_ids_grouped_by_type' do + let(:packages) { Packages::Package.where(id: [package1.id, package2.id]) } + + subject { described_class.dependency_ids_grouped_by_type(packages) } + + it 'aggregates dependencies by type', :aggregate_failures do + result = Gitlab::Json.parse(subject.to_json) + + expect(result.count).to eq(2) + expect(result).to include( + hash_including( + 'package_id' => package1.id, + 'dependency_ids_by_type' => { + '1' => [dependency2.id], + '2' => [dependency1.id] + } + ), + hash_including( + 'package_id' => package2.id, + 'dependency_ids_by_type' => { + '1' => [dependency1.id, dependency2.id] + } + ) + ) + end + end + + describe '.for_packages' do + let(:packages) { Packages::Package.where(id: package1.id) } + + subject { described_class.for_packages(packages) } + + it 'returns dependency links for selected packages' do + expect(subject).to contain_exactly(dependency_link1, dependency_link2) + end + end + + describe '.select_dependency_id' do + subject { described_class.select_dependency_id } + + it 'returns only dependency_id' do + expect(subject[0].attributes).to eq('dependency_id' => dependency1.id, 'id' => nil) + end + end end |