diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-20 00:10:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-20 00:10:26 +0300 |
commit | b6bf52d3e274bd060a7b7e7a2812fda30e0d66d5 (patch) | |
tree | f4c98cfa82db4035744cd87c05d8a804c9b25e80 /spec/services/ci | |
parent | 1e1012d3d28c426637eecc0909c415fe2c8b7c3a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/ci')
-rw-r--r-- | spec/services/ci/catalog/add_resource_service_spec.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/services/ci/catalog/add_resource_service_spec.rb b/spec/services/ci/catalog/add_resource_service_spec.rb new file mode 100644 index 00000000000..087aa2e3e5b --- /dev/null +++ b/spec/services/ci/catalog/add_resource_service_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::Catalog::AddResourceService, feature_category: :pipeline_composition do + let_it_be(:project) { create(:project, :repository, description: 'Our components') } + let_it_be(:user) { create(:user) } + + let(:service) { described_class.new(project, user) } + + before do + stub_licensed_features(ci_namespace_catalog: true) + end + + describe '#execute' do + context 'with an unauthorized user' do + it 'raises an AccessDeniedError' do + expect { service.execute }.to raise_error(Gitlab::Access::AccessDeniedError) + end + end + + context 'with an authorized user' do + before_all do + project.add_owner(user) + end + + context 'and a valid project' do + it 'creates a catalog resource' do + response = service.execute + + expect(response.payload.project).to eq(project) + end + end + + context 'with an invalid project' do + let_it_be(:project) { create(:project, :repository) } + + before_all do + project.add_owner(user) + end + + it 'does not create a catalog resource' do + response = service.execute + + expect(response.message).to eq('Project must have a description') + end + end + + context 'with an invalid catalog resource' do + it 'does not save the catalog resource' do + catalog_resource = instance_double(::Ci::Catalog::Resource, + valid?: false, + errors: instance_double(ActiveModel::Errors, full_messages: ['not valid'])) + allow(::Ci::Catalog::Resource).to receive(:new).and_return(catalog_resource) + + response = service.execute + + expect(response.message).to eq('not valid') + end + end + end + end +end |