diff options
Diffstat (limited to 'spec/services/ci/catalog/resources/create_service_spec.rb')
-rw-r--r-- | spec/services/ci/catalog/resources/create_service_spec.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/services/ci/catalog/resources/create_service_spec.rb b/spec/services/ci/catalog/resources/create_service_spec.rb new file mode 100644 index 00000000000..202c76acaec --- /dev/null +++ b/spec/services/ci/catalog/resources/create_service_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::Catalog::Resources::CreateService, feature_category: :pipeline_composition do + let_it_be(:project) { create(:project, :catalog_resource_with_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 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 |