diff options
Diffstat (limited to 'spec/services/releases')
-rw-r--r-- | spec/services/releases/create_evidence_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/releases/create_service_spec.rb | 20 | ||||
-rw-r--r-- | spec/services/releases/destroy_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/releases/links/create_service_spec.rb | 84 | ||||
-rw-r--r-- | spec/services/releases/links/destroy_service_spec.rb | 72 | ||||
-rw-r--r-- | spec/services/releases/links/update_service_spec.rb | 89 |
6 files changed, 267 insertions, 2 deletions
diff --git a/spec/services/releases/create_evidence_service_spec.rb b/spec/services/releases/create_evidence_service_spec.rb index 0ac15a7291d..75d0a2b9c0e 100644 --- a/spec/services/releases/create_evidence_service_spec.rb +++ b/spec/services/releases/create_evidence_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Releases::CreateEvidenceService do +RSpec.describe Releases::CreateEvidenceService, feature_category: :release_orchestration do let_it_be(:project) { create(:project) } let(:release) { create(:release, project: project) } diff --git a/spec/services/releases/create_service_spec.rb b/spec/services/releases/create_service_spec.rb index 9768ceb12e8..ca5dd912e77 100644 --- a/spec/services/releases/create_service_spec.rb +++ b/spec/services/releases/create_service_spec.rb @@ -55,6 +55,26 @@ RSpec.describe Releases::CreateService, feature_category: :continuous_integratio end end + context 'when project is a catalog resource' do + let(:ref) { 'master' } + let!(:catalog_resource) { create(:catalog_resource, project: project) } + + context 'and it is valid' do + let_it_be(:project) { create(:project, :repository, description: 'our components') } + + it_behaves_like 'a successful release creation' + end + + context 'and it is invalid' do + it 'raises an error and does not update the release' do + result = service.execute + + expect(result[:status]).to eq(:error) + expect(result[:message]).to eq('Project must have a description') + end + end + end + context 'when ref is provided' do let(:ref) { 'master' } let(:tag_name) { 'foobar' } diff --git a/spec/services/releases/destroy_service_spec.rb b/spec/services/releases/destroy_service_spec.rb index 46550ac5bef..953490ac379 100644 --- a/spec/services/releases/destroy_service_spec.rb +++ b/spec/services/releases/destroy_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Releases::DestroyService do +RSpec.describe Releases::DestroyService, feature_category: :release_orchestration do let(:project) { create(:project, :repository) } let(:mainatiner) { create(:user) } let(:repoter) { create(:user) } diff --git a/spec/services/releases/links/create_service_spec.rb b/spec/services/releases/links/create_service_spec.rb new file mode 100644 index 00000000000..9928d2162d7 --- /dev/null +++ b/spec/services/releases/links/create_service_spec.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Releases::Links::CreateService, feature_category: :release_orchestration do + let(:service) { described_class.new(release, user, params) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + let_it_be(:release) { create(:release, project: project, author: user, tag: 'v1.1.0') } + + let(:params) { { name: name, url: url, direct_asset_path: direct_asset_path, link_type: link_type } } + let(:name) { 'link' } + let(:url) { 'https://example.com' } + let(:direct_asset_path) { '/path' } + let(:link_type) { 'other' } + + before do + project.add_developer(user) + end + + describe '#execute' do + subject(:execute) { service.execute } + + let(:link) { subject.payload[:link] } + + it 'successfully creates a release link' do + expect { execute }.to change { Releases::Link.count }.by(1) + + expect(link).to have_attributes( + name: name, + url: url, + filepath: direct_asset_path, + link_type: link_type + ) + end + + context 'when user does not have access to create release link' do + before do + project.add_guest(user) + end + + it 'returns an error' do + expect { execute }.not_to change { Releases::Link.count } + + is_expected.to be_error + expect(execute.message).to include('Access Denied') + expect(execute.reason).to eq(:forbidden) + end + end + + context 'when url is invalid' do + let(:url) { 'not_a_url' } + + it 'returns an error' do + expect { execute }.not_to change { Releases::Link.count } + + is_expected.to be_error + expect(execute.message[0]).to include('Url is blocked') + expect(execute.reason).to eq(:bad_request) + end + end + + context 'when both direct_asset_path and filepath are provided' do + let(:params) { super().merge(filepath: '/filepath') } + + it 'prefers direct_asset_path' do + is_expected.to be_success + + expect(link.filepath).to eq(direct_asset_path) + end + end + + context 'when only filepath is set' do + let(:params) { super().merge(filepath: '/filepath') } + let(:direct_asset_path) { nil } + + it 'uses filepath' do + is_expected.to be_success + + expect(link.filepath).to eq('/filepath') + end + end + end +end diff --git a/spec/services/releases/links/destroy_service_spec.rb b/spec/services/releases/links/destroy_service_spec.rb new file mode 100644 index 00000000000..a248932eada --- /dev/null +++ b/spec/services/releases/links/destroy_service_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Releases::Links::DestroyService, feature_category: :release_orchestration do + let(:service) { described_class.new(release, user, {}) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + let_it_be(:release) { create(:release, project: project, author: user, tag: 'v1.1.0') } + + let!(:release_link) do + create( + :release_link, + release: release, + name: 'awesome-app.dmg', + url: 'https://example.com/download/awesome-app.dmg' + ) + end + + before do + project.add_developer(user) + end + + describe '#execute' do + subject(:execute) { service.execute(release_link) } + + it 'successfully deletes a release link' do + expect { execute }.to change { release.links.count }.by(-1) + + is_expected.to be_success + end + + context 'when user does not have access to delete release link' do + before do + project.add_guest(user) + end + + it 'returns an error' do + expect { execute }.not_to change { release.links.count } + + is_expected.to be_error + expect(execute.message).to include('Access Denied') + expect(execute.reason).to eq(:forbidden) + end + end + + context 'when release link does not exist' do + let(:release_link) { nil } + + it 'returns an error' do + expect { execute }.not_to change { release.links.count } + + is_expected.to be_error + expect(execute.message).to eq('Link does not exist') + expect(execute.reason).to eq(:not_found) + end + end + + context 'when release link deletion failed' do + before do + allow(release_link).to receive(:destroy).and_return(false) + end + + it 'returns an error' do + expect { execute }.not_to change { release.links.count } + + is_expected.to be_error + expect(execute.reason).to eq(:bad_request) + end + end + end +end diff --git a/spec/services/releases/links/update_service_spec.rb b/spec/services/releases/links/update_service_spec.rb new file mode 100644 index 00000000000..3f48985cf60 --- /dev/null +++ b/spec/services/releases/links/update_service_spec.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Releases::Links::UpdateService, feature_category: :release_orchestration do + let(:service) { described_class.new(release, user, params) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + let_it_be(:release) { create(:release, project: project, author: user, tag: 'v1.1.0') } + + let(:release_link) do + create( + :release_link, + release: release, + name: 'awesome-app.dmg', + url: 'https://example.com/download/awesome-app.dmg' + ) + end + + let(:params) { { name: name, url: url, direct_asset_path: direct_asset_path, link_type: link_type } } + let(:name) { 'link' } + let(:url) { 'https://example.com' } + let(:direct_asset_path) { '/path' } + let(:link_type) { 'other' } + + before do + project.add_developer(user) + end + + describe '#execute' do + subject(:execute) { service.execute(release_link) } + + let(:updated_link) { execute.payload[:link] } + + it 'successfully updates a release link' do + is_expected.to be_success + + expect(updated_link).to have_attributes( + name: name, + url: url, + filepath: direct_asset_path, + link_type: link_type + ) + end + + context 'when user does not have access to update release link' do + before do + project.add_guest(user) + end + + it 'returns an error' do + is_expected.to be_error + expect(execute.message).to include('Access Denied') + expect(execute.reason).to eq(:forbidden) + end + end + + context 'when url is invalid' do + let(:url) { 'not_a_url' } + + it 'returns an error' do + is_expected.to be_error + expect(execute.message[0]).to include('Url is blocked') + expect(execute.reason).to eq(:bad_request) + end + end + + context 'when both direct_asset_path and filepath are provided' do + let(:params) { super().merge(filepath: '/filepath') } + + it 'prefers direct_asset_path' do + is_expected.to be_success + + expect(updated_link.filepath).to eq(direct_asset_path) + end + end + + context 'when only filepath is set' do + let(:params) { super().merge(filepath: '/filepath') } + let(:direct_asset_path) { nil } + + it 'uses filepath' do + is_expected.to be_success + + expect(updated_link.filepath).to eq('/filepath') + end + end + end +end |