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

resource_resolver_spec.rb « catalog « ci « resolvers « graphql « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 313d1d337dab8b214b687dd5462aa3bec68393a3 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Resolvers::Ci::Catalog::ResourceResolver, feature_category: :pipeline_composition do
  include GraphqlHelpers

  let_it_be(:namespace) { create(:group) }
  let_it_be(:project) { create(:project, :private, namespace: namespace) }
  let_it_be(:resource) { create(:ci_catalog_resource, :published, project: project) }
  let_it_be(:user) { create(:user) }

  describe '#resolve' do
    context 'when id argument is provided' do
      context 'when the user is authorised to view the resource' do
        before_all do
          namespace.add_developer(user)
        end

        context 'when resource is found' do
          it 'returns a single CI/CD Catalog resource' do
            result = resolve(described_class, ctx: { current_user: user },
              args: { id: resource.to_global_id })

            expect(result.id).to eq(resource.id)
            expect(result.class).to eq(Ci::Catalog::Resource)
          end
        end

        context 'when resource is not found' do
          it 'raises ResourceNotAvailable error' do
            result = resolve(described_class, ctx: { current_user: user },
              args: { id: GlobalID.new(
                ::Gitlab::GlobalId.build(model_name: '::Ci::Catalog::Resource', id: "not-a-real-id")
              ) })

            expect(result).to be_a(::Gitlab::Graphql::Errors::ResourceNotAvailable)
          end
        end
      end

      context 'when user is not authorised to view the resource' do
        it 'raises ResourceNotAvailable error' do
          result = resolve(described_class, ctx: { current_user: user },
            args: { id: resource.to_global_id })

          expect(result).to be_a(::Gitlab::Graphql::Errors::ResourceNotAvailable)
        end
      end
    end

    context 'when full_path argument is provided' do
      context 'when the user is authorised to view the resource' do
        before_all do
          namespace.add_developer(user)
        end

        context 'when resource is found' do
          it 'returns a single CI/CD Catalog resource' do
            result = resolve(described_class, ctx: { current_user: user },
              args: { full_path: resource.project.full_path })

            expect(result.id).to eq(resource.id)
            expect(result.class).to eq(Ci::Catalog::Resource)
          end
        end

        context 'when resource is not found' do
          it 'raises ResourceNotAvailable error' do
            result = resolve(described_class, ctx: { current_user: user },
              args: { full_path: "project/non_exisitng_resource" })

            expect(result).to be_a(::Gitlab::Graphql::Errors::ResourceNotAvailable)
          end
        end

        context 'when project is not a catalog resource' do
          let_it_be(:project) { create(:project, :private, namespace: namespace) }

          it 'raises ResourceNotAvailable error' do
            result = resolve(described_class, ctx: { current_user: user }, args: { full_path: project.full_path })

            expect(result).to be_a(::Gitlab::Graphql::Errors::ResourceNotAvailable)
          end
        end
      end

      context 'when user is not authorised to view the resource' do
        it 'raises ResourceNotAvailable error' do
          result = resolve(described_class, ctx: { current_user: user },
            args: { full_path: resource.project.full_path })

          expect(result).to be_a(::Gitlab::Graphql::Errors::ResourceNotAvailable)
        end
      end
    end

    context 'when neither id nor full_path argument is provided' do
      before_all do
        namespace.add_developer(user)
      end
      it 'raises ArgumentError' do
        expect_graphql_error_to_be_created(::Gitlab::Graphql::Errors::ArgumentError,
          "Exactly one of 'id' or 'full_path' arguments is required.") do
          resolve(described_class, ctx: { current_user: user },
            args: {})
        end
      end
    end

    context 'when both full_path and id arguments are provided' do
      before_all do
        namespace.add_developer(user)
      end

      it 'raises ArgumentError' do
        expect_graphql_error_to_be_created(::Gitlab::Graphql::Errors::ArgumentError,
          "Exactly one of 'id' or 'full_path' arguments is required.") do
          resolve(described_class, ctx: { current_user: user },
            args: { full_path: resource.project.full_path, id: resource.to_global_id })
        end
      end
    end
  end
end