diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/api/entities/nuget | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/api/entities/nuget')
5 files changed, 213 insertions, 0 deletions
diff --git a/spec/lib/api/entities/nuget/dependency_group_spec.rb b/spec/lib/api/entities/nuget/dependency_group_spec.rb new file mode 100644 index 00000000000..5a649be846b --- /dev/null +++ b/spec/lib/api/entities/nuget/dependency_group_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe API::Entities::Nuget::DependencyGroup do + let(:dependency_group) do + { + id: 'http://gitlab.com/Sandbox.App/1.0.0.json#dependencygroup', + type: 'PackageDependencyGroup', + target_framework: 'fwk test', + dependencies: [ + { + id: 'http://gitlab.com/Sandbox.App/1.0.0.json#dependency', + type: 'PackageDependency', + name: 'Dependency', + range: '2.0.0' + } + ] + } + end + + let(:expected) do + { + '@id': 'http://gitlab.com/Sandbox.App/1.0.0.json#dependencygroup', + '@type': 'PackageDependencyGroup', + 'targetFramework': 'fwk test', + 'dependencies': [ + { + '@id': 'http://gitlab.com/Sandbox.App/1.0.0.json#dependency', + '@type': 'PackageDependency', + 'id': 'Dependency', + 'range': '2.0.0' + } + ] + } + end + let(:entity) { described_class.new(dependency_group) } + + subject { entity.as_json } + + it { is_expected.to eq(expected) } + + context 'dependency group without target framework' do + let(:dependency_group_with_no_target_framework) { dependency_group.tap { |dg| dg[:target_framework] = nil } } + let(:expected_no_target_framework) { expected.except(:targetFramework) } + let(:entity) { described_class.new(dependency_group_with_no_target_framework) } + + it { is_expected.to eq(expected_no_target_framework) } + end +end diff --git a/spec/lib/api/entities/nuget/dependency_spec.rb b/spec/lib/api/entities/nuget/dependency_spec.rb new file mode 100644 index 00000000000..13897cc91f0 --- /dev/null +++ b/spec/lib/api/entities/nuget/dependency_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe API::Entities::Nuget::Dependency do + let(:dependency) do + { + id: 'http://gitlab.com/Sandbox.App/1.0.0.json#dependency', + type: 'PackageDependency', + name: 'Dependency', + range: '2.0.0' + } + end + + let(:expected) do + { + '@id': 'http://gitlab.com/Sandbox.App/1.0.0.json#dependency', + '@type': 'PackageDependency', + 'id': 'Dependency', + 'range': '2.0.0' + } + end + let(:entity) { described_class.new(dependency) } + + subject { entity.as_json } + + it { is_expected.to eq(expected) } +end diff --git a/spec/lib/api/entities/nuget/metadatum_spec.rb b/spec/lib/api/entities/nuget/metadatum_spec.rb new file mode 100644 index 00000000000..fe94ea3a69a --- /dev/null +++ b/spec/lib/api/entities/nuget/metadatum_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe API::Entities::Nuget::Metadatum do + let(:metadatum) do + { + project_url: 'http://sandbox.com/project', + license_url: 'http://sandbox.com/license', + icon_url: 'http://sandbox.com/icon' + } + end + let(:expected) do + { + 'projectUrl': 'http://sandbox.com/project', + 'licenseUrl': 'http://sandbox.com/license', + 'iconUrl': 'http://sandbox.com/icon' + } + end + let(:entity) { described_class.new(metadatum) } + + subject { entity.as_json } + + it { is_expected.to eq(expected) } + + %i[project_url license_url icon_url].each do |optional_field| + context "metadatum without #{optional_field}" do + let(:metadatum_without_a_field) { metadatum.except(optional_field) } + let(:expected_without_a_field) { expected.except(optional_field.to_s.camelize(:lower).to_sym) } + let(:entity) { described_class.new(metadatum_without_a_field) } + + it { is_expected.to eq(expected_without_a_field) } + end + end +end diff --git a/spec/lib/api/entities/nuget/package_metadata_catalog_entry_spec.rb b/spec/lib/api/entities/nuget/package_metadata_catalog_entry_spec.rb new file mode 100644 index 00000000000..c422b51bf3b --- /dev/null +++ b/spec/lib/api/entities/nuget/package_metadata_catalog_entry_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe API::Entities::Nuget::PackageMetadataCatalogEntry do + let(:entry) do + { + json_url: 'http://sandbox.com/json/package', + authors: 'Authors', + dependency_groups: [], + package_name: 'PackageTest', + package_version: '1.2.3', + tags: 'tag1 tag2 tag3', + archive_url: 'http://sandbox.com/archive/package', + summary: 'Summary', + metadatum: { + project_url: 'http://sandbox.com/project', + license_url: 'http://sandbox.com/license', + icon_url: 'http://sandbox.com/icon' + } + } + end + + let(:expected) do + { + '@id': 'http://sandbox.com/json/package', + 'id': 'PackageTest', + 'version': '1.2.3', + 'authors': 'Authors', + 'dependencyGroups': [], + 'tags': 'tag1 tag2 tag3', + 'packageContent': 'http://sandbox.com/archive/package', + 'summary': 'Summary', + 'projectUrl': 'http://sandbox.com/project', + 'licenseUrl': 'http://sandbox.com/license', + 'iconUrl': 'http://sandbox.com/icon' + } + end + + subject { described_class.new(entry).as_json } + + it { is_expected.to eq(expected) } +end diff --git a/spec/lib/api/entities/nuget/search_result_spec.rb b/spec/lib/api/entities/nuget/search_result_spec.rb new file mode 100644 index 00000000000..2a760c70224 --- /dev/null +++ b/spec/lib/api/entities/nuget/search_result_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe API::Entities::Nuget::SearchResult do + let(:search_result) do + { + type: 'Package', + authors: 'Author', + name: 'PackageTest', + version: '1.2.3', + versions: [ + { + json_url: 'http://sandbox.com/json/package', + downloads: 100, + version: '1.2.3' + } + ], + summary: 'Summary', + total_downloads: 100, + verified: true, + tags: 'tag1 tag2 tag3', + metadatum: { + project_url: 'http://sandbox.com/project', + license_url: 'http://sandbox.com/license', + icon_url: 'http://sandbox.com/icon' + } + } + end + let(:expected) do + { + '@type': 'Package', + 'authors': 'Author', + 'id': 'PackageTest', + 'title': 'PackageTest', + 'summary': 'Summary', + 'totalDownloads': 100, + 'verified': true, + 'version': '1.2.3', + 'tags': 'tag1 tag2 tag3', + 'projectUrl': 'http://sandbox.com/project', + 'licenseUrl': 'http://sandbox.com/license', + 'iconUrl': 'http://sandbox.com/icon', + 'versions': [ + { + '@id': 'http://sandbox.com/json/package', + 'downloads': 100, + 'version': '1.2.3' + } + ] + } + end + + subject { described_class.new(search_result).as_json } + + it { is_expected.to eq(expected) } +end |