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

destroy_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: da5ba7ad0bce5490d5fd51c099f8257bccf8a066 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::Catalog::Resources::DestroyService, feature_category: :pipeline_composition do
  let_it_be(:project) { create(:project, :catalog_resource_with_components) }
  let_it_be(:catalog_resource) { create(:ci_catalog_resource, project: project) }
  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(catalog_resource) }.to raise_error(Gitlab::Access::AccessDeniedError)
      end
    end

    context 'with an authorized user' do
      before_all do
        project.add_owner(user)
      end

      it 'destroys a catalog resource' do
        expect(project.catalog_resource).to eq(catalog_resource)

        response = service.execute(catalog_resource)

        expect(project.reload.catalog_resource).to be_nil
        expect(response.status).to be(:success)
      end
    end
  end
end