blob: ae07f312fcc7bee3f18a2e95c744a0a9b55fdbd8 (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Nuget::SyncMetadatumService, feature_category: :package_registry do
let_it_be(:package, reload: true) { create(:nuget_package) }
let_it_be(:metadata) do
{
project_url: 'https://test.org/test',
license_url: 'https://test.org/MIT',
icon_url: 'https://test.org/icon.png'
}
end
let(:service) { described_class.new(package, metadata) }
let(:nuget_metadatum) { package.nuget_metadatum }
describe '#execute' do
subject { service.execute }
RSpec.shared_examples 'saving metadatum attributes' do
it 'saves nuget metadatum' do
subject
metadata.each do |attribute, expected_value|
expect(nuget_metadatum.send(attribute)).to eq(expected_value)
end
end
end
it 'creates a nuget metadatum' do
expect { subject }
.to change { package.nuget_metadatum.present? }.from(false).to(true)
end
it_behaves_like 'saving metadatum attributes'
context 'with exisiting nuget metadatum' do
let_it_be(:package) { create(:nuget_package, :with_metadatum) }
it 'does not create a nuget metadatum' do
expect { subject }.to change { ::Packages::Nuget::Metadatum.count }.by(0)
end
it_behaves_like 'saving metadatum attributes'
context 'with empty metadata' do
let_it_be(:metadata) { {} }
it 'destroys the nuget metadatum' do
expect { subject }
.to change { package.reload.nuget_metadatum.present? }.from(true).to(false)
end
end
end
end
end
|