Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create_service_spec.rb « resources « catalog « ci « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 202c76acaecc6018765b626f751367f6ceb6b5d7 (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
# 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